From ff8fbc06427270384d2fc3c0230f385c0772090a Mon Sep 17 00:00:00 2001 From: Kishore Nallan Date: Tue, 18 Oct 2022 11:49:13 +0530 Subject: [PATCH] Fix an issue with multi-field phrase matching. --- src/index.cpp | 2 +- test/collection_specific_more_test.cpp | 28 ++++++++++++++++++++++++++ 2 files changed, 29 insertions(+), 1 deletion(-) diff --git a/src/index.cpp b/src/index.cpp index 470ee6e0..7fd85292 100644 --- a/src/index.cpp +++ b/src/index.cpp @@ -3874,7 +3874,7 @@ void Index::do_phrase_search(const size_t num_search_fields, const std::vectorsearch(R"("product fast")", {"title"}, "", {}, {}, {2}, 10, 1, FREQUENCY, {true}, 0).get(); ASSERT_EQ(0, res["hits"].size()); } + +TEST_F(CollectionSpecificMoreTest, PhraseMatchMultipleFields) { + nlohmann::json schema = R"({ + "name": "coll1", + "fields": [ + {"name": "title", "type": "string"}, + {"name": "author", "type": "string"} + ] + })"_json; + + Collection* coll1 = collectionManager.create_collection(schema).get(); + + nlohmann::json doc; + doc["id"] = "0"; + doc["title"] = "A Walk to the Tide Pools"; + doc["author"] = "Nok Nok"; + ASSERT_TRUE(coll1->add(doc.dump()).ok()); + + doc["id"] = "1"; + doc["title"] = "Random Title"; + doc["author"] = "Tide Pools"; + ASSERT_TRUE(coll1->add(doc.dump()).ok()); + + auto res = coll1->search(R"("tide pools")", {"title", "author"}, "", {}, {}, {2}, 10, 1, FREQUENCY, {true}, 0).get(); + ASSERT_EQ(2, res["hits"].size()); + ASSERT_EQ("1", res["hits"][0]["document"]["id"].get()); + ASSERT_EQ("0", res["hits"][1]["document"]["id"].get()); +}