summaryrefslogtreecommitdiff
path: root/test/elixir/test/nouveau_test.exs
diff options
context:
space:
mode:
Diffstat (limited to 'test/elixir/test/nouveau_test.exs')
-rw-r--r--test/elixir/test/nouveau_test.exs82
1 files changed, 67 insertions, 15 deletions
diff --git a/test/elixir/test/nouveau_test.exs b/test/elixir/test/nouveau_test.exs
index ee5d20542..896ff6154 100644
--- a/test/elixir/test/nouveau_test.exs
+++ b/test/elixir/test/nouveau_test.exs
@@ -22,6 +22,7 @@ defmodule NouveauTest do
def create_ddoc(db_name, opts \\ %{}) do
default_ddoc = %{
+ autoupdate: false,
nouveau: %{
bar: %{
default_analyzer: "standard",
@@ -42,22 +43,47 @@ defmodule NouveauTest do
assert Map.has_key?(resp.body, "ok") == true
end
+ def create_mango_index(db_name) do
+ body = %{
+ type: "nouveau",
+ index: %{
+ fields: [
+ %{name: "foo", type: "string"},
+ %{name: "bar", type: "number"}
+ ]
+ }
+ }
+
+ resp = Couch.post("/#{db_name}/_index", body: body)
+ assert resp.status_code in [200]
+ end
+
def get_ids(resp) do
%{:body => %{"hits" => hits}} = resp
Enum.map(hits, fn hit -> hit["doc"]["_id"] end)
end
+ def get_mango_ids(resp) do
+ %{:body => %{"docs" => docs}} = resp
+ Enum.map(docs, fn doc -> doc["_id"] end)
+ end
+
def get_bookmark(resp) do
%{:body => %{"bookmark" => bookmark}} = resp
bookmark
end
+ def assert_status_code(resp, code) do
+ assert resp.status_code == code,
+ "status code: #{resp.status_code}, resp body: #{:jiffy.encode(resp.body)}"
+ end
+
test "search analyze", context do
url = "/_nouveau_analyze"
resp = Couch.post(url,
headers: ["Content-Type": "application/json"],
body: %{analyzer: "standard", text: "hello there"})
- assert resp.status_code == 200, "error #{resp.status_code} #{:jiffy.encode(resp.body)}"
+ assert_status_code(resp, 200)
assert resp.body == %{"tokens" => ["hello", "there"]}
end
@@ -70,11 +96,11 @@ defmodule NouveauTest do
# query it so it builds
url = "/#{db_name}/_design/foo/_nouveau/bar"
resp = Couch.get(url, query: %{q: "*:*", include_docs: true})
- assert resp.status_code == 200, "error #{resp.status_code} #{:jiffy.encode(resp.body)}"
+ assert_status_code(resp, 200)
url = "/#{db_name}/_design/foo/_nouveau_info/bar"
resp = Couch.get(url)
- assert resp.status_code == 200, "error #{resp.status_code} #{:jiffy.encode(resp.body)}"
+ assert_status_code(resp, 200)
info = Map.get(resp.body, "search_index")
assert Map.get(info, "disk_size") > 0
assert Map.get(info, "num_docs") > 0
@@ -89,7 +115,7 @@ defmodule NouveauTest do
url = "/#{db_name}/_design/foo/_nouveau/bar"
resp = Couch.get(url, query: %{q: "*:*", include_docs: true})
- assert resp.status_code == 200, "error #{resp.status_code} #{:jiffy.encode(resp.body)}"
+ assert_status_code(resp, 200)
ids = get_ids(resp)
# nouveau sorts by _id as tie-breaker
assert ids == ["doc1", "doc2", "doc3", "doc4"]
@@ -103,7 +129,7 @@ defmodule NouveauTest do
url = "/#{db_name}/_design/foo/_nouveau/bar"
resp = Couch.post(url, body: %{q: "*:*", include_docs: true})
- assert resp.status_code == 200, "error #{resp.status_code} #{:jiffy.encode(resp.body)}"
+ assert_status_code(resp, 200)
ids = get_ids(resp)
assert ids == ["doc1", "doc2", "doc3", "doc4"]
end
@@ -118,13 +144,13 @@ defmodule NouveauTest do
# page 1
resp = Couch.post(url, body: %{q: "*:*", limit: 2, include_docs: true})
- assert resp.status_code == 200, "error #{resp.status_code} #{:jiffy.encode(resp.body)}"
+ assert_status_code(resp, 200)
ids = get_ids(resp)
assert ids == ["doc1", "doc2"]
# page 2
resp = Couch.post(url, body: %{q: "*:*", limit: 2, bookmark: get_bookmark(resp), include_docs: true})
- assert resp.status_code == 200, "error #{resp.status_code} #{:jiffy.encode(resp.body)}"
+ assert_status_code(resp, 200)
ids = get_ids(resp)
assert ids == ["doc3", "doc4"]
end
@@ -137,7 +163,7 @@ defmodule NouveauTest do
url = "/#{db_name}/_design/foo/_nouveau/bar"
resp = Couch.post(url, body: %{q: "foo:bar", include_docs: true})
- assert resp.status_code == 200, "error #{resp.status_code} #{:jiffy.encode(resp.body)}"
+ assert_status_code(resp, 200)
ids = get_ids(resp)
assert ids == ["doc3"]
end
@@ -150,7 +176,7 @@ defmodule NouveauTest do
url = "/#{db_name}/_design/foo/_nouveau/bar"
resp = Couch.post(url, body: %{q: "*:*", sort: "foo<string>", include_docs: true})
- assert resp.status_code == 200, "error #{resp.status_code} #{:jiffy.encode(resp.body)}"
+ assert_status_code(resp, 200)
ids = get_ids(resp)
assert ids == ["doc3", "doc1", "doc4", "doc2"]
end
@@ -163,7 +189,7 @@ defmodule NouveauTest do
url = "/#{db_name}/_design/foo/_nouveau/bar"
resp = Couch.post(url, body: %{q: "*:*", sort: "-foo<string>", include_docs: true})
- assert resp.status_code == 200, "error #{resp.status_code} #{:jiffy.encode(resp.body)}"
+ assert_status_code(resp, 200)
ids = get_ids(resp)
assert ids == ["doc2", "doc4", "doc1", "doc3"]
end
@@ -176,7 +202,7 @@ defmodule NouveauTest do
url = "/#{db_name}/_design/foo/_nouveau/bar"
resp = Couch.post(url, body: %{q: "*:*", sort: "bar<double>", include_docs: true})
- assert resp.status_code == 200, "error #{resp.status_code} #{:jiffy.encode(resp.body)}"
+ assert_status_code(resp, 200)
ids = get_ids(resp)
assert ids == ["doc1", "doc3", "doc4", "doc2"]
end
@@ -189,7 +215,7 @@ defmodule NouveauTest do
url = "/#{db_name}/_design/foo/_nouveau/bar"
resp = Couch.post(url, body: %{q: "*:*", sort: "-bar<double>", include_docs: true})
- assert resp.status_code == 200, "error #{resp.status_code} #{:jiffy.encode(resp.body)}"
+ assert_status_code(resp, 200)
ids = get_ids(resp)
assert ids == ["doc2", "doc4", "doc3", "doc1"]
end
@@ -202,7 +228,7 @@ defmodule NouveauTest do
url = "/#{db_name}/_design/foo/_nouveau/bar"
resp = Couch.post(url, body: %{q: "*:*", counts: ["foo"], include_docs: true})
- assert resp.status_code == 200, "error #{resp.status_code} #{:jiffy.encode(resp.body)}"
+ assert_status_code(resp, 200)
%{:body => %{"counts" => counts}} = resp
assert counts == %{"foo" => %{"bar" => 1, "baz" => 1, "foo" => 1, "foobar" => 1}}
end
@@ -218,7 +244,7 @@ defmodule NouveauTest do
%{label: "cheap", min: 0, max: 42},
%{label: "expensive", min: 42, min_inclusive: false, max: 1000}]},
include_docs: true})
- assert resp.status_code == 200, "error #{resp.status_code} #{:jiffy.encode(resp.body)}"
+ assert_status_code(resp, 200)
%{:body => %{"ranges" => ranges}} = resp
assert ranges == %{"bar" => %{"cheap" => 3, "expensive" => 1}}
end
@@ -234,9 +260,35 @@ defmodule NouveauTest do
%{label: "cheap", max: 42},
%{label: "expensive", min: 42, min_inclusive: false}]},
include_docs: true})
- assert resp.status_code == 200, "error #{resp.status_code} #{:jiffy.encode(resp.body)}"
+ assert_status_code(resp, 200)
%{:body => %{"ranges" => ranges}} = resp
assert ranges == %{"bar" => %{"cheap" => 3, "expensive" => 1}}
end
+ @tag :with_db
+ test "mango search by number", context do
+ db_name = context[:db_name]
+ create_search_docs(db_name)
+ create_mango_index(db_name)
+
+ url = "/#{db_name}/_find"
+ resp = Couch.post(url, body: %{selector: %{bar: %{"$gt": 5}}})
+ assert_status_code(resp, 200)
+ ids = get_mango_ids(resp)
+ assert ids == ["doc2", "doc3", "doc4"]
+ end
+
+ @tag :with_db
+ test "mango search by string", context do
+ db_name = context[:db_name]
+ create_search_docs(db_name)
+ create_mango_index(db_name)
+
+ url = "/#{db_name}/_find"
+ resp = Couch.post(url, body: %{selector: %{foo: %{"$eq": "foo"}}})
+ assert_status_code(resp, 200)
+ ids = get_mango_ids(resp)
+ assert ids == ["doc4"]
+ end
+
end