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

Builds the inverted index for a document.

Takes the analyzed terms and writes them to the `search_post_terms` table
and the raw terms set to `search_post_fields` for later diff-based updates.

Uses `UNLOGGED BATCH` for efficient bulk writes.

## Usage

    Indexer.Builder.index(repo, keyspace, post_id, field_num, [
      {"phoenix", 2},
      {"elixir", 1}
    ])

# `index`

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

Indexes the analyzed terms for a single field of a post.

Writes term → post_id mappings to `search_post_terms` and stores
the set of unique terms in `search_post_fields` for future diffing.

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

# `index_fields`

```elixir
@spec index_fields(
  module(),
  String.t(),
  String.t(),
  %{required(non_neg_integer()) =&gt; [{String.t(), pos_integer()}]}
) :: :ok | {:error, term()}
```

Indexes analyzed terms across multiple fields for a post.

Accepts a map of `%{field_num => [{term, tf}]}` and writes all rows.

---

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