# `Giza.SearchTables`

Table management functions for Manticore Search. Covers DDL (table lifecycle),
DML (writing to RT tables), clustered DML (replication-aware writes),
replication cluster management, and maintenance operations.

## Table Create Options
@see https://manual.manticoresearch.com/Introduction
@see https://manual.manticoresearch.com/Searching/Sorting_and_ranking#Ranking-overview
@see https://manual.manticoresearch.com/Searching/Spell_correction#Fuzzy-Search

# `cluster_add_table`

Add a table to a replication cluster.

## Examples

    iex> SearchTables.cluster_add_table("my_cluster", "products")
    {:ok, %SphinxqlResponse{}}

# `cluster_delete`

Delete from a replicated table using `cluster:table` notation.

## Examples

    iex> SearchTables.cluster_delete("my_cluster", "products", "id = 1")
    {:ok, %SphinxqlResponse{}}

# `cluster_drop_table`

Remove a table from a replication cluster. The table survives as a local
non-replicated table.

## Examples

    iex> SearchTables.cluster_drop_table("my_cluster", "products")
    {:ok, %SphinxqlResponse{}}

# `cluster_insert`

Insert into a replicated table using `cluster:table` notation.

## Examples

    iex> SearchTables.cluster_insert("my_cluster", "products", ["id", "title"], [1, "Laptop"])
    {:ok, %SphinxqlResponse{}}

# `cluster_replace`

Full upsert into a replicated table using `cluster:table` notation.

## Examples

    iex> SearchTables.cluster_replace("my_cluster", "products", ["id", "title"], [1, "Laptop"])
    {:ok, %SphinxqlResponse{}}

# `create_cluster`

Create a replication cluster.

## Examples

    iex> SearchTables.create_cluster("my_cluster")
    {:ok, %SphinxqlResponse{}}

    iex> SearchTables.create_cluster("my_cluster", "/var/data/cluster")
    {:ok, %SphinxqlResponse{}}

# `create_cluster`

# `create_distributed_table`

Create a distributed table that fans queries out to local shards and/or remote agents.

`parts` is a keyword list whose keys are `:local` or `:agent`:

    [local: "shard1", local: "shard2", agent: "host:port:remote"]

## Examples

    iex> SearchTables.create_distributed_table("dist_products",
    ...>   [local: "shard1", local: "shard2", agent: "10.0.0.2:9312:remote_shard"])
    {:ok, %SphinxqlResponse{}}

# `create_distributed_table`

# `create_table`

Create a real-time table with the given schema definition.

`schema` may be a raw SQL string or a list of `{name, type}` tuples.

## Examples

    iex> SearchTables.create_table("products", "title text, price uint")
    {:ok, %SphinxqlResponse{}}

    iex> SearchTables.create_table("products", [{"title", "text"}, {"price", "uint"}])
    {:ok, %SphinxqlResponse{}}

    iex> SearchTables.create_table("products", "title text", "morphology='stem_en'")
    {:ok, %SphinxqlResponse{}}

# `create_table`

# `create_table_if_not_exists`

Idempotent table creation — uses `IF NOT EXISTS`.

Accepts the same arguments as `create_table/2,3`.

## Examples

    iex> SearchTables.create_table_if_not_exists("products", "title text, price uint")
    {:ok, %SphinxqlResponse{}}

# `create_table_if_not_exists`

# `create_table_like`

Clone a table's schema.

## Examples

    iex> SearchTables.create_table_like("products_copy", "products")
    {:ok, %SphinxqlResponse{}}

# `delete`

Delete documents matching a condition.

## Examples

    iex> SearchTables.delete("products", "id = 1")
    {:ok, %SphinxqlResponse{}}

# `delete_cluster`

Delete a replication cluster. Tables survive as local non-replicated tables.

## Examples

    iex> SearchTables.delete_cluster("my_cluster")
    {:ok, %SphinxqlResponse{}}

# `describe_table`

Return the schema of a table.

## Examples

    iex> SearchTables.describe_table("products")
    {:ok, %SphinxqlResponse{fields: ["Field", "Type", "Properties"], matches: [...]}}

# `drop_table`

Drop a table. Pass `if_exists: true` to suppress errors when the table doesn't exist.

## Examples

    iex> SearchTables.drop_table("products")
    {:ok, %SphinxqlResponse{}}

    iex> SearchTables.drop_table("products", if_exists: true)
    {:ok, %SphinxqlResponse{}}

# `drop_table`

# `flush_table`

Force the RAM chunk to a new disk chunk. Important before planned shutdowns.

## Examples

    iex> SearchTables.flush_table("products")
    {:ok, %SphinxqlResponse{}}

# `insert`

Insert a row into a table.

`columns` is a list of column name strings. `values` is a list of corresponding
values — strings are automatically single-quoted, numbers are left bare.

## Examples

    iex> SearchTables.insert("products", ["id", "title", "price"], [1, "Laptop", 999])
    {:ok, %SphinxqlResponse{}}

# `join_cluster`

Join an existing replication cluster at the given host.

## Examples

    iex> SearchTables.join_cluster("my_cluster", "10.0.0.1:9312")
    {:ok, %SphinxqlResponse{}}

    iex> SearchTables.join_cluster("my_cluster", "10.0.0.1:9312", "/var/data/cluster")
    {:ok, %SphinxqlResponse{}}

# `join_cluster`

# `optimize_table`

Merge disk chunks. Run periodically to avoid read amplification.

## Examples

    iex> SearchTables.optimize_table("products")
    {:ok, %SphinxqlResponse{}}

# `replace`

Full upsert by document id — replaces the entire row if it exists.

## Examples

    iex> SearchTables.replace("products", ["id", "title", "price"], [1, "Updated Laptop", 899])
    {:ok, %SphinxqlResponse{}}

# `show_create_table`

Return the DDL statement that would recreate the table.

## Examples

    iex> SearchTables.show_create_table("products")
    {:ok, %SphinxqlResponse{}}

# `show_table_status`

Show table status — document count, disk size, chunk count, etc.
Useful for deciding when to run `optimize_table/1`.

## Examples

    iex> SearchTables.show_table_status("products")
    {:ok, %SphinxqlResponse{}}

# `truncate_table`

Wipe all data from a table while preserving its schema.

## Examples

    iex> SearchTables.truncate_table("products")
    {:ok, %SphinxqlResponse{}}

# `update`

Partial attribute update. Only attributes (not full-text fields) can be updated.

`attrs` is a keyword list or map of `{attribute, value}` pairs.

## Examples

    iex> SearchTables.update("products", [price: 799], "id = 1")
    {:ok, %SphinxqlResponse{}}

    iex> SearchTables.update("products", %{"price" => 799}, "id = 1")
    {:ok, %SphinxqlResponse{}}

---

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