I might be dumb. Is it possible to rank full words that match entered text higher?

Hello, folks!

I may be dumb. It’s true. Here’s the scenario I’m looking at…

User types “car” into my search bar. Results pop up. Yay! Everything’s going so well! The results are:

  1. Carton

  2. Carnival

  3. Carbon Footprint

  4. Car Place

  5. Care Package

What I would LOVE is for “Car Place” to be at the top, since what the user entered (“car”) matches one entire word in “Car Place” while it’s only a substring match for the others.

So far, I haven’t managed to figure out how to make this happen. Am I missing something? Is it impossible? Any help would be greatly appreciated!

PS: I know that all the user has to do it hit space (making their search “car_”) and “Car Place” pops up to the top…but that wouldn’t be intuitive to a user.

Hi Daniel,

Thank you for contacting us. Yes, this is possible to have this behaviour. There is a special case when the query contains only one word. The rule of the ranking formula will match if an attribute in the record contains only the word in the query (in you case, it would work if a record have an attribute that contains only “car”).

To change that you can update the settings and set exactOnSingleWordQuery to word instead of attribute. Currently this is not possible to do this update from the dashboard, you have to do it in your code.

Here is the documentation to do this :

Don’t hesitate to contact us again if you have any other questions!

2 Likes

Thanks so much, @karim.matrah! That worked perfectly.

I do have a follow-up question, if you don’t mind.

Since you and others have probably done a lot more thinking about this than I have, can you think of a reason why making this change would not be advisable? Obviously the parameter is set to “attribute” by default for a reason, and I don’t want to make a change for one situation that negatively affects other situations.

Any thoughts there?

Yes this can affect other queries, but there is no general rule about which one is better. It depends on your dataset. For example, with exactOnSingleWordQuery set to word, if you search for “new”, it will promote to the top all the records that contain the common word “new” and put at the end those who contain nouns like “Newark”.

The best thing to do is to try both and choose the one that suits your needs :slight_smile:

Let us know if you have any other questions after doing some tests.

1 Like