Packages

A search deployment helper library. Aims to easy deployment and monitoring of distributed Manticore & Sphinx in a Linux environment

Current section

Files

Jump to
khafra_search lib sample sample.ex
Raw

lib/sample/sample.ex

defmodule Khafra.Sample do
@moduledoc """
Contains functions pertaining to testing functionality of Khafra. Aims to show
how one might integrate khafra smoothly with their app
"""
alias Giza.ManticoreQL
alias Khafra.Sample.TestSchema
@repo Application.compile_env(:khafra_search, :repo)
@doc "Add city"
def add_city(%{} = attrs, opts) do
%TestSchema{}
|> TestSchema.changeset(attrs)
|> @repo.insert()
|> Khafra.insert(opts)
end
@doc "Update city"
def update_city(city, %{} = attrs, opts) do
city
|> TestSchema.changeset(attrs)
|> @repo.update()
|> Khafra.update(opts)
end
@doc "Retrieve a city"
def get_city(id) do
@repo.get_by(TestSchema, id: id)
end
@doc "Find cities from search tables"
def find_cities(search_string) do
ManticoreQL.new()
|> ManticoreQL.from("test_dist")
|> ManticoreQL.match("*#{search_string}*")
|> Giza.send()
end
end