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 edge case with phrase match on array.

Kishore Nallanb5aa84f743d7
diff --git a/src/posting_list.cpp b/src/posting_list.cpp
index 61035fc5..23f17e8b 100644
--- a/src/posting_list.cpp
+++ b/src/posting_list.cpp
@@ -1302,7 +1302,7 @@ void posting_list_t::get_phrase_matches(std::vector<iterator_t>& its, bool field
for(auto& kv: array_token_positions) {
const auto& token_positions = kv.second;
- if(has_phrase_match(token_positions)) {
+ if(token_positions.size() == its.size() && has_phrase_match(token_positions)) {
phrase_ids[phrase_id_index] = ids[i];
phrase_id_index++;
break;
diff --git a/test/collection_specific_more_test.cpp b/test/collection_specific_more_test.cpp
index 9593d33a..070b0580 100644
--- a/test/collection_specific_more_test.cpp
+++ b/test/collection_specific_more_test.cpp
@@ -1782,6 +1782,26 @@ TEST_F(CollectionSpecificMoreTest, PhraseMatchMultipleFields) {
ASSERT_EQ("0", res["hits"][1]["document"]["id"].get<std::string>());
}
+TEST_F(CollectionSpecificMoreTest, PhraseMatchAcrossArrayElements) {
+ nlohmann::json schema = R"({
+ "name": "coll1",
+ "fields": [
+ {"name": "texts", "type": "string[]"}
+ ]
+ })"_json;
+
+ Collection* coll1 = collectionManager.create_collection(schema).get();
+
+ nlohmann::json doc;
+ doc["texts"] = {"state of the", "of the art"};
+
+ ASSERT_TRUE(coll1->add(doc.dump()).ok());
+
+ auto res = coll1->search(R"("state of the art)", {"texts"}, "", {}, {}, {0}, 10, 1,
+ FREQUENCY, {true}, 10, spp::sparse_hash_set<std::string>()).get();
+ ASSERT_EQ(0, res["hits"].size());
+}
+
TEST_F(CollectionSpecificMoreTest, WeightTakingPrecendeceOverMatch) {
nlohmann::json schema = R"({
"name": "coll1",