Is it possible to restrict query to match only the beginning of attributes?

For instance, say someone types in “lets buy”. I want to match “lets buy food” but not “instead lets buy”. In regex terms, lik /^lets buy/.

Is that possible with Algolia?

Yep, you can use the different settings of prefix, and if you want to give an extra relevance to the “exact match”, i.e. complete words that start the same as the record, you can use optionalFilters (enterprise feature).

Feel free to ask more information if needed, the exact way of solving this relevance issue depends a bit on how your data is structured

Thanks for the reply! I re-read those docs and none of them seem applicable to my scenario though. Like if I have an attribute called title, lets say the following objects exist:

  1. Lets buy broccoli
  2. Lets purchase broccoli
  3. In the future, lets buy broccoli

If the user types in lets buy as their query, I want to only return (1). I don’t think any of the prefix options help me here. Am I missng something?

Hey Robert, you can use the ordered attribute actually, I misunderstood your question when reading it first :sweat:

You can read more about it here:

Ok, cool. I noticed that is the default. So what I’m thinking is that there isn’t a way to tell Algolia “only send me results that begin with the query” like I was hoping. However, I can rank those first. And thus I can do some post-processing of the results I get back and just remove any that aren’t prefixed by the term before rendering them for the user.

Thanks for all the support @haroen!

Yes, to completely filter the other results out, you’ll need to do some post-processing on the client side, I don’t see another way for now