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

Copy Markdown View Source

Applies aggregate-level index diffs for a document.

Postings are stored at document level (one row per term with total frequency), while search_post_fields keeps per-field maps. An update:

  1. Computes the new merged document totals from the stored field maps and the newly analyzed fields
  2. Deletes posting rows whose total dropped to zero
  3. Upserts posting rows whose total changed
  4. Rewrites the search_post_fields rows of every updated field

This keeps multi-field documents correct even when a term is shared across fields (removing it from one field only lowers the total).

Summary

Functions

Applies a precomputed diff between merged old and new document totals.

Functions

apply_diff(repo, keyspace, post_id, upserts, deletes, field_maps)

@spec apply_diff(
  module(),
  String.t(),
  String.t(),
  [{String.t(), pos_integer()}],
  [String.t()],
  %{
    required(String.t()) => [{String.t(), pos_integer()}]
  }
) :: :ok | {:error, term()}

Applies a precomputed diff between merged old and new document totals.

  • upserts[{"term", new_total}] postings that are new or changed
  • deletes["term"] postings removed entirely
  • field_maps%{"field" => [{term, tf}]} analyzed maps of the fields being updated; fields with an empty list have their stored row deleted

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