Giza.ManticoreQL (giza_sphinxsearch v2.0.0)

Copy Markdown

Query building helper functions for ManticoreQL. Manticore Search is a fork of Sphinx Search with active development and new features. This module delegates the standard query-composing interface to ManticoreQL and is the place to add Manticore-specific extensions.

Summary

Functions

Word-level autocomplete via CALL SUGGEST. Returns candidate completions for the given partial word against the specified index dictionary.

Appends a FACET clause to the query. Multiple calls chain additional facets. Manticore reuses the base result set for each facet, so the total cost is only marginally more than the plain query.

Adds HIGHLIGHT() to the SELECT list so Manticore annotates matching keywords in stored fields. Requires the table to have stored_fields configured.

Sets a KNN (k-nearest-neighbour) vector search clause in WHERE. Requires the table to have a float_vector attribute with an HNSW index.

Executes a percolate (reverse search) query — matches stored queries in a percolate table against one or more incoming documents.

Functions

autocomplete(word, index)

Word-level autocomplete via CALL SUGGEST. Returns candidate completions for the given partial word against the specified index dictionary.

Options:

  • :limit - max suggestions (default: 5)
  • :max_edits - Levenshtein distance tolerance (default: 4)

Examples

iex> ManticoreQL.autocomplete("elxi", "posts_index")
{:ok, %SphinxqlResponse{}}

iex> ManticoreQL.autocomplete("elxi", "posts_index", limit: 3, max_edits: 2)
{:ok, %SphinxqlResponse{}}

autocomplete(word, index, opts)

call(query, call)

See Giza.SphinxQL.call/2.

facet(query, expr)

Appends a FACET clause to the query. Multiple calls chain additional facets. Manticore reuses the base result set for each facet, so the total cost is only marginally more than the plain query.

Options:

  • :order - ORDER BY expression string, e.g. "COUNT(*) DESC"
  • :limit - integer cap on facet rows returned

Examples

iex> ManticoreQL.new()
|> ManticoreQL.from("products")
|> ManticoreQL.match("phone")
|> ManticoreQL.facet("brand_id")
|> ManticoreQL.facet("price", order: "COUNT(*) DESC", limit: 10)
|> ManticoreQL.send()

facet(query, expr, opts)

from(query, index)

See Giza.SphinxQL.from/2.

highlight(query)

Adds HIGHLIGHT() to the SELECT list so Manticore annotates matching keywords in stored fields. Requires the table to have stored_fields configured.

Options are passed as keyword pairs and become key='value' inside HIGHLIGHT({...}). Common options: before_match, after_match, around, limit, limit_passages.

Examples

iex> ManticoreQL.new()
|> ManticoreQL.from("articles")
|> ManticoreQL.match("elixir")
|> ManticoreQL.highlight()
|> ManticoreQL.send()

iex> ManticoreQL.new()
|> ManticoreQL.from("articles")
|> ManticoreQL.match("elixir")
|> ManticoreQL.highlight(before_match: "<em>", after_match: "</em>", limit: 200)
|> ManticoreQL.send()

highlight(query, opts)

knn(query, field, k, vector)

Sets a KNN (k-nearest-neighbour) vector search clause in WHERE. Requires the table to have a float_vector attribute with an HNSW index.

Typically combine with select/2 to also retrieve knn_dist() in results.

Examples

iex> ManticoreQL.new()
|> ManticoreQL.select(["id", "title", "knn_dist()"])
|> ManticoreQL.from("articles")
|> ManticoreQL.knn("embedding", 5, [0.1, 0.2, 0.3, 0.4])
|> Giza.send()

limit(query, limit)

See Giza.SphinxQL.limit/2.

match(query, search_term)

See Giza.SphinxQL.match/2.

meta()

See Giza.SphinxQL.meta/0.

new()

See Giza.SphinxQL.new/0.

offset(query, offset)

See Giza.SphinxQL.offset/2.

option(query, option)

See Giza.SphinxQL.option/2.

order_by(query, order_by)

See Giza.SphinxQL.order_by/2.

percolate(table, doc)

Executes a percolate (reverse search) query — matches stored queries in a percolate table against one or more incoming documents.

doc is a JSON string. docs is a list of JSON strings that will be wrapped in a JSON array.

Examples

iex> ManticoreQL.percolate("pq_alerts", ~s({"title": "breaking news"}))
{:ok, %SphinxqlResponse{}}

iex> ManticoreQL.percolate("pq_alerts", [~s({"title": "foo"}), ~s({"title": "bar"})])
{:ok, %SphinxqlResponse{}}

raw(query, raw_query_string)

See Giza.SphinxQL.raw/2.

select(query, fields)

See Giza.SphinxQL.select/2.

suggest(query, index, phrase)

See Giza.SphinxQL.suggest/3.

suggest(query, index, phrase, opts)

See Giza.SphinxQL.suggest/4.

where(query, where)

See Giza.SphinxQL.where/2.