Created
May 14, 2015 06:55
-
-
Save dtynn/8be6ed079fa6df8f0270 to your computer and use it in GitHub Desktop.
bleve highlight incorrect result
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
package main | |
import ( | |
"log" | |
"github.com/blevesearch/bleve" | |
) | |
func main() { | |
indexMapping := bleve.NewIndexMapping() | |
index, err := bleve.NewUsing("boltdb", indexMapping, "boltdb", nil) | |
if err == bleve.ErrorIndexPathExists { | |
index, err = bleve.OpenUsing("boltdb", nil) | |
} | |
if err != nil { | |
log.Fatalln(err) | |
} | |
docs := []struct { | |
Title string | |
Tags []string | |
}{ | |
{ | |
Title: "highlight", | |
Tags: []string{"abc", "123 45 678"}, | |
}, | |
} | |
for _, doc := range docs { | |
index.Index(doc.Title, doc) | |
} | |
keyword := "123" | |
query := bleve.NewMatchQuery(keyword) | |
search := bleve.NewSearchRequest(query) | |
search.Highlight = bleve.NewHighlight() | |
searchResults, err := index.Search(search) | |
if err != nil { | |
log.Fatalln(err) | |
return | |
} | |
log.Printf("result: %s: %s \n", keyword, searchResults) | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment