added reindexing
This commit is contained in:
parent
407ec638fe
commit
bb22097b7b
17 changed files with 226 additions and 47 deletions
|
|
@ -6,6 +6,7 @@ import (
|
|||
"errors"
|
||||
"git.giftfish.de/ston1th/docstore/pkg/core"
|
||||
"github.com/blevesearch/bleve"
|
||||
"github.com/blevesearch/bleve/document"
|
||||
"github.com/blevesearch/bleve/mapping"
|
||||
"html/template"
|
||||
"os"
|
||||
|
|
@ -17,13 +18,13 @@ const maxSearchResult = 101
|
|||
|
||||
const docType = "document"
|
||||
|
||||
type document struct {
|
||||
type Document struct {
|
||||
Text string `json:"text"`
|
||||
Tags []string `json:"tags"`
|
||||
Created time.Time `json:"created"`
|
||||
}
|
||||
|
||||
func (d *document) Type() string {
|
||||
func (d *Document) Type() string {
|
||||
return docType
|
||||
}
|
||||
|
||||
|
|
@ -70,7 +71,34 @@ func (i *Index) Add(text string, tags []string) (id string, err error) {
|
|||
}
|
||||
id = newID()
|
||||
}
|
||||
err = i.i.Index(id, &document{text, tags, time.Now()})
|
||||
err = i.i.Index(id, &Document{text, tags, time.Now()})
|
||||
return
|
||||
}
|
||||
|
||||
func (i *Index) Reindex(id string, doc *Document) error {
|
||||
return i.i.Index(id, doc)
|
||||
}
|
||||
|
||||
func (i *Index) Get(id string) (doc *Document, err error) {
|
||||
d, err := i.i.Document(id)
|
||||
if d == nil || err != nil {
|
||||
return
|
||||
}
|
||||
doc = new(Document)
|
||||
for _, f := range d.Fields {
|
||||
n := f.Name()
|
||||
switch n {
|
||||
case "text":
|
||||
text := document.NewTextField(n, f.ArrayPositions(), f.Value())
|
||||
doc.Text = string(text.Value())
|
||||
//case "tags":
|
||||
// tags := document.NewTextField(n, f.ArrayPositions(), f.Value())
|
||||
// doc.Tags = append(doc.Tags, string(tags.Value()))
|
||||
case "created":
|
||||
created := document.NewDateTimeFieldFromBytes(n, f.ArrayPositions(), f.Value())
|
||||
doc.Created, _ = created.DateTime()
|
||||
}
|
||||
}
|
||||
return
|
||||
}
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue