AshScylla.Search.Indexer (AshScylla v1.9.0)

Copy Markdown View Source

Index management coordinator.

Orchestrates indexing, updating, and deleting documents in the inverted index. Delegates to Builder, Updater, and Deleter sub-modules.

Fields are identified by name, so partial updates only ever touch the fields present in the given map. Postings are stored at document level: a term shared across fields is stored once with its summed frequency, and updates recompute those totals from the per-field maps.

Usage

# Index a new document
Indexer.index(repo, keyspace, post_id, %{title: "Hello World", body: "Elixir is great"})

# Update a document
Indexer.update(repo, keyspace, post_id, %{title: "Updated Title", body: "New content"})

# Delete a document
Indexer.delete(repo, keyspace, post_id)

Summary

Functions

Removes a document entirely from the inverted index.

Removes a single field from the index for a document. Shared terms keep their contributions from remaining fields.

Indexes a new document into the inverted index.

Updates a document's indexed terms.

Types

field_map()

@type field_map() :: %{optional(atom() | String.t()) => String.t()}

Functions

delete(repo, keyspace, post_id)

@spec delete(module(), String.t(), String.t()) :: :ok | {:error, term()}

Removes a document entirely from the inverted index.

delete_field(repo, keyspace, post_id, field_name)

@spec delete_field(module(), String.t(), String.t(), atom() | String.t()) ::
  :ok | {:error, term()}

Removes a single field from the index for a document. Shared terms keep their contributions from remaining fields.

index(repo, keyspace, post_id, fields, opts \\ [])

@spec index(module(), String.t(), String.t(), field_map(), keyword()) ::
  :ok | {:error, term()}

Indexes a new document into the inverted index.

Accepts a map of field names to text values. Each field is analyzed (tokenized, normalized, stemmed); the per-field maps are aggregated into document-level postings and written in a single batch.

Returns :ok on success or {:error, reason} on failure.

update(repo, keyspace, post_id, fields, opts \\ [])

@spec update(module(), String.t(), String.t(), field_map(), keyword()) ::
  :ok | {:error, term()}

Updates a document's indexed terms.

Reads the stored per-field maps, applies the newly analyzed text for every field present in the map, recomputes document-level totals, and writes only the changed postings. Fields omitted from the map are left untouched.