Sort by max numbers of currect words and min numbers of wrong words

So i am doing the Movie title thing, where i save names of movies.
Lets say i have the following:

  • Iron Man
  • Iron Man Goes again.
  • Iron Man 2
  • Iron Maiden

Then i search for “Iron Man” want the order to be:

  1. Iron Man
  2. Iron Man 2
  3. Iron Man Goes Again
  4. Iron Maiden.

I want to sort on the following:

  1. Numbers of currect words.
  2. Numbers of non currect words.

So my 4 words is incompare to the search Query “Iron Man”
Iron Man
2 currect words. 0 wrong words.
Iron Man 2
2 currect words. 1 wrong words.
Iron Man Goes Again
2 currect words. 2 wrong words.
Iron Maiden
1 currect words. 1 wrong words.

My problem is that when i can also sort after currect words, and have 20 titles starting with “Iron Man”, then i sometimes have to get to item 15 before i get the only “Iron Man” title.

Is there anything i can do here? :slight_smile:

Hi Peter,

When searching for “Iron Man”, in order to have the “Iron Man” movie as the first result, you have to pay attention to the order of your searchable attributes.
We have a documentation about that here: Searchable Attributes | Managing Results | Guide | Algolia Documentation

I made a small test with a new index and the examples you mention, and it works as you expected. What I did is:

  • don’t change rankingAndSorting
  • in searchableAttributes set the attribute that holds the title first.

There’s also a detailed doc on configuring searchable attributes here: Configuring Searchable Attributes the Right Way | How to | Managing Results | Guide | Algolia Documentation

I tried it out and it worked! Did read the doc about it before, but i think i just ended up doing it with a more comlicated logic that needed. Ofcause i should just ude Title as the sort attribute. :slight_smile:

Many thanks for the quick help!