Skip to content

Instantly share code, notes, and snippets.

@dtynn
Created May 14, 2015 06:55
Show Gist options
  • Save dtynn/8be6ed079fa6df8f0270 to your computer and use it in GitHub Desktop.
Save dtynn/8be6ed079fa6df8f0270 to your computer and use it in GitHub Desktop.
bleve highlight incorrect result
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