Skip to content

fredwu/meilisearch-ex

 
 

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

51 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

An unofficial Meilisearch client based on Finch HTTP client wrapped by Tesla.

GitHub Workflow Status GitHub Hex.pm Hex.pm Hexdocs.pm Coveralls

Installation

The package can be installed by adding meilisearch_ex to your list of dependencies in mix.exs:

def deps do
  [
    {:finch, "~> 0.14.0"},
    {:meilisearch_ex, "~> 1.0.1"}
  ]
end

Documentation can be found at https://hexdocs.pm/meilisearch_ex.

Usage

You can create a client when you needs it.

# Start finch with your app
Finch.start_link(name: :search_finch)

# Create a Meilisearch client whenever and wherever you need it.
[endpoint: "https://search.mydomain.com", key: "replace_me", finch: :search_finch]
|> Meilisearch.Client.new()
|> Meilisearch.Health.get()

# %Meilisearch.Health{status: "available"}

But you can also start a client alongside your application to access it whenever you need it.

Finch.start_link(name: :search_finch)
Meilisearch.start_link(:main, [
  endpoint: "https://search.mydomain.com",
  key: "replace_me",
  finch: :search_finch
])

:main
|> Meilisearch.client()
|> Meilisearch.Health.get()

# %Meilisearch.Health{status: "available"}

Within a Phoenix app you would do like this:

defmodule MyApp.Application do
  # ...

  @impl true
  def start(_type, _args) do
    children = [
      # ...
      {Finch, name: :search_finch},
      {Meilisearch, name: :search_admin, endpoint: "https://search.mydomain.com", key: "key_admin", finch: :search_finch},
      {Meilisearch, name: :search_public, endpoint: "https://search.mydomain.com", key: "key_public", finch: :search_finch}
    ]

    # ...
  end

  # ...
end

defmodule MyApp.MyContext do
  def create_search_index() do
    :search_admin
    |> Meilisearch.client()
    |> Meilisearch.Index.create(%{uid: "items", primaryKey: "id"})
  end

  def add_documents_to_search_index(documents) do
    :search_admin
    |> Meilisearch.client()
    |> Meilisearch.Document.create_or_replace("items", documents)
  end

  def search_document(query) do
    :search_public
    |> Meilisearch.client()
    |> Meilisearch.Search.search("items", %{q: query})
  end
end

Compatibility

For now, we only support version 1.0.x of Meilisearch.

meilisearch meilisearch-ex
1.0.x 1.0

About

A Meilisearch client for Elixir.

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages

  • Elixir 100.0%