liveBook · Manning

Tokenization

As explained in MongoDB 8.0 in Action, Third Edition

Tokenization is the process of dividing a stream of text into smaller units called tokens.

Tokenization divides text into searchable units called tokens, such as words, phrases, or symbols. In Atlas Search, an analyzer processes text when it is indexed or queried. The resulting index terms let a search index locate matching documents without scanning every document. section 11.3.3 section 11.2

Choose how text becomes searchable terms:

  • Select a tokenizer to split the text. The built-in whitespace analyzer splits at whitespace, while the simple analyzer splits at nonletter characters. section 11.3.3
  • Use analyzer filters to account for variations such as punctuation, capitalization, and unnecessary words. Normalizing text to lowercase can make differently capitalized text searchable as the same term. section 11.3.3 section 11.2
  • Specify an analyzer for indexed fields and, if needed, a searchAnalyzer for query text. Atlas Search uses its standard analyzer when none is specified; custom analyzers can combine built-in character filters, tokenizers, and token filters. section 11.3.3

Matching inspection records

In a simplified inverted index, two inspection records share the terms “NO VIOLATION ISSUED” and “MOBILE FOOD VENDOR - 881.” A query matched against those terms returns both records. Their relevance scores can still differ: matching terms that occur frequently in a document gain weight, while terms common across the collection gain less. section 11.2

Table 11.3 Atlas Search built-in analyzers

Analyzer

Description

Standard

Uses the default analyzer for all Atlas Search indexes and queries

Simple

Divides text into searchable terms wherever it finds a nonletter character

Whitespace

Divides text into searchable terms wherever it finds a whitespace character

Language

Provides a set of language-specific text analyzers

Keyword

Indexes text fields as single terms

Compare the built-in analyzers before choosing how to split a field: whitespace and simple split differently, while keyword indexes a text field as one term. section 11.3.3

Listing 11.1 Atlas Search index syntax
{
  "analyzer": "<analyzer-for-index>",
  "searchAnalyzer": "<analyzer-for-query>",
  "mappings": {
    "dynamic": <boolean>,
    "fields": { <field-definition> }
  },
  "analyzers": [ <custom-analyzer> ],
  "storedSource": <boolean> | {
    <stored-source-definition>
  },
  "synonyms": [
    {
      "name": "<synonym-mapping-name>",
      "source": {
        "collection": "<source-collection-name>"
      },
      "analyzer": "<synonym-mapping-analyzer>"
    }
  ]
}

The index definition shows where to set the indexing analyzer, the query analyzer, and custom analyzers. section 11.3.3

How MongoDB 8.0 in Action, Third Edition covers it

How deep it goes
Explains splitting, normalization, filters, and analyzer selection, but leaves custom-analyzer construction to external documentation.
Examples
Uses two inspection documents, their shared indexed terms, a matching query, and a table of built-in analyzers.
What it assumes
Assumes basic familiarity with documents and queries while defining tokens and analyzers in place.
What you can do after
Operate/configure it in Atlas Search by selecting indexing and query analyzers or defining a custom analyzer.
How it connects
Links tokenization to analyzers, inverted indexes, normalization, and relevance scoring.

Also explained in

Compare how 25 books explain tokenization →

Related concepts

This explainer was generated by Manning's knowledge graph from the text of MongoDB 8.0 in Action, Third Edition. The section links point to the parts of the book it draws on.