🎉 Try the public beta of the new docs site at algolia.com/doc-beta! 🎉
Guides / Managing results / Optimize search results / Override engine defaults

Adjusting the Exact criterion

The Exact ranking criterion helps users find what they want by showing the most relevant results. When users search for something, the engine will rank records with the exact query words higher than those with similar (inexact) words. For example, if you search for “dog food,” records that contain the exact phrase “dog food” will rank higher than records that contain the words “dog” and “food”, such as “dog treats” or “food for dogs.”

An exact match occurs when a full word in a query completely matches a full word in an attribute. An inexact match has typos or only matches a prefix. For example:

  • “star wars” is an exact match for “Star Wars”
  • “Stare wa” is an inexact match for “Star Wars”
  • “Star wa” is an exact match for “Star”, and an inexact match for “Wars”

How is the Exact criterion computed?

The Exact criterion is a counter: if an exact match occurs in an attribute, the count is incremented by 1. The higher the count, the higher the record is ranked.

  • The counter works with single or multi-word queries, but every word is treated separately. If the query contains two words that match exactly in the same attribute, that’s 2 points, 1 for each match. If the first word matches in one attribute, and the second in another, that’s also 2 points.
  • Single-word matches on multi-word attributes aren’t considered exact matches by default. For example, on the single-word query “road”, only a record with an attribute equal to “road” would be considered an exact match. A record with an attribute containing the term “road trip” wouldn’t be an exact match in this case.
  • Exact words are only counted once per record. If the same word has 10 exact matches in a record, whether in the same attribute or not, that query word still gets only 1 point. This means exact is always a number between 0 and the number of words in the query.
  • Synonyms and singular/plural forms of a word are considered to be exact. If a word’s synonym is a precise match, it’s considered to be exact.

A record’s Exact score differs from the Words criterion score because the Words criterion considers inexact matches. A record’s Exact score may be less than the number of query words because of inexact matches or if you’re using the optionalWords setting.

For example, for the query “Apple iPhon 14”, a record containing “iPhone 14” (and not “Apple”) would have a Words score of 2 and an Exact score of 1, even though there are three query words.

This is only possible if optionalWords includes “Apple” since, by default, a record must contain all query words to be considered a match.

What adjustments can be made to the Exact settings?

You can change the settings to make single-word queries behave differently or to turn off Exact for some attributes. This can help users find what they’re looking for more easily.

Single-word exact queries

By default, the engine treats single-word queries differently than multi-word queries. Single-word queries only increment the count when they exactly match single-word attributes.

Change this default and make single-word queries behave similarly to multi-word queries by setting exactOnSingleWordQuery to word. Consider doing this if you don’t have many important single-word attributes and want matches on single-word and multi-word attributes to rank evenly.

Turn off Exact for some attributes

You can remove the Exact score computation from attributes with the disableExactOnAttributes setting.

If you have an extensive description attribute (making it more likely to have an exact match), consider removing Exact on this attribute. By doing so, you favor exact matching on other, more meaningful attributes such as title or name. This gives attributes with shorter content more control over ranking than those with more extensive content.

Changing the default meaning of Exact

By default, the engine counts singular/plural and single-word synonym matches as exact matches. For example, if you have a synonym between “swimwear” and “swimsuit”, a search for “swimwear” will count as an exact match on a record with the word “swimsuit”. Multi-word synonyms aren’t counted as exact matches. Change this default using alternativesAsExact. In practice, there is rarely a good reason to do this.

See also

Did you find this page helpful?