Last active
November 14, 2020 09:52
-
-
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
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 | |
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