-
Notifications
You must be signed in to change notification settings - Fork 26
/
search.ex
61 lines (52 loc) · 1.61 KB
/
search.ex
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
defmodule Meilisearch.Search do
@moduledoc """
Collection of functions used to search for documents matching given query.
[MeiliSearch Documentation - Search](https://docs.meilisearch.com/references/search.html)
"""
alias Meilisearch.HTTP
@doc """
Search for documents matching a specific query in the given index.
A `search_query` value of `nil` will send a placeholder query.
## Options
* `offset` Number of documents to skip. Defaults to `0`
* `limit` Maximum number of documents returned. Defaults to `20`
## Examples
iex> Meilisearch.Search.search("meilisearch_test", "where art thou")
{:ok,
%{
"exhaustiveNbHits" => false,
"hits" => [
%{
"id" => 2,
"tagline" => "They have a plan but not a clue",
"title" => "O' Brother Where Art Thou"
}
],
"limit" => 20,
"nbHits" => 1,
"offset" => 0,
"processingTimeMs" => 17,
"query" => "where art thou"
}}
iex> Meilisearch.Search.search("meilisearch_test", "nothing will match")
{:ok,
%{
"exhaustiveNbHits" => false,
"hits" => [],
"limit" => 20,
"nbHits" => 0,
"offset" => 0,
"processingTimeMs" => 27,
"query" => "nothing will match"
}}
"""
@spec search(String.t(), String.t() | nil, Keyword.t()) :: HTTP.response()
def search(uid, search_query, opts \\ []) do
params =
case search_query do
nil -> opts
q -> [{:q, q} | opts]
end
HTTP.get_request("indexes/#{uid}/search", [], params: params)
end
end