CQL schema definitions for the inverted index tables used by the search engine.
Provides functions to create and drop the required tables for the inverted index. The tables are:
search_post_termsâ inverted index mapping(term, shard, post_id)to the term's total frequency within the document (summed across fields)search_post_fieldsâ per-field term/frequency maps used to compute diff-based updates
Postings are stored at document level: one row per (term, post_id).
Queries fetch FĂ fewer rows than per-field layouts (F = number of fields),
which is the dominant cost when reading hot terms.
Usage
AshScylla.Search.Storage.create_tables(MyApp.Repo, "my_keyspace")
AshScylla.Search.Storage.drop_tables(MyApp.Repo, "my_keyspace")
Summary
Functions
Returns the CQL statement to create the search_post_fields table.
Returns the CQL statement to create the search_post_terms table.
Creates all search engine tables in the given keyspace.
Drops all search engine tables from the given keyspace.
Fetches every stored field map for a post from search_post_fields.
Computes the shard number for a given term.
Functions
Returns the CQL statement to create the search_post_fields table.
Stores the analyzed terms with their frequencies for each post field. Used during updates to diff old vs new content and recompute document-level totals.
Returns the CQL statement to create the search_post_terms table.
This is the primary inverted index table. Each row maps a term to a post_id with the term's total frequency in that document.
Partition key: (term, shard) to avoid hotspot partitions for common terms.
Clustering key: post_id.
Creates all search engine tables in the given keyspace.
Returns :ok on success or {:error, reason} on failure.
Drops all search engine tables from the given keyspace.
Returns :ok on success or {:error, reason} on failure.
@spec fetch_field_maps(module(), String.t(), String.t()) :: {:ok, %{required(String.t()) => %{required(String.t()) => pos_integer()}}} | {:error, term()}
Fetches every stored field map for a post from search_post_fields.
Returns %{"field_name" => %{"term" => tf}}. Empty map if the post has no
indexed fields.
@spec shard_for(String.t(), non_neg_integer()) :: non_neg_integer()
Computes the shard number for a given term.
Uses :erlang.phash2/2 to distribute terms across the configured number
of shards. This prevents hotspot partitions for high-frequency terms.