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

Enabling exhaustive search should automatically drop tokens.

Kishore Nallanf40637fe643d
diff --git a/src/index.cpp b/src/index.cpp
index 94f084cd..f599eab6 100644
--- a/src/index.cpp
+++ b/src/index.cpp
@@ -2708,7 +2708,7 @@ void Index::search(std::vector<query_tokens_t>& 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 608c5fea..3527bbec 100644
--- a/test/collection_specific_more_test.cpp
+++ b/test/collection_specific_more_test.cpp
@@ -1782,6 +1782,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<std::string>(),
+ spp::sparse_hash_set<std::string>(), 10, "", 30, 4, "title", 20, {}, {}, {}, 0,
+ "<mark>", "</mark>", {}, 1000, true, false, true, "", exhaustive_search).get();
+
+ ASSERT_EQ(2, res["hits"].size());
+}
+
TEST_F(CollectionSpecificMoreTest, CrossFieldTypoAndPrefixWithWeights) {
nlohmann::json schema = R"({
"name": "coll1",