mirror of
https://github.com/typesense/typesense.git
synced 2025-05-22 06:40:30 +08:00
Fix an issue with multi-field phrase matching.
This commit is contained in:
parent
61986e700a
commit
ff8fbc0642
@ -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 {
|
||||
|
@ -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>());
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user