# `AshScylla.Search.Indexer.Updater`
[🔗](https://github.com/ohhi-vn/ash_scylla/blob/main/lib/ash_scylla/search/indexer/updater.ex#L1)

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.

# `fetch_old_terms`

```elixir
@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`

```elixir
@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.

---

*Consult [api-reference.md](api-reference.md) for complete listing*
