-
Notifications
You must be signed in to change notification settings - Fork 93
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #198 from Zatvobor/resources
`Tirexs.Resources` module
- Loading branch information
Showing
9 changed files
with
338 additions
and
19 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,63 @@ | ||
defmodule Tirexs.Resources.Search do | ||
@moduledoc false | ||
|
||
import Tirexs.Resources, only: [urn: 1, __c: 2] | ||
|
||
|
||
@doc false | ||
@r [action: "/_explain", bump: :post, bump!: :post!] | ||
def _explain(a, b, c, d), do: __c(urn([a, b, c, @r[:action], d]), @r) | ||
def _explain(a, b, c), do: __c(urn([a, b, c, @r[:action]]), @r) | ||
def _explain(a, b), do: __c(urn([a, @r[:action], b]), @r) | ||
def _explain(a), do: __c(urn([a, @r[:action]]), @r) | ||
|
||
@doc false | ||
@r [action: "/_search_shards", bump: :get, bump!: :get!] | ||
def _search_shards(a, b, c), do: __c(urn([a, b, @r[:action], c]), @r) | ||
def _search_shards(a, {b}), do: __c(urn([a, @r[:action], {b}]), @r) | ||
def _search_shards(a, b), do: __c(urn([a, b, @r[:action]]), @r) | ||
def _search_shards(a), do: __c(urn([a, @r[:action]]), @r) | ||
|
||
@doc false | ||
@r [action: "/_field_stats", bump: :post, bump!: :post!] | ||
def _field_stats(a, b), do: __c(urn([a, @r[:action], b]), @r) | ||
def _field_stats({a}), do: __c(urn([@r[:action], {a}]), @r) | ||
def _field_stats(a), do: __c(urn([a, @r[:action]]), @r) | ||
def _field_stats(), do: __c(urn([@r[:action]]), @r) | ||
|
||
@doc false | ||
@r [action: "/_validate/query", bump: :post, bump!: :post!] | ||
def _validate_query(a, b, c), do: __c(urn([a, b, @r[:action], c]), @r) | ||
def _validate_query(a, {b}), do: __c(urn([a, @r[:action], {b}]), @r) | ||
def _validate_query(a, b), do: __c(urn([a, b, @r[:action]]), @r) | ||
def _validate_query({a}), do: __c(urn([@r[:action], {a}]), @r) | ||
def _validate_query(a), do: __c(urn([a, @r[:action]]), @r) | ||
def _validate_query(), do: __c(urn([@r[:action]]), @r) | ||
|
||
@doc false | ||
@r [action: "/_count", bump: :post, bump!: :post!] | ||
def _count(a, b, c), do: __c(urn([a, b, @r[:action], c]), @r) | ||
def _count(a, {b}), do: __c(urn([a, @r[:action], {b}]), @r) | ||
def _count(a, b), do: __c(urn([a, b, @r[:action]]), @r) | ||
def _count({a}), do: __c(urn([@r[:action], {a}]), @r) | ||
def _count(a), do: __c(urn([a, @r[:action]]), @r) | ||
def _count(), do: __c(urn([@r[:action]]), @r) | ||
|
||
@doc false | ||
@r [action: "/_search/exists", bump: :post, bump!: :post!] | ||
def _search_exists(a, b, c), do: __c(urn([a, b, @r[:action], c]), @r) | ||
def _search_exists(a, {b}), do: __c(urn([a, @r[:action], {b}]), @r) | ||
def _search_exists(a, b), do: __c(urn([a, b, @r[:action]]), @r) | ||
def _search_exists({a}), do: __c(urn([@r[:action], {a}]), @r) | ||
def _search_exists(a), do: __c(urn([a, @r[:action]]), @r) | ||
def _search_exists(), do: __c(urn([@r[:action]]), @r) | ||
|
||
@doc false | ||
@r [action: "/_search", bump: :post, bump!: :post!] | ||
def _search(a, b, c), do: __c(urn([a, b, @r[:action], c]), @r) | ||
def _search(a, {b}), do: __c(urn([a, @r[:action], {b}]), @r) | ||
def _search(a, b), do: __c(urn([a, b, @r[:action]]), @r) | ||
def _search({a}), do: __c(urn([@r[:action], {a}]), @r) | ||
def _search(a), do: __c(urn([a, @r[:action]]), @r) | ||
def _search(), do: __c(urn([@r[:action]]), @r) | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,86 @@ | ||
defmodule Acceptances.Resources.SearchTest do | ||
use ExUnit.Case | ||
|
||
alias Tirexs.{HTTP, Resources} | ||
|
||
|
||
setup do | ||
HTTP.delete("bear_test") && :ok | ||
end | ||
|
||
|
||
test "_explain/4" do | ||
{ :ok, 201, _ } = HTTP.put("/bear_test/my_type/1?refresh=true", [user: "kimchy"]) | ||
{ :ok, 200, r } = Resources.bump._explain("bear_test", "my_type", "1", { [q: "user:k*"] }) | ||
assert r[:matched] | ||
end | ||
|
||
test "_explain/3" do | ||
{ :ok, 201, _ } = HTTP.put("/bear_test/my_type/1?refresh=true", [user: "kimchy"]) | ||
search = [query: [ term: [ user: "kimchy" ] ]] | ||
{ :ok, 200, r } = Resources.bump(search)._explain("bear_test", "my_type", "1") | ||
assert r[:matched] | ||
end | ||
|
||
test "_explain/2" do | ||
{ :ok, 201, _ } = HTTP.put("/bear_test/my_type/2?refresh=true", [user: "zatvobor"]) | ||
{ :ok, 200, r } = Resources.bump._explain("bear_test/my_type/2", { [q: "user:z*"] }) | ||
assert r[:matched] | ||
end | ||
|
||
test "_explain/1" do | ||
{ :ok, 201, _ } = HTTP.put("/bear_test/my_type/2?refresh=true", [user: "zatvobor"]) | ||
search = [query: [ term: [ user: "zatvobor" ] ]] | ||
{ :ok, 200, r } = Resources.bump(search)._explain("bear_test/my_type/2") | ||
assert r[:matched] | ||
end | ||
|
||
test "_search_shards/2" do | ||
{ :ok, 200, _ } = HTTP.put("/bear_test") | ||
{ :ok, 200, _ } = Resources.bump._search_shards("bear_test", { [local: true] }) | ||
end | ||
|
||
test "_field_stats/0" do | ||
{ :ok, 200, _ } = HTTP.put("/bear_test") | ||
{ :ok, 200, _ } = Resources.bump([fields: ["rating"]])._field_stats() | ||
end | ||
|
||
test "_field_stats/2" do | ||
{ :ok, 200, _ } = HTTP.put("/bear_test") | ||
{ :ok, 200, _ } = Resources.bump._field_stats("bear_test", { [fields: "some"] }) | ||
end | ||
|
||
test "_validate_query/2" do | ||
{ :ok, 201, _ } = HTTP.put("/bear_test/my_type/1?refresh=true", [user: "kimchy"]) | ||
{ :ok, 200, r } = Resources.bump._validate_query("bear_test", { [q: "user1:z*"] }) | ||
assert r[:valid] | ||
end | ||
|
||
test "_validate_query/1" do | ||
{ :ok, 201, _ } = HTTP.put("/bear_test/my_type/2?refresh=true", [user: "zatvobor"]) | ||
search = [query: [ term: [ user: "zatvobor" ] ]] | ||
{ :ok, 200, r } = Resources.bump(search)._validate_query("bear_test") | ||
assert r[:valid] | ||
end | ||
|
||
test "_count/2" do | ||
{ :ok, 201, _ } = HTTP.put("/bear_test/my_type/2?refresh=true", [user: "zatvobor"]) | ||
search = [query: [ term: [ user: "zatvobor" ] ]] | ||
{ :ok, 200, r } = Resources.bump(search)._count("bear_test", "my_type") | ||
assert r[:count] == 1 | ||
end | ||
|
||
test "_search_exists/2" do | ||
{ :ok, 201, _ } = HTTP.put("/bear_test/my_type/2?refresh=true", [user: "zatvobor"]) | ||
search = [query: [ term: [ user: "zatvobor" ] ]] | ||
{ :ok, 200, r } = Resources.bump(search)._search_exists("bear_test", "my_type") | ||
assert r[:exists] | ||
end | ||
|
||
test "_search/2" do | ||
{ :ok, 201, _ } = HTTP.put("/bear_test/my_type/2?refresh=true", [user: "zatvobor"]) | ||
search = [query: [ term: [ user: "zatvobor" ] ]] | ||
{ :ok, 200, r } = Resources.bump(search)._search("bear_test", "my_type") | ||
assert r[:hits][:total] == 1 | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.