unstable: initial tags
This commit is contained in:
parent
2e71b60248
commit
b3b62af3a4
28 changed files with 503 additions and 91 deletions
|
|
@ -19,7 +19,7 @@ const docType = "document"
|
|||
|
||||
type document struct {
|
||||
Text string `json:"text"`
|
||||
Keyword []string `json:"keyword"`
|
||||
Tags []string `json:"tags"`
|
||||
Created time.Time `json:"created"`
|
||||
}
|
||||
|
||||
|
|
@ -61,7 +61,7 @@ func (i *Index) Close() error {
|
|||
return i.i.Close()
|
||||
}
|
||||
|
||||
func (i *Index) Add(text string) (id string, err error) {
|
||||
func (i *Index) Add(text string, tags []string) (id string, err error) {
|
||||
id = newID()
|
||||
for {
|
||||
doc, _ := i.i.Document(id)
|
||||
|
|
@ -70,8 +70,7 @@ func (i *Index) Add(text string) (id string, err error) {
|
|||
}
|
||||
id = newID()
|
||||
}
|
||||
k := classify(text)
|
||||
err = i.i.Index(id, &document{text, k, time.Now()})
|
||||
err = i.i.Index(id, &document{text, tags, time.Now()})
|
||||
return
|
||||
}
|
||||
|
||||
|
|
@ -97,12 +96,12 @@ func (i *Index) Search(search string) (results core.Results, err error) {
|
|||
continue
|
||||
}
|
||||
for fragField, frags := range hit.Fragments {
|
||||
if fragField == "keyword" {
|
||||
var k string
|
||||
if fragField == "tags" {
|
||||
var t string
|
||||
for _, f := range frags {
|
||||
k += f
|
||||
t += f
|
||||
}
|
||||
r.Keyword = strings.ReplaceAll(strings.ReplaceAll(k, "<mark>", ""), "</mark>", "")
|
||||
r.Tags = strings.ReplaceAll(strings.ReplaceAll(t, "<mark>", ""), "</mark>", "")
|
||||
}
|
||||
if fragField == "text" || fragField == "created" {
|
||||
for _, f := range frags {
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue