I attempted building the autocomplete based on multiple attributes of an Algolia document, however its purpose does not really help me at completing a phrase but it directs me at selecting a specific product.
If you want to suggest some searches instead of products/objects you can build an index with your searches logs. You can use Algolia's Analytics API + top searches endpoint to get them if you don't have them yet.
You could then store them in a popular_searches
index like that:
{
"value": "my popular search",
"count": 42 // the search frequency
}
And configure:
searchableAttribute
to target the value
attribute
customRanking
to use desc(count)
as the attribute reflecting the popularity
That being said, you should know that such popular searches autocomplete can be super complex to setup to reach the UX of Amazon/Google:
- make sure that the searches you use are popular enough (remove low frequencies)
- make sure the searches you use are actually retrieving results -> to ensure your users will get results while selecting it from the dropdown menu (you can query your product index at build-time)
- make sure your searches are not containing SPAM (super easy to do a script bombarding your API to make a spam search very popular so it goes in your dropdown menu)
- make sure your searches don't include offensive/bad words :) (Even google has a hard time with that)
tldr; If you have choice, precompute a list of searches from your products/objects instead of using your query logs :) It will be safer & easier to maintain (I'm pretty sure that's what Amazon do).