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

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)

# `field_map`

```elixir
@type field_map() :: %{optional(atom()) =&gt; String.t()}
```

# `delete`

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

Removes a document entirely from the inverted index.

# `delete_field`

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

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

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

---

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