Skip to content

Commit d9eba69

Browse files
authored
Use POST for search and browse (#10)
1 parent 81e834b commit d9eba69

File tree

2 files changed

+15
-11
lines changed

2 files changed

+15
-11
lines changed

lib/algolia.ex

Lines changed: 13 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -120,12 +120,16 @@ defmodule Algolia do
120120
def search(client, index, query, opts \\ []) do
121121
{req_opts, opts} = pop_request_opts(opts)
122122

123-
path = Paths.search(index, query, opts)
123+
body =
124+
opts
125+
|> Map.new()
126+
|> Map.put(:query, query)
124127

125128
with {:ok, %{} = data} <-
126129
send_request(client, :read, %{
127-
method: :get,
128-
path: path,
130+
method: :post,
131+
path: Paths.search(index),
132+
body: body,
129133
options: req_opts
130134
}) do
131135
:telemetry.execute(
@@ -207,10 +211,13 @@ defmodule Algolia do
207211
def browse(client, index, opts \\ []) do
208212
{req_opts, opts} = pop_request_opts(opts)
209213

210-
path = Paths.browse(index, opts)
211-
212214
with {:ok, %{} = data} <-
213-
send_request(client, :read, %{method: :get, path: path, options: req_opts}) do
215+
send_request(client, :read, %{
216+
method: :post,
217+
path: Paths.browse(index),
218+
body: Map.new(opts),
219+
options: req_opts
220+
}) do
214221
:telemetry.execute(
215222
[:algolia, :browse, :result],
216223
%{hits: data["nbHits"], processing_time: data["processingTimeMS"]},

lib/algolia/paths.ex

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -28,16 +28,13 @@ defmodule Algolia.Paths do
2828
object(index, object_id) <> "/partial" <> to_query(params)
2929
end
3030

31-
def search(index, query, opts) do
32-
params = Keyword.put(opts, :query, query)
33-
index(index) <> to_query(params)
34-
end
31+
def search(index), do: index(index) <> "/query"
3532

3633
def search_facet(index, facet) do
3734
index(index) <> "/facets/" <> URI.encode(facet) <> "/query"
3835
end
3936

40-
def browse(index, opts), do: index(index) <> "/browse" <> to_query(opts)
37+
def browse(index), do: index(index) <> "/browse"
4138

4239
def clear(index), do: index(index) <> "/clear"
4340

0 commit comments

Comments
 (0)