# `Redis.Commands.Search`
[🔗](https://github.com/joshrotenberg/redis_ex/blob/v0.7.1/lib/redis/commands/search.ex#L1)

Command builders for RediSearch (FT.*) full-text search and indexing.

Provides pure functions for creating and managing search indexes, running
full-text and numeric queries, performing aggregations, and managing
auto-complete suggestion dictionaries. Includes a schema builder DSL that
translates Elixir tuples into the FT.CREATE SCHEMA syntax.

All functions return command lists for use with `Redis.command/2` or
`Redis.pipeline/2`.

## Examples

    # Create a JSON index with text, numeric, and tag fields
    Redis.command(conn, Search.create("idx:users", :json,
      prefix: "user:",
      schema: [
        {"$.name", :text, as: "name"},
        {"$.age", :numeric, as: "age", sortable: true},
        {"$.email", :tag, as: "email"}
      ]
    ))

    # Full-text search with sorting and pagination
    Redis.command(conn, Search.search("idx:users", "@name:Alice",
      sortby: {"age", :asc},
      limit: {0, 20},
      return: ["name", "age"]
    ))

    # Aggregation with grouping and reduction
    Redis.command(conn, Search.aggregate("idx:users", "*",
      groupby: ["@age"],
      reduce: [{"COUNT", 0, as: "count"}],
      sortby: [{"@count", :desc}],
      limit: {0, 10}
    ))

# `aggregate`

```elixir
@spec aggregate(String.t(), String.t(), keyword()) :: [String.t()]
```

FT.AGGREGATE — run an aggregation query.

## Options

  * `:groupby` - list of fields to group by
  * `:reduce` - list of reduce functions `{func, nargs}` or `{func, nargs, as: alias}`
  * `:sortby` - `[{field, :asc | :desc}]`
  * `:limit` - `{offset, count}`
  * `:apply` - `{expression, as: alias}`
  * `:filter` - filter expression
  * `:params` - `[{name, value}]`
  * `:dialect` - query dialect version

# `alter`

```elixir
@spec alter(String.t(), {String.t(), atom()} | {String.t(), atom(), keyword()}) :: [
  String.t()
]
```

FT.ALTER — add a field to an existing index.

# `create`

```elixir
@spec create(String.t(), :hash | :json, keyword()) :: [String.t()]
```

FT.CREATE — create a search index.

## Options

  * `:prefix` - key prefix(es) to index (string or list)
  * `:filter` - filter expression
  * `:language` - default language
  * `:score` - default score
  * `:stopwords` - list of stopwords (or 0 for none)
  * `:schema` - list of field definitions (required)

## Schema Fields

Each field is a tuple: `{name_or_path, type}` or `{name_or_path, type, opts}`

Types: `:text`, `:tag`, `:numeric`, `:geo`, `:vector`

Field options:
  * `:as` - alias name
  * `:sortable` - enable sorting
  * `:noindex` - store but don't index
  * `:nostem` - disable stemming (text)
  * `:weight` - field weight (text)
  * `:separator` - tag separator (default ",")

# `dropindex`

```elixir
@spec dropindex(
  String.t(),
  keyword()
) :: [String.t()]
```

FT.DROPINDEX — drop an index.

# `info`

```elixir
@spec info(String.t()) :: [String.t()]
```

FT.INFO — get index information.

# `list`

```elixir
@spec list() :: [String.t()]
```

FT._LIST — list all indexes.

# `search`

```elixir
@spec search(String.t(), String.t(), keyword()) :: [String.t()]
```

FT.SEARCH — search an index.

## Options

  * `:return` - list of fields to return
  * `:limit` - `{offset, count}` (default: `{0, 10}`)
  * `:sortby` - `{field, :asc | :desc}`
  * `:nocontent` - return only IDs
  * `:verbatim` - don't expand query terms
  * `:params` - `[{name, value}]` for parameterized queries
  * `:dialect` - query dialect version

# `sugadd`

```elixir
@spec sugadd(String.t(), String.t(), float(), keyword()) :: [String.t()]
```

FT.SUGADD — add a suggestion string.

# `sugdel`

```elixir
@spec sugdel(String.t(), String.t()) :: [String.t()]
```

FT.SUGDEL — delete a suggestion.

# `sugget`

```elixir
@spec sugget(String.t(), String.t(), keyword()) :: [String.t()]
```

FT.SUGGET — get suggestion strings.

# `suglen`

```elixir
@spec suglen(String.t()) :: [String.t()]
```

FT.SUGLEN — get number of suggestions.

# `tagvals`

```elixir
@spec tagvals(String.t(), String.t()) :: [String.t()]
```

FT.TAGVALS — get all distinct tag values for a field.

---

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