Ranking exact word matches higher than compound words


My index consists of food names in Finnish language. I’m trying to figure out how to rank “regular” first word matches higher than compound word matches. I have my name searchableAttribute set as ordered and the field is included in decompounedAttributes. Yet, compound words seem to rank over non-compound. For example, search string ‘peruna’ produces results:

Peruna, keitetty
Peruna, kuorittu

The last two are an exact first word match and should rank higher than the preceding four compound words. How can I accomplish that?


Scenarios like this are when I like to look at the ranking results in the Dashboard when searching for the values. I took the values provided above and set up an index to test this out and saw this as the results:

What this shows is that our ranking criteria (by default) ranks these items exactly the same because they both contain the word but do not contain the word by itself (like just Peruna does). Setting the attribute to ordered won’t help with this exact issue as this would only make results that include the query at the beginning rank higher (but in both of these results it is the first word - so it’s not applicable here).

While I was unable to find a configuration value to help with this specifically, one thing you can do is add a pre-sorting to the values before the ranking algorithm takes place. This way, the results will sort naturally in the way you are looking for.

To do this, navigate to your Index and select ‘Configuration’, and then ‘Ranking and Sorting’. Click the ‘Add sort-by attribute’ and type the attribute name that houses your food names (ex name) and set it as Ascending. Drag this sort-by attribute to the bottom of the ranking algorithm so that the Ranking Criteria is run afterward and still provides relevant results (otherwise, if it was at the top, it would just sort your results with no relevance).

Although if anyone knows of a way to rank it another way please let me know! Thanks!

@michael.king Thanks for the suggestion! However, none of my searchable attributes (including name) are available to be selected via ‘Add sort-by attribute ’ Only attributes which are not selected as searchable are available.

Your screenshot suggests you may have selected ‘A custom ranking attribute’ instead. Is that what you meant?

The field names don’t prepopulate for me either but it does let me select an attribute I have marked as searchable if I just type it out:

Did you get a specific error message when trying this? I can try to reproduce it on my side.

@michael.king Hmm…this is interesting. I can also type it out and, by default, it get’s added to the top of Ranking and Sorting list as a ‘Sort by’ criteria. However, if I drag it to the bottom of the list it transforms into a Custom Ranking criteria. :thinking:

Ah, I see. I think this is just how we classify the criteria. I just confirmed you can add a ‘Custom Ranking’ and set it to Ascending as well and it’ll function the same (since they are technically the same under the hood I guess).

1 Like

@michael.king Ten-four, thanks! This solution may work well for me in combination with a couple other custom ranking criteria.