I'm busy implementing indexed search in Flutter / Dart using algolia. I've ran into a problem that's not an actual problem. I'm struggling to figure out how to query for autocomplete results. Meaning, if I pass in the term "burg" I should be getting back "bacon burger", "avo burger", etc.
The problem is not with flutter, I can do everything I want to in flutter. The problem is not with dart, I know my way around Dart well. The problem is with Algolia docs and how to implement autocomplete if they don't have a provided widget for the platform.
The things I've been googling that I would like to know is.
I'm using this plugin and have setup the instance properly as I can get results back from my indexed data on Algolia. I'm setting the facets and passing in values for those facetFilters. It works great for normal search but I can't figure out, from the docs, how to adjust my query to make it return auto complete results for potential matches and not the results of the actual search.
I hope that's clear. to make it even clearer. Things that I don't need.
I've looked at Query suggestions on Algolia docs but the code isn't very clear on what I need to query if i want to manually get these suggestions from the algolia instance. I've looked at autocomplete js queries are hidden, or at least from my eyes. I've looked at Autocomplete Vue to no avail. And every other auto complete link that popped up.
This question has been open for a long time. I assume you probably don't need an answer to it anymore, but given the amount of upvotes, it might still be worth answering it.
The behavior you're looking for is called "prefix matching" in Algolia's documentation.
The main parameter to control this behavior in Algolia is queryType
.
It accepts 3 values: prefixLast
, prefixNone
& prefixAll
.
prefixLast
treats only the last word of the query as a potential prefix.
All the previous words are matched as complete words.
It's a good fit for "as-you-type search" experiences, and most likely the value you were looking for.
This is the default value of this parameter, so you should just be able to run client.query("burg")
to get the expected behavior.
Note: if the last word is followed by a space, it is not considered as a prefix.
prefixNone
treats no word of the query as a potential prefix.
It's a good fit for traditional "press Enter -> get search results" experiences.
prefixAll
matches all words of the query as prefixes.
It's rarely a good option, as it might bring a lot of false positives.
If you'd like this behavior only for some words (e.g. "avo" for "avocado"), I'd suggest using synonyms instead.
https://www.algolia.com/doc/api-reference/api-parameters/queryType/
This parameter can be changed in your index settings, or at query time.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With