Algolia search with attribute name
Asked Answered
B

1

6

Data on algolia is like this

objectID:3464542
Type:"Accelerator"
Country:"Germany"
City:null
Name:"ProsiebenSat1 Accelerator Batch #8"

I want to search any name which are in Germany. How I do that?

When I do Contact.raw_search("Batch"), I get all records even whose name include this even non-German. I want to get all those which are of specific country.

Biscuit answered 10/5, 2016 at 18:30 Comment(1)
No one has any answer?Biscuit
E
4

To do so, you'll first need to put the Country attribute in your attributesForFaceting list. You can do that using the REST API, your client of choice or from the Algolia Dashboard. Using the later one, go to the Indices page, select your index and click on the Display tab. Here, you could add your Country field to the Attributes for faceting list. After that, click on save and your index will be rebuild.

Now, your index is ready to filter the search queries according to the country you want. To perform the search query, you can use (using the Ruby client):

Contact.search("Batch", {
    facets: ["Country"],
    facetFilters: ["Country:Germany"]
})

For more informations about faceting, here is a quick intro from the FAQ and a more detailed guide in the documentation.

Eliezer answered 12/5, 2016 at 9:55 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.