Happy Friday Vijay!
In our Support channel, an engineer answered your question and I wanted to have it here for visibility to the community should anyone else have a similar question:
I can think of at least two directions to help you solve this:
- Explicitly search for phrase queries
By default, words from the search query must all appear in a record for it to match, but they need not appear contiguously, nor even inside the same attribute for that matter. (Of course, if they do, they should rank higher—see point #2 below.)
You can however ask for two words to be contiguous by using the advanced syntax (see the
advancedSyntax parameter) and surround the expression with double quotes.
If the query string is directly entered by your end-users, however, this may not be possible, so read on.
- Ensure proper ranking
By default, Algolia uses word proximity as one of the criteria in the ranking formula, which should ensure that contiguous words rank higher than non-contiguous words. If they don’t, it is likely that some other factor is interfering here. Most likely, your ranking formula contains other criteria before the “proximity” criterion that cause records to rank differently: for example, a sort by attribute, or geo location (if you are using geo search).
Check your ranking formula and let us know if we can be of more help.
Also, check out Ranking Guide to help you better understand how ranking works: https://www.algolia.com/doc/guides/relevance/ranking/