Giza (giza_sphinxsearch v1.0.7)
Client for Sphinx Search, the search product built by the legendary Andrew Aksyonoff. Sphinx is a robust and FAST database indexer and search daemon that can process large amounts of concurrent through-put. Giza aims to make implementing Sphinx in your Elixir apps quick and simple. Check out the examples below for most use cases and dive deeper if need be through the docs. The github docs take an Elixir perspective approach. This doc here will get you up and running with Sphinx and Elixir.
Example
Let's integrate into a Phoenix App.
Add Giza to dependencies (in mix.exs)
def deps do [{:giza_sphinxsearch, "~> 1.0.1"},
...]
end
Add Giza to your OTP tree in your application file at lib/yourapp/application.ex
children = [ ..., supervisor(Giza.Application, []) ]
Install sphinx or manticore.
Option: Install from here https://manticoresearch.com/downloads/ Option: Install from here http://sphinxsearch.com/downloads/current/
Generate a config file. From your apps directory:
# Config file will appear in sphinx/sphinx.conf
mix giza.sphinx.config
Run the index and start the search daemon
mix giza.sphinx.index (Output shown: check for any issues in your indices!) mix.giza.sphinx.searchd
Now you can use the examples below and throughout the documentation in your code!
Example
alias Giza.SphinxQL
SphinxQL.new()
|> SphinxQL.suggest("posts_index", "splt")
|> SphinxQL.send()
%SphinxqlResponse{fields: ["suggest", "distance", "docs"], matches: [["split", 1, 5]...]}
Example
SphinxQL.new()
|> SphinxQL.from("posts, posts_recent")
|> SphinxQL.match("tengri")
|> SphinxQL.send()
|> Giza.get_doc_ids()
[1, 4, 6, 12, ..]
{:ok, %{:total_found => last_query_total_found} = Giza.SphinxQL.meta()
800
Example
SphinxQL.new()
|> SphinxQL.raw("SELECT id, WEIGHT() as w FROM posts_index WHERE MATCH('subetei the swift')")
|> SphinxQL.send()
%SphinxqlResponse{ .. }
Link to this section Summary
Functions
Takes a giza result from a search and returns a list of the document id's
Take a sphinx protocol giza result from the erlang tcp implementation's tuple and return it as a map easier to navigate in Elixir.
Link to this section Functions
get_doc_ids(error)
Takes a giza result from a search and returns a list of the document id's
Examples
iex> Giza.get_doc_ids(giza_result)
{:ok, [1, 5, 6, 7], 4}
result_tuple_to_map(result)
Take a sphinx protocol giza result from the erlang tcp implementation's tuple and return it as a map easier to navigate in Elixir.
Examples
iex> Giza.result_tuple_to_map({:giza_query_result, ...})
{:ok,
%{attrs: [{"title", 7}, {"body", 7}],
fields: ["title", "body", "tags"],
matches: [{171,
[doc_id: 171, weight: 2,
attrs: [{"title", 7}, {"body", 7}]]}],
{190,
..
}],
status: 0,
time: 0.008,
total: 19,
total_found: 19,
warnings: [],
words: [{"test", 19, 23}]
}
}