Skip to content

Instantly share code, notes, and snippets.

@matryer
Created November 14, 2020 09:52
Show Gist options
  • Save matryer/49534f0e8434a4311371318ade95fbae to your computer and use it in GitHub Desktop.
Save matryer/49534f0e8434a4311371318ade95fbae to your computer and use it in GitHub Desktop.
Firesearch Go SDK sample showing how to do full-text search in Google Cloud Platform
// for more information, see https://firesearch.dev
// add or update a document
_, err := indexService.PutDoc(PutDocRequest{
IndexPath: "firesearch/indexes/my-search-index",
Doc: Doc{
ID: "document-1",
SearchFields: []SearchField{
{
Key: "body",
Value: "When life gives you lemons, search me."
},
},
},
})
if err != nil {
return err // failed
}
// perform a search
searchResp, err := indexService.Search(SearchRequest{
Query: Query{
IndexPath: "firesearch/indexes/my-search-index",
AccessKey: "access-key-goes-here",
Limit: 10,
Text: "lemons",
},
})
if err != nil {
return err // failed
}
for _, hit := range searchResp.Hits {
fmt.Println(hit.ID, hit.Title)
for _, highlight := range hit.Highlights {
fmt.Println("\t", highlight.Text)
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment