giza_sphinxsearch v1.0.0 Giza.SphinxQL

Query building helper functions for SphinxQL requests (http://sphinxsearch.com/docs/devel.html#sphinxql-reference). This is the recommended way to query Sphinx (for client speed particularly) and will be the most supported style in Giza going forward. SphinxQL is very close to standard SQL with a few non-supported terms that wouldn’t make sence in the search world and a few extras that only make sense in Sphinx’s world. 100% of Sphinx’ functionality is accessable through this method.

Link to this section Summary

Functions

Return a SphinxQL query augmented with a CALL statement. A string is acceptable input

Returns a SphinxQL query augmented with an index to select from

Returns an api query augmented with a limit for amount of returned documents. Note that Sphinx also allows for setting an internal limit in configuration. Only an integer is acceptable input

Returns a SphinxQL query augmented with a where clause which will be formated as a MATCH query, a common way of asking Sphinx for search matches on a word or phrase (word bag)

Return meta information about the latest query on the current client. This is commonly used to retrieve the total returned in that query and the total available without limit. This information can be used for pagination

Return a http api query structure with default values

Returns an api query augmented with a limit for amount of returned documents. Only an integer is acceptable input. This is normally used to support pagination

Return a SphinxQL query with it’s raw field set allowing to run a custom client created query. Raw overrides other options such as select, where, etc. If you can’t find functionality needed from the query helpers in this module, this is the best way to unlock the full feature set of sphinx

Return a SphinxQL query augmented with a select statement. Either a string (binary) or list of fields is acceptable input

Send a query to be executed after preprocessing of the SphinxqlQuery structure. Returns a tuple with :ok or :error and the error message if applicable

Shortcut helper function to form a suggestion query. Options can be passed to change the default limit and max edits (amount of levenstein distance acceptable, so 4 would mean 4 characters can be wrong)

Returns a SphinxQL query with a where clause added. A string representing the whole where part of your query is the only accepted input

Link to this section Functions

Link to this function call(query, call)

Return a SphinxQL query augmented with a CALL statement. A string is acceptable input.

Examples

iex> Giza.SphinxQL.new() |> Giza.SphinxQL.call("QSUGGEST('subtei', 'posts_index')") |> Giza.SphinxQL.send()
Link to this function from(query, index)

Returns a SphinxQL query augmented with an index to select from.

Examples

iex> Giza.SphinxQL.new() |> Giza.SphinxQL.from("posts")
Link to this function limit(query, limit)

Returns an api query augmented with a limit for amount of returned documents. Note that Sphinx also allows for setting an internal limit in configuration. Only an integer is acceptable input.

Examples

iex> Giza.SphinxQL.new() |> Giza.SphinxQL.limit(1)
Link to this function match(query, search_phrase)

Returns a SphinxQL query augmented with a where clause which will be formated as a MATCH query, a common way of asking Sphinx for search matches on a word or phrase (word bag)

Examples

iex> Giza.SphinxQL.new() |> Giza.SphinxQL.match("Subetei the Swift")

Return meta information about the latest query on the current client. This is commonly used to retrieve the total returned in that query and the total available without limit. This information can be used for pagination

http://sphinxsearch.com/docs/devel.html#sphinxql-show-meta

Examples

iex> Giza.SphinxQL.meta()

    {:ok, %SphinxqlMeta{"total": 20, "total_found": 1000, "time": 0.0006, ...}

Return a http api query structure with default values

Examples

iex> Giza.SphinxQL.new() |> ...
Link to this function offset(query, offset)

Returns an api query augmented with a limit for amount of returned documents. Only an integer is acceptable input. This is normally used to support pagination.

Examples

iex> Giza.SphinxQL.new() |> Giza.SphinxQL.offset(10)
Link to this function raw(query, raw_query_string)

Return a SphinxQL query with it’s raw field set allowing to run a custom client created query. Raw overrides other options such as select, where, etc. If you can’t find functionality needed from the query helpers in this module, this is the best way to unlock the full feature set of sphinx.

Examples

iex> Giza.SphinxQL.new() |> Giza.SphinxQL.raw("SELECT id, WEIGHT() as w FROM posts_index WHERE MATCH('subetei the swift')")
Link to this function select(query, fields)

Return a SphinxQL query augmented with a select statement. Either a string (binary) or list of fields is acceptable input.

Examples

iex> Giza.SphinxQL.new() |> Giza.SphinxQL.select(["id", "WEIGHT() as w"])

Send a query to be executed after preprocessing of the SphinxqlQuery structure. Returns a tuple with :ok or :error and the error message if applicable.

Examples

iex> Giza.SphinxQL.new() |> Giza.SphinxQL.raw("SELECT id FROM test_index WHERE MATCH('great kahn')") |> Giza.SphinxQL.send()
Link to this function suggest(query, index, phrase, opts)

Shortcut helper function to form a suggestion query. Options can be passed to change the default limit and max edits (amount of levenstein distance acceptable, so 4 would mean 4 characters can be wrong)

Examples

iex> Giza.SphinxQL.new() |> Giza.SphinxQL.suggest('sbetei', 'posts_index', [limit: 3, max_edits: 4])
Link to this function where(query, where)

Returns a SphinxQL query with a where clause added. A string representing the whole where part of your query is the only accepted input.

Examples

iex> Giza.SphinxQL.new() |> Giza.SphinxQL.where("MATCH('tengri') AND room = 'mongol lounge'")