ProductPromotion
Logo

Elixir

made by https://0x3d.site

GitHub - Tyler-pierce/giza_sphinxsearch: Sphinx Fulltext Search Client for Elixir Projects (Phoenix Example Included)
Sphinx Fulltext Search Client for Elixir Projects (Phoenix Example Included) - Tyler-pierce/giza_sphinxsearch
Visit Site

GitHub - Tyler-pierce/giza_sphinxsearch: Sphinx Fulltext Search Client for Elixir Projects (Phoenix Example Included)

GitHub - Tyler-pierce/giza_sphinxsearch: Sphinx Fulltext Search Client for Elixir Projects (Phoenix Example Included)

Giza: Sphinx Search Client

Elixir Client implementation of the Sphinx Fulltext Search Engine. Sphinx is a (very) fast, light, robust and highly customizable search solution. It's support for concurrency and reputable uptime keeps up with OTP beautifully. Giza supports all connection and querying methods Sphinx offers.

Read the full docs for many usage examples.

NEW: 1.0.1 released. With cleaned up interface, documentation, concurrency model and easy configuration. To upgrade from 0.1.4 update your application file with the new simpler Giza.Application as shown below.

Installation

Add giza_sphinxsearch to your list of dependencies in mix.exs and add to your application list:

def deps do
  [{:giza_sphinxsearch, "~> 1.0"}]
end

And add Giza to your application tree:

# lib/your_app_name/application.ex for Phoenix and most OTP applications
children = [
  ...,
  supervisor(Giza.Application, [])
]

Usage Options

Giza wants to know where your sphinx host is and what ports to use. It uses sensible defaults based on most setups. The 3 connection type ports (native sphinx/http/sphinxQL) can be overriden optionally as shown below as well as the host in case you run Sphinx on a separate cluster/machine in production for example.

# SQL Port recommened so you can query with SphinxQL
config :giza_sphinxsearch,
  host: 'localhost',
  sql_port: 9306,
  port: 9312,
  http_port: 9308

Querying Sphinx!

SphinxQL (Recommended)

SphinxQL uses an SQL client to send requests to the Sphinx Daemon. Giza exposes all Sphinx functionality through this method and is recommended for client speed as well. Thus this is the officially supported querying for this library.

# Must have Sphinx beta 2.3.2 (or 3+ when released) to use suggest
alias Giza.SphinxQL

SphinxQL.new() 
  |> SphinxQL.suggest("posts_index", "splt")
  |> SphinxQL.send()

%SphinxqlResponse{fields: ["suggest", "distance", "docs"], matches: [["split", 1, 5]...]}
SphinxQL.new()
|> SphinxQL.from("posts")
|> SphinxQL.match("tengri")
|> SphinxQL.send()
|> Giza.get_doc_ids()

[1, 4, 6, 12, ..]

{:ok, %{:total_found => last_query_total_found} = Giza.SphinxQL.meta()

800
SphinxQL.new()
|> SphinxQL.raw("SELECT id, WEIGHT() as w FROM posts_index WHERE MATCH('subetei the swift')")
|> SphinxQL.send()

%SphinxqlResponse{ .. }

Recipes!

The recipe library allows you to make use of complex sphinx queries pre-prepared by Giza. The first such recipe made available is the ability to weigh your queries toward newer entries:

SphinxQL.new()
|> SphinxQL.from("posts")
|> SphinxQL.match("tengri")
|> SphinxQL.Recipe.weigh_by_date("last_updated_timestamp")
|> SphinxQL.send()

%SphinxqlResponse{ .. }

Here is one that helps you filter on your source attributes:

SphinxQL.new()
|> SphinxQL.from("blog_comments")
|> SphinxQL.Recipe.match_and_filter("subetei", post_id: 1, depth: 2)
|> SphinxQL.send()

%SphinxqlResponse{ .. }

There are more examples here in the documentation.

Mix Helpers

There are several mix tasks packaged with Giza to help you get up and running with Sphinx immediately. These are especially great if you are new to Sphinx and want a headstart learning configuration.

Creates a sphinx config file with sensible defaults and info to connect to your database:

mix giza.sphinx.config your_app YourApp.Repo

You can now open the generated file and update the SQL queries to whatever you want to index in your database.

Runs the batch indexer using the Sphinx conf in sphinx/sphinx.conf:

mix giza.sphinx.index

Starts the search daemon.. after this you are running Sphinx or Manticore with your index and can query!

mix giza.sphinx.searchd

Run a query over the sql protocol

mix giza.sphinx.query "SELECT * FROM i_blog WHERE MATCH('miranda')"

Native protocol

The native protocol can be easy to use as well with Giza's helpers and provides your query meta all at once. For most needs this works well; for some features like Search Suggestions (such as for autocomplete), you should use SphinxQL. Credit goes to the original Giza author for the Erlang client, as we still route these requests through that code. We wrap the returned value in a more convenient Map.

Examples:

alias Giza.SphinxProtocol

SphinxProtocol.query("blog_index", "subetei the swift")
|> SphinxProtocol.limit(5)
|> SphinxProtocol.offset(5)
|> SphinxProtocol.filter_exclude('user_age', 1, 17)
|> SphinxProtocol.send()

{: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: 5, 
    total_found: 19, 
    warnings: [],
    words: [{"subetei the swift", 5, 8}]
  }
}

https://hexdocs.pm/giza_sphinxsearch/1.0.0/Giza.SphinxProtocol.html#functions

Sphinx HTTP REST API (experimental)

This is simply there to support the infrastructure but not recommended for production use yet. If you have sphinx 2.3.2+ installed feel free to try this out if you prefer to use HTTP for any reason. Please log any issues so this can be supported fully!

https://hexdocs.pm/giza_sphinxsearch/Giza.Http.html#functions

Documentation

https://hexdocs.pm/giza_sphinxsearch/Giza.html#content

And to learn more about Sphinx from there excellent documentation:

http://sphinxsearch.com/docs/current.html

And to learn more about the recent Sphinx fork Manticore:

https://docs.manticoresearch.com/latest/html/

Upcoming Development

  • Do something about error messages from Maria client (they aren't currently easy to handle/read in Giza)

  • Create the ability to download and run the sphinx binary locally so the project can be setup immediately via mix

Articles
to learn more about the elixir concepts.

Resources
which are currently available to browse on.

mail [email protected] to add your project or resources here 🔥.

FAQ's
to know more about the topic.

mail [email protected] to add your project or resources here 🔥.

Queries
or most google FAQ's about Elixir.

mail [email protected] to add more queries here 🔍.

More Sites
to check out once you're finished browsing here.

0x3d
https://www.0x3d.site/
0x3d is designed for aggregating information.
NodeJS
https://nodejs.0x3d.site/
NodeJS Online Directory
Cross Platform
https://cross-platform.0x3d.site/
Cross Platform Online Directory
Open Source
https://open-source.0x3d.site/
Open Source Online Directory
Analytics
https://analytics.0x3d.site/
Analytics Online Directory
JavaScript
https://javascript.0x3d.site/
JavaScript Online Directory
GoLang
https://golang.0x3d.site/
GoLang Online Directory
Python
https://python.0x3d.site/
Python Online Directory
Swift
https://swift.0x3d.site/
Swift Online Directory
Rust
https://rust.0x3d.site/
Rust Online Directory
Scala
https://scala.0x3d.site/
Scala Online Directory
Ruby
https://ruby.0x3d.site/
Ruby Online Directory
Clojure
https://clojure.0x3d.site/
Clojure Online Directory
Elixir
https://elixir.0x3d.site/
Elixir Online Directory
Elm
https://elm.0x3d.site/
Elm Online Directory
Lua
https://lua.0x3d.site/
Lua Online Directory
C Programming
https://c-programming.0x3d.site/
C Programming Online Directory
C++ Programming
https://cpp-programming.0x3d.site/
C++ Programming Online Directory
R Programming
https://r-programming.0x3d.site/
R Programming Online Directory
Perl
https://perl.0x3d.site/
Perl Online Directory
Java
https://java.0x3d.site/
Java Online Directory
Kotlin
https://kotlin.0x3d.site/
Kotlin Online Directory
PHP
https://php.0x3d.site/
PHP Online Directory
React JS
https://react.0x3d.site/
React JS Online Directory
Angular
https://angular.0x3d.site/
Angular JS Online Directory