Skip to content

Instantly share code, notes, and snippets.

@matryer
Created November 14, 2020 09:56
Show Gist options
  • Save matryer/c03f4a933baac87ce2c2a85b2d305944 to your computer and use it in GitHub Desktop.
Save matryer/c03f4a933baac87ce2c2a85b2d305944 to your computer and use it in GitHub Desktop.
Full Text Search with Google App Engine
// Firesearch brings full-text search to Google App Engine
// This sample shows how easy it is to use in JavaScript.
// You run this in Cloud Run, it connected to Cloud Firestore,
// and you write code that interacts with the Firesearch API
// to bring a high performance, highly accurate search experience
// to your apps and websites.
// 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