Created
November 14, 2020 09:52
-
-
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
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
// 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