Algorithm Search⌘K

Indexing and query processing

Problems

  • Phrase query

    Find the documents in which the query terms occur next to each other in the given order.

    O(M + r P) positional_indexintro
  • Posting list intersection

    Given the sorted posting lists of the terms of an AND query, output the documents that appear in all of them.

    O(m log(n/m + 1)) gallopingintro
  • Ranked retrieval

    Given a query and a scoring function, return the k documents of highest score, ideally without scoring every document.

    O(T (m + log k)) exhaustiveintro
  • Dynamic index maintenance

    Keep an inverted index current while documents are added and deleted, with fast queries and low merge cost.

    core
  • Wildcard query

    Find the documents that contain any term matching a pattern with wildcards, such as mon*h.

    O(L + n q + P log r) dictionary_scancore
  • Document identifier reassignment

    Renumber the documents of a collection so that the gaps in the posting lists are small and the index compresses best.

    advanced

Algorithms

  • Merge-based list intersection

    Walks two sorted posting lists with one pointer each and advances the smaller, in time linear in the sum of the lengths.

    O(m + n) worst1 languagesintro
  • Blocked sort-based indexing

    Builds an inverted index on disk by sorting blocks of termid-docid pairs in memory and merging the sorted runs.

    O(T log T) worst · average · best1 languagescore
  • Document-at-a-time evaluation

    Reads all query posting lists in parallel in docid order and scores each document fully before moving on, keeping a heap of the best k.

    O(T (m + log k)) worst1 languagescore
  • Logarithmic merging

    Keeps indexes of sizes n, 2n, 4n and so on, and merges two of equal size like a binary counter, so each posting is merged O(log(T/n)) times.

    Θ(T log(T/n)) build1 languagescore
  • Porter stemmer

    Removes English suffixes in five rule phases, each rule guarded by a condition on the measure of the remaining stem.

    O(n) worst · best1 languagescore
  • Positional intersection

    Intersects two positional posting lists and, inside each common document, merges the position lists to find occurrences within distance k.

    O(m + n + P + z) worst1 languagescore
  • Single-pass in-memory indexing

    Builds a separate dictionary and posting lists for each block in one pass with no global term ids, then merges the blocks.

    O(T log T) worst1 languagescore
  • Term-at-a-time evaluation

    Reads the posting lists one term after another and adds each term's contribution into a score accumulator per document.

    O(T (1 + log k)) expected1 languagescore
  • Baeza-Yates intersection

    Searches the median of the shorter list in the longer one and recurses on both halves, adapting to the ratio of the list lengths.

    O(m log(n/m + 1)) worst1 languagesadvanced
  • Geometric partitioning

    Keeps index partitions whose sizes grow geometrically by a ratio r, or at most p of them, trading merge cost against the number of partitions a query reads.

    O(r T log(T/b) / log r) build1 languagesadvanced
  • MaxScore

    Splits query terms into essential and nonessential by their score upper bounds, and skips documents that only nonessential terms could lift into the top k.

    O(T (m log T + log k)) worst1 languagesadvanced
  • Simple-9 coding

    Packs as many small integers as fit into each 32-bit word, using 4 selector bits to choose one of nine equal-width layouts.

    O(n + W) decode1 languagesadvanced
  • Small-versus-small intersection

    Intersects many lists by taking the two shortest first and searching each candidate of the short list in the next one by galloping.

    O(m log(n/m + 1)) worst1 languagesadvanced
  • WAND

    Sorts posting cursors by docid and finds a pivot where the summed term upper bounds first exceed the heap threshold, skipping all earlier documents.

    O(T m log m) worst1 languagesadvanced
  • Block-max WAND

    Refines WAND with score upper bounds stored per block of postings, so whole blocks are skipped when their local bounds cannot reach the threshold.

    O(T m log m) worst1 languagesresearch
  • Demaine-Lopez-Ortiz-Munro adaptive intersection

    Intersects k sorted sets by cycling through them with galloping search, in time bounded by the size of a proof of the result.

    Ω(m log(n/m + 1)) lower1 languagesresearch
  • Recursive graph bisection for index reordering

    Orders documents by recursive balanced bisection of the term-document graph, moving documents to minimize a log-gap cost.

    O(I (m + n log n) log n) total1 languagesresearch

Data structures

  • Posting list

    The sorted list of document ids, with optional frequencies and positions, for one term of an inverted index.

    O(1) access1 languagesintro
  • Permuterm index

    Indexes every rotation of each term with an end marker, so a wildcard query becomes a prefix lookup in a search tree.

    O(l (l log K + K)) delete · insert1 languagescore
  • Positional index

    An inverted index whose postings store, for each document, the positions where the term occurs, so phrase and proximity queries can be answered.

    O(L) expected add_document1 languagescore
  • Tiered index

    Splits each posting list into tiers by score, and reads lower tiers only when the higher tiers give fewer than k results.

    O(n log r) build1 languagescore
  • k-gram index

    Maps each character k-gram to the dictionary terms that contain it, for wildcard queries and spelling correction.

    O(k l + l P) delete · insert1 languagescore
  • Impact-ordered index

    Sorts each posting list by precomputed impact scores, so query evaluation reads the highest impacts first and can stop early.

    O(n log n) build1 languagesadvanced
  • Signature file

    Stores for each document a bit signature made by OR-ing hashed term codes, so a scan rejects most documents without false negatives.

    O(m D + F/w) insert1 languagesadvanced
  • Partitioned Elias-Fano index

    Splits each posting list into chunks chosen by dynamic programming and codes each chunk with Elias-Fano or a bitmap, to fit local density.

    O(log m) access1 languagesresearch

Techniques

  • Stemming

    Maps the inflected and derived forms of a word to one stem before indexing and querying, so that a query word also matches its variants.

    intro
  • Stop word removal

    Drops the most frequent function words from the index or the query, to save space and time at a small cost in recall.

    intro
  • Front coding

    Stores each term of a sorted dictionary as the length of the prefix it shares with the previous term plus its remaining suffix.

    1 languagescore
  • Postings gap encoding

    Stores the differences between consecutive document ids of a posting list, which are small and compress well with integer codes.

    core
  • Skip pointers

    Adds about sqrt(n) forward pointers to a posting list so an intersection can jump over runs that cannot match.

    core
  • Static index pruning

    Removes low-impact postings from an inverted index at build time, so the index is smaller and faster with a small, measured loss in ranking quality.

    advanced

Concepts

  • Index partitioning

    Distributes an index over machines either by documents, each node holding a full local index, or by terms, each node holding whole posting lists.

    core

Definitions

Models

  • Heaps' law

    The number of distinct terms in a collection of T tokens grows as k T^b with b near one half.

    intro
  • Zipf's law

    The frequency of the i-th most common term in a collection is roughly proportional to 1/i.

    intro