Skip to content

Open Source alternative to Algolia + Pinecone and an Easier-to-Use alternative to ElasticSearch ⚡ 🔍 ✨ Fast, typo tolerant, in-memory fuzzy Search Engine for building delightful search experiences

Fix an issue with multi-field phrase matching.

Kishore Nallanff8fbc064272
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::vector<s
}
// across fields, we have to OR phrase match ids
- if(filter_ids_length == 0) {
+ if(phrase_match_ids_size == 0) {
phrase_match_ids = field_phrase_match_ids;
phrase_match_ids_size = field_phrase_match_ids_size;
} else {
diff --git a/test/collection_specific_more_test.cpp b/test/collection_specific_more_test.cpp
index 4cfed868..f1c2945f 100644
--- a/test/collection_specific_more_test.cpp
+++ b/test/collection_specific_more_test.cpp
@@ -1591,3 +1591,31 @@ TEST_F(CollectionSpecificMoreTest, PhraseMatchRepeatingTokens) {
res = coll1->search(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<std::string>());
+ ASSERT_EQ("0", res["hits"][1]["document"]["id"].get<std::string>());
+}