Guides / Managing results / Optimize search results

Override Engine Defaults

Don’t override engine defaults unless it’s necessary

There are times when you want to dig deeper into how the engine functions. Not out of curiosity, but because your results aren’t quite right, and you think tweaking the engine will fix the problem.

Before taking that step, you should look at a few other things:

  1. Review the content of your data.
  2. Verify that both searchable attributes and custom ranking are well configured.
  3. Verify that you’ve chosen the best search and index settings for your data and needs.
  4. Take a look at your analytics data for insights into how to improve your data or settings.
  5. Review the troubleshooting guide.

If you’ve gone through these steps, here is a list of engine-level settings that you can look at to address persistent, “unsolvable” problems.

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.

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:

  • Phrasal queries
  • Excluding words

Advanced syntax enables both these behaviors. You can’t enable the behaviors individually.

Matching 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.

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.”

API reference AdvancedSyntax

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.

API reference SeparatorsToIndex

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 product 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.

API reference MinProximity
Did you find this page helpful?