View Source ExTypesense.Document (ExTypesense v0.2.2)

Module for CRUD operations for documents. Refer to this doc guide.

Link to this section Summary

Functions

Search from a document. Returns an Ecto query.

Get a document from a collection by its document id.

Indexes multiple documents.

Link to this section Types

@type response() :: {:ok, map()} | {:error, map()}

Link to this section Functions

Link to this function

ecto_search(module_name, search_term, search_field, query_by)

View Source (since 0.1.0)
@spec ecto_search(module(), String.t(), String.t(), String.t()) :: Ecto.Query.t()

Search from a document. Returns an Ecto query.

examples

Examples

iex> Document.search(Something, "umbrella", "title,description")
#Ecto.Query<...>
Link to this function

get_document(document_id)

View Source (since 0.1.0)
@spec get_document(String.t()) :: response()

Get a document from a collection by its document id.

Link to this function

index_multiple_documents(list_of_structs)

View Source (since 0.1.0)
@spec index_multiple_documents([struct()]) :: [map()]

Indexes multiple documents.

examples

Examples

iex> posts = Posts |> Repo.all()

iex> Document.index_multiple_documents(posts)
[
  %{"success" => true},
  %{"success" => true},
  ...
]
Link to this function

search(collection_name, search_term, query_by)

View Source (since 0.1.0)
@spec search(module() | String.t(), String.t(), String.t()) :: response()

Search from a document.

examples

Examples

iex> Document.search(Something, "umbrella", "title,description")
{:ok,
 %{
  "facet_counts" => [],
  "found" => 20,
  "hits" => [...],
  "out_of" => 111,
  "page" => 1,
  "request_params" => %{
    "collection_name" => "something",
    "per_page" => 10,
    "q" => "umbrella"
  },
  "search_cutoff" => false,
  "search_time_ms" => 5
 }
}