Concepts / Managing results / Handling Natural Languages (NLP)
Jan. 14, 2019

Handling Natural Languages (NLP)

Algolia support all languages

The Algolia engine supports all languages out of the box. For this to be possible, it uses a wide array of natural language techniques, ranging from the most general (finding words, using Unicode) to the most specific (distinguishing letters from logograms, breaking down compound words, and using single-language dictionaries for vocabulary).

We’ve organized this page around 4 natural language understanding strategies:

  • Engine-level processing (normalization)
  • Dictionaries
  • Query Processing
  • Natural Language Processing (NLP) with Query Rules
  • Configuring Typo Tolerance

Some language-based techniques (such as normalization) play an integral role in the engine, and are performed with every indexing and search operation. These are generally not configurable. Other techniques rely on specialized dictionaries, which facilitate word and word-root detection. These come with several configurable options. Finally, Algolia offers many other techniques (like typo tolerance, query rules) that can be enabled, disabled, or fine-tuned according to the use case. These are also configurable using Algolia’s API settings and suggested best practices.

How the engine normalizes data

Normalization is done at both indexing and query time, ensuring consistency in how your data is represented as well as matched.

You cannot disable normalization. Additionally, there is no language-specific normalization - what we do for one language we do for all. Our normalization process is, therefore,language-agnostic.

What does normalization mean?

  • Switch all characters to lower case
  • Remove all diacritics (eg accents)
  • Remove punctuation within words (eg apostrophes)
  • Manage punctuation between words
  • Use word separators (such as spaces, but not only)
  • Include or exclude non-alphanumeric characters (separatorsToIndex)
  • Transform traditional Chinese to modern

Adding Language Specificity using Dictionaries

As already suggested, some of our automated techniques do not work in all languages. Here we discuss how we add language-specific functionality to the Engine.

No automatic language detection

Algolia does not attempt to detect the language of your data nor the language of your end-users as they type in queries.

Therefore, to benefit from our language-specific algorithms, you will need to tell the engine in what language you want your data to be interpreted.

  • If you do not designate a language, we will consider that you want to support every language. The drawback here is that you will create ambiguities by mixing every language’s peculiarities. For example, plurals in Italian will be applied to plurals in English, causing problems such as the following: “paste”, the plural of “pasta” in Italian, will also be considered the plural of “pasta” in English, which is not the case, as “paste” in English is a word in its own right (to spread).
  • If you designate more than one language (say 2 or 3) - because your index contains more than one language - this is fine, as long as you prepare your data appropriately and carefully. For more on this, check out our multiple languages tutorial.

Using dictionaries

Several of our language-related methods require the use of dictionaries. With dictionaries, the engine can apply language-specific, word-based logic to your data and end-user queries. Each method below - whether it stops words or alternative forms - uses a different dictionary. The success of this approach relies on the accuracy and completeness of the dictionary we use. We regularly update these dictionaries.

Disabling typoTolerance and prefix search on specific words

The advancedSyntax boolean parameter provides a way to disable typo tolerance on specific words in a query by using double quotes: foot problems would be typo tolerant on both query words, while "foot" problems would only be typo tolerant on problems.

This parameter also disables prefix searching on words inside the double quotes.

Typo Tolerance and Languages

What is a typo?

  • A missing letter in a word, “hllo” → “hello”
  • An extraneous letter, “heello” → “hello”
  • Inverted letters: “hlelo” → “hello”

Typo tolerance allows users to make mistakes while typing and still find the words they are looking for. This is done by matching words that are close in spelling.

Typos as language-dependent

As you can see, we use English to illustrate the principle. That works because English is phonemic - it uses single characters to represent sound to form a word. Spelling errors are possible in that case.

However, for logogram-based languages (e.g., Chinese and o), which do not use single letters to represent sound but rely on pictures to represent words (or partial words), our typo logic is not really sensible.

For alphabet-based and phonemic languages (English, French, Russian, ..), we offer many ways to configure the engine to improve typo tolerance:

Natural Language Processing with Query Rules

You can set up rules (Query Rules) that tell the engine to look for specific words or phrases in a query, and if it finds them, to instruct the engine to take a specific action or change its default behavior.

For example, some query terms can be converted into a filter. If a user types in a filter value - say, “red” - that term can be used as a filter instead of as a search term. If the full query were “red dress”, then the engine would only look at the “red” records for the word “dress”. This is called dynamic filtering, where filter values are removed from the search and used directly as filters.

Dynamic filtering is only one way that Query Rules can understand and detect the intent of the user.

Did you find this page helpful?