AshScylla.Search.Indexer.Updater (AshScylla v1.6.1)

Copy Markdown View Source

Updates the inverted index when a document's text changes.

Computes the diff between old and new terms:

  1. Fetches the old term set from search_post_fields
  2. Analyzes the new text to get new terms
  3. Removes terms present in old but not new
  4. Adds terms present in new but not old

This avoids re-indexing unchanged terms.

Summary

Functions

Fetches the stored term set for a post field from search_post_fields.

Updates the index for a single field of a post.

Functions

fetch_old_terms(repo, keyspace, post_id, field)

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

Fetches the stored term set for a post field from search_post_fields.

Returns an empty MapSet if no terms are found.

update_field(repo, keyspace, post_id, field, new_terms, old_term_set)

@spec update_field(
  module(),
  String.t(),
  String.t(),
  non_neg_integer(),
  [{String.t(), pos_integer()}],
  MapSet.t()
) :: :ok | {:error, term()}

Updates the index for a single field of a post.

Takes the repo, keyspace, post_id, field number, and the new text. Reads the old terms from search_post_fields, computes the diff, and applies only the necessary inserts and deletes.

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