Created
August 17, 2020 15:03
-
-
Save shazow/eed069b4f52c3d7ab0b4f5c14076baae to your computer and use it in GitHub Desktop.
Bleve partial word search example
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 ( | |
"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