Override engine defaults
Donât override engine defaults unless necessary
If your results arenât quite right, before tweaking the engine in an attempt to fix the problem, first perform these steps:
- Review the content of your data.
- Verify that both searchable attributes and custom ranking are well configured.
- Take a look at your analytics data for insights into how to improve your data or settings.
- Review the troubleshooting guide for Rules.
Search engine tweaks
If youâve gone through the preceding steps, here is a list of engine-level settings that you can look at to address persistent, âunsolvableâ problems.
- Override the default prefix setting
- Allow users to use quotes and negative query terms
- Enable search on some non-alphanumeric characters
- Override the default ranking formula
- Make the Words criterion first in the list
- Adjust the Exact criterion
- Adjust the Proximity criterion
These settings are global, so youâll need to be careful since every change affects every search. With a minor tweak, you may solve one problem but create others, or worse, undermine your entire search solution.
Adjusting prefix search
Prefix matching is central to Algoliaâs as-you-type search experience. It enables the engine to start matching records based on partial words.
For example, as soon as a user types a
, ap
, apr
, any records containing apricot
will be returned. Thereâs no need for the engine to wait for a full-word match before displaying results.
By default, only the last word in a query is treated as a prefix: all other text in the query must be a complete match.
You can change this and get more results by making all text in a query match the prefix.
Advanced syntax
When Algoliaâs advanced syntax is enabled (advancedSyntax
), search queries are treated differently in two significant ways:
- Matching phrases within quotes
- Excluding words
Advanced syntax enables both these behaviors by default but you can enable them individually with (advancedSyntaxFeatures
).
Match phrases within quotes
Terms in quotes must match exactly. For example, sparkly blue "iPhone case"
only returns records containing the exact string, âiPhone caseâ but âsparklyâ and âblueâ could occur anywhere in the record.
Algoliaâs typo tolerance is turned off inside quotes.
Exclude words from search
To exclude a word from a search, prefix it with a minus sign. For example, search -engine
only matches records that contain âsearchâ and donât contain âengine.â
Enable search on non-alphanumeric characters
By default, separators (such as !#()[]{}*+-_äž,:;<>?@/\^|%&~£„$§âŹ
âââââââ âĄ`)arenât included in indices and, hence, canât be searched. for. The query âyahoo!â becomes âyahooâ.
To ensure that you can search for terms like âGoogle+â or âC#â, you must override the default and ensure that +
and #
are treated like alphanumeric characters.
Change the ranking formula criteria
You are strongly discouraged from changing the ranking formula unless you understand the global impact of the change. While changing the ranking formula might solve some queries, it might cause unexpected consequences for all others.
Make Words the first ranking formula criterion
The most common change, and least risky, is to put the Words criterion as the first entry in the ranking formula.
Moving the criterion is often done when dealing with long documents and queries, where you care about how many words match.
The more words that match, the more likely the document is relevant.
This works in connection with optionalWords
.
Algoliaâs DocSearch uses this âWord firstâ approach.
Adjust the Exact criterion
The Exact criterion behaves like a counter: if an exact match occurs in an attribute, the Exact counter is incremented by 1. The higher the Exact count, the higher the record is ranked.
- An exact match is where a complete word in a query matches fully without typos to a word in an attribute.
-
An inexact match is one with typos or matched by a prefix.
- âstarâ is an exact match to âStar Warsâ.
- âStaâ is an inexact match to âStar Warsâ
Synonym matching and plural/singular matching are considered exact.
- Single-word matches on single-word attributes rank higher than multi-word exact matching.
You can adjust one or more of these behaviors.
Adjust the Proximity criterion
By default:
- Adjacent words rank higher than words with one word between them
- Words with one word between them rank higher than words with two words between them, and so on
You can override this default behavior by increasing the minimum proximity up to 7.
For example, consider the query âjavascript frameworkâ. If you set minProximity to 2, two records containing âJavaScript frameworkâ and âJavaScript charting frameworkâ have the same proximity score.
Large attributes affect proximity
If you have attributes of more than 1,000 characters, Algolia will assign all matched words after the 1,000th character a proximity score of 8 (the lowest).
If you have such large attributes, you should split them into smaller components.