bombadil v0.1.2 Bombadil
Bombadil is a wrapper around some PostgreSQL search capabilities.
It supports:
- exact match through PostgreSQL tsvector(s)
- fuzzy search inside jsonb field
- indexing in the jsonb field
Link to this section Summary
Functions
Fuzzy search data of a string (or substring)
Index a document payload as map
Search data with exact match of a string (or substring)
Link to this section Functions
Link to this function
fuzzy_search(schema, query, opts \\ [])
fuzzy_search(Ecto.Schema.t(), String.t() | list(), Keyword.t()) :: list()
Fuzzy search data of a string (or substring)
Assuming that you have indexed %{"book" => "Lord of the Rings}
Example:
alias Bombadil.Ecto.Schema.SearchIndex
iex> Bombadil.fuzzy_search(SearchIndex, "lord of the ringz")
[
%Bombadil.Ecto.Schema.SearchIndex{
__meta__: #Ecto.Schema.Metadata<:loaded, "search_index">,
payload: %{"book" => "Lord of the Rings"},
id: 1
}
]
Link to this function
index(schema, payload, params \\ [])
index(Ecto.Schema.t(), map(), list()) :: :ok | {:error, String.t()}
Index a document payload as map
Example:
alias Bombadil.Ecto.Schema.SearchIndex
Bombadil.index(SearchIndex, payload: %{"book" => "Lord of the Rings"})
Search data with exact match of a string (or substring)
Assuming that you have indexed %{"book" => "Lord of the Rings}
Example:
alias Bombadil.Ecto.Schema.SearchIndex
iex> Bombadil.search("Lord of the Rings")
[
%Bombadil.Ecto.Schema.SearchIndex{
__meta__: #Ecto.Schema.Metadata<:loaded, "search_index">,
payload: %{"book" => "Lord of the Rings"},
id: 1
}
]