diff --git a/src/mango/test/06-text-default-field-test.py b/src/mango/test/06-text-default-field-test.py deleted file mode 100644 index 1e88967f2e1..00000000000 --- a/src/mango/test/06-text-default-field-test.py +++ /dev/null @@ -1,64 +0,0 @@ -# Licensed under the Apache License, Version 2.0 (the "License"); you may not -# use this file except in compliance with the License. You may obtain a copy of -# the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, WITHOUT -# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the -# License for the specific language governing permissions and limitations under -# the License. - -import mango -import unittest - - -@unittest.skipUnless(mango.has_text_service(), "requires text service") -class NoDefaultFieldTest(mango.UserDocsTextTests): - DEFAULT_FIELD = False - - def test_basic(self): - docs = self.db.find({"$text": "Ramona"}) - # Or should this throw an error? - assert len(docs) == 0 - - def test_other_fields_exist(self): - docs = self.db.find({"age": 22}) - assert len(docs) == 1 - assert docs[0]["user_id"] == 9 - - -@unittest.skipUnless(mango.has_text_service(), "requires text service") -class NoDefaultFieldWithAnalyzer(mango.UserDocsTextTests): - DEFAULT_FIELD = {"enabled": False, "analyzer": "keyword"} - - def test_basic(self): - docs = self.db.find({"$text": "Ramona"}) - assert len(docs) == 0 - - def test_other_fields_exist(self): - docs = self.db.find({"age": 22}) - assert len(docs) == 1 - assert docs[0]["user_id"] == 9 - - -@unittest.skipUnless(mango.has_text_service(), "requires text service") -class DefaultFieldWithCustomAnalyzer(mango.UserDocsTextTests): - DEFAULT_FIELD = {"enabled": True, "analyzer": "keyword"} - - def test_basic(self): - docs = self.db.find({"$text": "Ramona"}) - assert len(docs) == 1 - assert docs[0]["user_id"] == 9 - - def test_not_analyzed(self): - docs = self.db.find({"$text": "Lott Place"}) - assert len(docs) == 1 - assert docs[0]["user_id"] == 9 - - docs = self.db.find({"$text": "Lott"}) - assert len(docs) == 0 - - docs = self.db.find({"$text": "Place"}) - assert len(docs) == 0 diff --git a/test/elixir/test/config/search.elixir b/test/elixir/test/config/search.elixir index 87715d4caf3..c2714ca9e7a 100644 --- a/test/elixir/test/config/search.elixir +++ b/test/elixir/test/config/search.elixir @@ -38,5 +38,17 @@ ], "LimitTests": [ "limit field" - ] + ], + "NoDefaultFieldTest": [ + "basic", + "other fields exist", + ], + "NoDefaultFieldWithAnalyzer": [ + "basic", + "other fields exist", + ], + "DefaultFieldWithCustomAnalyzer": [ + "basic", + "not analyzed", + ], } diff --git a/test/elixir/test/mango/06-text-default-field-test.exs b/test/elixir/test/mango/06-text-default-field-test.exs new file mode 100644 index 00000000000..92c8a8b67f1 --- /dev/null +++ b/test/elixir/test/mango/06-text-default-field-test.exs @@ -0,0 +1,100 @@ +# Licensed under the Apache License, Version 2.0 (the "License"); you may not +# use this file except in compliance with the License. You may obtain a copy of +# the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, WITHOUT +# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the +# License for the specific language governing permissions and limitations under +# the License. + +defmodule NoDefaultFieldTest do + use CouchTestCase + + @db_name "no-default-field" + + setup do + UserDocs.setup(@db_name, "text") + MangoDatabase.create_text_index( + @db_name, + default_field: false, + ddoc: "text" + ) + :ok + end + + test "basic" do + {:ok, docs} = MangoDatabase.find(@db_name, %{"$text" => "Ramona"}, use_index: "text") + # Or should this throw an error? + assert Enum.empty?(docs) + end + + test "other fields exist" do + {:ok, docs} = MangoDatabase.find(@db_name, %{"age" => 22}, use_index: "text") + assert length(docs) == 1 + assert Enum.at(docs, 0)["user_id"] == 9 + end +end + +defmodule NoDefaultFieldWithAnalyzer do + use CouchTestCase + + @db_name "no-default-field-with-analyzer" + + setup do + UserDocs.setup(@db_name, "text") + MangoDatabase.create_text_index( + @db_name, + default_field: %{"enabled" => false, "analyzer" => "keyword"}, + ddoc: "text" + ) + :ok + end + + test "basic" do + {:ok, docs} = MangoDatabase.find(@db_name, %{"$text" => "Ramona"}, use_index: "text") + assert Enum.empty?(docs) + end + + test "other fields exist" do + {:ok, docs} = MangoDatabase.find(@db_name, %{"age" => 22}, use_index: "text") + assert length(docs) == 1 + assert Enum.at(docs, 0)["user_id"] == 9 + end +end + +defmodule DefaultFieldWithCustomAnalyzer do + use CouchTestCase + + @db_name "default-field-with-custom-analyser" + + setup do + UserDocs.setup(@db_name, "text") + MangoDatabase.create_text_index( + @db_name, + default_field: %{"enabled" => true, "analyzer" => "keyword"}, + ddoc: "text" + ) + :ok + end + + test "basic" do + {:ok, docs} = MangoDatabase.find(@db_name, %{"$text" => "Ramona"}, use_index: "text") + assert length(docs) == 1 + assert Enum.at(docs, 0)["user_id"] == 9 + end + + test "not analyzed" do + {:ok, docs} = MangoDatabase.find(@db_name, %{"$text" => "Lott Place"}, use_index: "text") + assert length(docs) == 1 + assert Enum.at(docs, 0)["user_id"] == 9 + + {:ok, docs} = MangoDatabase.find(@db_name, %{"$text" => "Lott"}, use_index: "text") + assert Enum.empty?(docs) + + {:ok, docs} = MangoDatabase.find(@db_name, %{"$text" => "Place"}, use_index: "text") + assert Enum.empty?(docs) + end +end