AshScylla.Search.Indexer (AshScylla v1.6.1)

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.

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.

Indexes a new document into the inverted index.

Updates a document's indexed terms.

Types

field_map()

@type field_map() :: %{optional(atom()) => 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_num)

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

Removes a single field from the index for a document.

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:

  1. Analyzed (tokenized, normalized, stemmed)
  2. Written to search_post_terms and search_post_fields

Fields are numbered sequentially starting from 0 in the order they appear in the map.

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.

For each field, computes the diff between old stored terms and new analyzed terms, then applies only the necessary inserts and deletes.

Fields that haven't changed are left untouched.