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
C++ algoliadatastoreelasticsearchenterprise-searchfacetingfull-text-searchfuzzy-searchgeosearchin-memoryinstantsearchmerchandisingpineconesearchsearch-enginesemantic-searchsimilarity-searchsite-searchsynonymstypo-tolerancevector-search
Only the last facet query token must be treated as prefix.
kishorenc991bf03bcba7
diff --git a/include/collection.h b/include/collection.hindex 971527eb..907693a2 100644--- a/include/collection.h+++ b/include/collection.h@@ -169,7 +169,7 @@ public:Collection(const std::string name, const uint32_t collection_id, const uint64_t created_at,const uint32_t next_seq_id, Store *store, const std::vector<field> & fields,- const std::string & default_sorting_field, const size_t num_indices=4);+ const std::string & default_sorting_field, const size_t num_indices);~Collection();diff --git a/src/index.cpp b/src/index.cppindex 4dc469d4..3d3717c5 100644--- a/src/index.cpp+++ b/src/index.cpp@@ -555,10 +555,12 @@ void Index::do_facets(std::vector<facet> & facets, facet_query_t & facet_query,auto & q = query_tokens[qtoken_index];string_utils.unicode_normalize(q);int bounded_cost = (q.size() < 3) ? 0 : 1;+ bool prefix_search = (qtoken_index == (query_tokens.size()-1)); // only last token must be used as prefix+std::vector<art_leaf*> leaves;art_fuzzy_search(search_index.at(a_facet.field_name), (const unsigned char *) q.c_str(),- q.size(),0, bounded_cost, 10000,- token_ordering::MAX_SCORE, true, leaves);+ q.size(), 0, bounded_cost, 10000,+ token_ordering::MAX_SCORE, prefix_search, leaves);for(size_t i = 0; i < leaves.size(); i++) {const auto & leaf = leaves[i];// calculate hash without terminating null chardiff --git a/test/collection_test.cpp b/test/collection_test.cppindex 49ad46ba..b2e47020 100644--- a/test/collection_test.cpp+++ b/test/collection_test.cpp@@ -2082,6 +2082,22 @@ TEST_F(CollectionTest, FacetCountsHighlighting) {ASSERT_STREQ("Cell Phone Accessories", results["facet_counts"][0]["counts"][0]["value"].get<std::string>().c_str());ASSERT_STREQ("Cell Phone <mark>Acces</mark>sories", results["facet_counts"][0]["counts"][0]["highlighted"].get<std::string>().c_str());+ // ensure that only the last token is treated as prefix search++ coll1->remove("100");+ doc["categories"] = {"Cell Phones", "Cell Phone Accessories", "Cellophanes"};+ coll1->add(doc.dump());++ results = coll1->search("phone", {"categories"}, "", facets, sort_fields, 0, 10, 1,+ token_ordering::FREQUENCY, true, 10, spp::sparse_hash_set<std::string>(),+ spp::sparse_hash_set<std::string>(), 10, 500, "categories:cell ph").get();++ ASSERT_EQ(1, results["facet_counts"].size());+ ASSERT_EQ(2, results["facet_counts"][0]["counts"].size());++ ASSERT_STREQ("Cell Phones", results["facet_counts"][0]["counts"][0]["value"].get<std::string>().c_str());+ ASSERT_STREQ("Cell Phone Accessories", results["facet_counts"][0]["counts"][1]["value"].get<std::string>().c_str());+collectionManager.drop_collection("coll1");}@@ -2673,4 +2689,6 @@ TEST_F(CollectionTest, StringArrayFieldShouldNotAllowPlainString) {auto add_op = coll1->add(doc.dump());ASSERT_FALSE(add_op.ok());ASSERT_STREQ("Field `categories` must be a string array.", add_op.error().c_str());++ collectionManager.drop_collection("coll1");}\ No newline at end of file