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

Boolean operations on posting lists.

Implements efficient set operations using a two-pointer merge algorithm
with O(n + m) complexity — identical to how Lucene performs intersections
and unions.

Supports:
  * AND — intersection of posting lists
  * OR — union of posting lists
  * NOT — difference of posting lists

# `posting_list`

```elixir
@type posting_list() :: [{String.t(), non_neg_integer(), non_neg_integer()}]
```

# `scored_post`

```elixir
@type scored_post() :: {String.t(), float()}
```

# `and_intersect`

```elixir
@spec and_intersect([posting_list()]) :: [{String.t(), non_neg_integer()}]
```

Computes the AND intersection of multiple posting lists.

Uses a two-pointer merge algorithm for each pair of lists.

## Example

    iex> BooleanEngine.and_intersect([
    ...>   [{"a", 1, 0}, {"b", 1, 1}, {"c", 1, 2}],
    ...>   [{"b", 1, 0}, {"c", 1, 1}, {"d", 1, 2}]
    ...> ])
    [{"b", 1}, {"c", 1}]

# `not_difference`

```elixir
@spec not_difference(posting_list(), posting_list()) :: [
  {String.t(), non_neg_integer()}
]
```

Computes the difference: posts in `include` that are NOT in `exclude`.

## Example

    iex> BooleanEngine.not_difference(
    ...>   [{"a", 1, 0}, {"b", 1, 1}, {"c", 1, 2}],
    ...>   [{"b", 1, 0}]
    ...> )
    [{"a", 1}, {"c", 1}]

# `or_union`

```elixir
@spec or_union([posting_list()]) :: [{String.t(), non_neg_integer()}]
```

Computes the OR union of multiple posting lists.

## Example

    iex> BooleanEngine.or_union([
    ...>   [{"a", 1, 0}, {"b", 1, 1}],
    ...>   [{"b", 1, 0}, {"c", 1, 1}]
    ...> ])
    [{"a", 1}, {"b", 1}, {"c", 1}]

---

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