Skip to content

Instantly share code, notes, and snippets.

@matryer
Last active November 14, 2020 09:52
Show Gist options
  • Save matryer/5c2ae385ff883f5ce753d07493f85242 to your computer and use it in GitHub Desktop.
Save matryer/5c2ae385ff883f5ce753d07493f85242 to your computer and use it in GitHub Desktop.
Firesearch JavaScript API sample showing how to do full-text search in Google Cloud Platform
// for more information, see https://firesearch.dev
// add or update a document
indexService.putDoc({
indexPath: "firesearch/indexes/my-search-index",
doc: {
id: "document-1",
searchFields: [
{
key: "body",
value: "When life gives you lemons, search me.",
},
]
}
})
.then(response => {
// success
})
.catch(err => {
console.warn(err) // failed
})
// perform a search
indexService.search({
query: {
indexPath: "firesearch/indexes/my-search-index",
accessKey: "access-key-goes-here",
limit: 10,
text: "lemons",
}
})
.then(response => {
response.hits.forEach(hit => {
console.info(hit.id, hit.title)
hit.highlights.forEach(highlight => {
console.info("---", highlight.text)
})
})
})
.catch(err => {
console.warn(err) // failed
})
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment