Skip to content

Instantly share code, notes, and snippets.

@shazow
Created August 17, 2020 15:03
Show Gist options
  • Save shazow/eed069b4f52c3d7ab0b4f5c14076baae to your computer and use it in GitHub Desktop.
Save shazow/eed069b4f52c3d7ab0b4f5c14076baae to your computer and use it in GitHub Desktop.
Bleve partial word search example
package main
import (
"fmt"
"log"
"github.com/blevesearch/bleve"
)
func main() {
mapping := bleve.NewIndexMapping()
index, err := bleve.NewMemOnly(mapping)
if err != nil {
log.Fatal(err)
}
if err := index.Index("sadness", "sadness"); err != nil {
log.Fatal(err)
}
if err := index.Index("happiness", "happiness"); err != nil {
log.Fatal(err)
}
query := bleve.NewQueryStringQuery("*sad*")
search := bleve.NewSearchRequest(query)
searchResults, err := index.Search(search)
if err != nil {
log.Fatal(err)
}
for _, hit := range searchResults.Hits {
fmt.Println("Hit", hit)
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment