Skip to content

Commit

Permalink
implement commit/2, commit!/2 functions for committing Solr docs to i…
Browse files Browse the repository at this point in the history
…ndex
  • Loading branch information
boonious committed Oct 9, 2018
1 parent 074773d commit 826f692
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 0 deletions.
8 changes: 8 additions & 0 deletions lib/hui.ex
Original file line number Diff line number Diff line change
Expand Up @@ -437,4 +437,12 @@ defmodule Hui do
@spec delete!(binary | Hui.URL.t, binary | list(binary), boolean) :: HTTPoison.Response.t
def delete!(url, ids, commit \\ true)
def delete!(url, ids, commit) when is_binary(ids) or is_list(ids), do: Request.update(url, true, %Hui.U{delete_id: ids, commit: commit})
@spec commit(binary | Hui.URL.t, boolean) :: {:ok, HTTPoison.Response.t} | {:error, Hui.Error.t}
def commit(url, wait_searcher \\ true)
def commit(url, wait_searcher), do: Request.update(url, %Hui.U{commit: true, waitSearcher: wait_searcher})

@spec commit!(binary | Hui.URL.t, boolean) :: HTTPoison.Response.t
def commit!(url, wait_searcher \\ true)
def commit!(url, wait_searcher), do: Request.update(url, %Hui.U{commit: true, waitSearcher: wait_searcher})

end
14 changes: 14 additions & 0 deletions test/update_test.exs
Original file line number Diff line number Diff line change
Expand Up @@ -116,6 +116,13 @@ defmodule HuiUpdateTest do
Hui.delete(url, ["tt1650453", "tt1650453"])
end

test "should commit docs", context do
url = %Hui.URL{url: "http://localhost:#{context.bypass.port}", handler: "update", headers: [{"Content-type", "application/json"}]}
expected_data = %Hui.U{commit: true, waitSearcher: true} |> Hui.U.encode
check_post_data_bypass_setup(context.bypass, expected_data)
Hui.commit(url)
end

test "should handle missing or malformed URL", context do
assert {:error, context.error_einval} == Hui.update(nil, context.update_doc)
assert {:error, context.error_einval} == Hui.update("", context.update_doc)
Expand Down Expand Up @@ -190,6 +197,13 @@ defmodule HuiUpdateTest do
Hui.delete!(url, ["tt1650453", "tt1650453"])
end

test "should commit docs", context do
url = %Hui.URL{url: "http://localhost:#{context.bypass.port}", handler: "update", headers: [{"Content-type", "application/json"}]}
expected_data = %Hui.U{commit: true, waitSearcher: true} |> Hui.U.encode
check_post_data_bypass_setup(context.bypass, expected_data)
Hui.commit!(url)
end

test "should handle missing or malformed URL", context do
assert_raise Hui.Error, ":einval", fn -> Hui.update!(nil, context.update_doc) end
assert_raise Hui.Error, ":einval", fn -> Hui.update!("", context.update_doc) end
Expand Down

0 comments on commit 826f692

Please sign in to comment.