liveBook · Manning

Token

As explained in MongoDB 8.0 in Action, Third Edition

A token is a text unit produced during analysis for indexing and searching, such as a word, phrase, or symbol.

A token is a searchable unit produced from text, such as a word, phrase, or symbol. Tokenization lets a search index work with parts of a string rather than only the complete string. An inverted index associates those units with documents so a query can find matching documents quickly. section 11.3.3 section 11.2

An analyzer determines how text becomes searchable terms. Its tokenizer segments the text; filters then adjust the resulting tokens for variations such as punctuation, capitalization, and unnecessary words. The same choice matters for query text: Atlas Search lets you specify an analyzer for indexing and a search analyzer for queries. If you specify neither, it uses the standard analyzer. section 11.3.3

Matching inspection records

Two inspection documents contain the values “No Violation Issued” and “Mobile Food Vendor - 881.” In a simplified inverted index, each value is a searchable unit associated with both documents. A query using those units can therefore find both records. This example uses multiword units; the tokens produced in an actual index depend on its analyzer. section 11.2 section 11.3.3

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 built-in analyzers before choosing token boundaries: whitespace splits at spaces, simple splits at nonletters, and 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>"
    }
  ]
}

Use the index definition’s analyzer and searchAnalyzer fields when indexing text and processing query text call for different analyzer choices. section 11.3.3

How MongoDB 8.0 in Action, Third Edition covers it

How deep it goes
Defines tokenization and explains analyzers, tokenizers, and filters, but stops short of implementing a tokenizer.
Examples
Illustrates matching with two inspection documents and compares standard, simple, whitespace, language, and keyword analyzers.
What it assumes
Introduces tokenization from its definition while using MongoDB documents and search indexes as the working context.
What you can do after
Operate/configure it by selecting Atlas Search analyzers for indexed fields and query text.
How it connects
Connects tokens to inverted indexes, analyzers, normalization, and full-text search.

Also explained in

Compare how 31 books explain token →

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.