From d44afc3295b148671612d599d3c2345afb4d5e09 Mon Sep 17 00:00:00 2001 From: Kishore Nallan Date: Thu, 2 Feb 2023 16:48:18 +0530 Subject: [PATCH] Enabling exhaustive search should automatically drop tokens. --- 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 8a6e8ded..2f3b6f07 100644 --- a/src/index.cpp +++ b/src/index.cpp @@ -2782,7 +2782,7 @@ void Index::search(std::vector& field_query_tokens, const std::v // gather up both original query and synonym queries and do drop tokens - if (all_result_ids_len < drop_tokens_threshold) { + if (exhaustive_search || all_result_ids_len < drop_tokens_threshold) { for (size_t qi = 0; qi < all_queries.size(); qi++) { auto& orig_tokens = all_queries[qi]; size_t num_tokens_dropped = 0; diff --git a/test/collection_specific_more_test.cpp b/test/collection_specific_more_test.cpp index 1da106a5..553f902b 100644 --- a/test/collection_specific_more_test.cpp +++ b/test/collection_specific_more_test.cpp @@ -1869,6 +1869,34 @@ TEST_F(CollectionSpecificMoreTest, SearchCutoffTest) { ASSERT_EQ(408, coll_op.code()); } +TEST_F(CollectionSpecificMoreTest, ExhaustiveSearchWithoutExplicitDropTokens) { + nlohmann::json schema = R"({ + "name": "coll1", + "fields": [ + {"name": "title", "type": "string"} + ] + })"_json; + + Collection* coll1 = collectionManager.create_collection(schema).get(); + + nlohmann::json doc; + doc["title"] = "alpha beta gamma"; + ASSERT_TRUE(coll1->add(doc.dump()).ok()); + + doc["title"] = "alpha"; + ASSERT_TRUE(coll1->add(doc.dump()).ok()); + + bool exhaustive_search = true; + size_t drop_tokens_threshold = 1; + + auto res = coll1->search("alpha beta", {"title"}, "", {}, {}, {0}, 3, 1, FREQUENCY, {false}, drop_tokens_threshold, + spp::sparse_hash_set(), + spp::sparse_hash_set(), 10, "", 30, 4, "title", 20, {}, {}, {}, 0, + "", "", {}, 1000, true, false, true, "", exhaustive_search).get(); + + ASSERT_EQ(2, res["hits"].size()); +} + TEST_F(CollectionSpecificMoreTest, CrossFieldTypoAndPrefixWithWeights) { nlohmann::json schema = R"({ "name": "coll1",