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
Fix value based faceting regression.
Kishore Nallanf502526588d4
diff --git a/src/collection.cpp b/src/collection.cppindex 41d5e9b1..ecee8eda 100644--- a/src/collection.cpp+++ b/src/collection.cpp@@ -2062,13 +2062,6 @@ Option<nlohmann::json> Collection::search(std::string raw_query,auto & facet_count = kv.second;std::string value;- const std::string& seq_id_key = get_seq_id_key((uint32_t) facet_count.doc_id);- nlohmann::json document;- const Option<bool> & document_op = get_document_from_store(seq_id_key, document);- if(!document_op.ok()) {- LOG(ERROR) << "Facet fetch error. " << document_op.error();- continue;- }if(a_facet.is_intersected) {value = kv.first;@@ -2076,14 +2069,22 @@ Option<nlohmann::json> Collection::search(std::string raw_query,} else {// fetch actual facet value from representative doc id//LOG(INFO) << "used hashes";+ const std::string& seq_id_key = get_seq_id_key((uint32_t) facet_count.doc_id);+ nlohmann::json document;+ const Option<bool> & document_op = get_document_from_store(seq_id_key, document);+ if(!document_op.ok()) {+ LOG(ERROR) << "Facet fetch error. " << document_op.error();+ continue;+ }+bool facet_found = facet_value_to_string(a_facet, facet_count, document, value);if(!facet_found) {continue;}- }- if(the_field.nested && should_return_parent) {- value = get_facet_parent(the_field.name, document);+ if(the_field.nested && should_return_parent) {+ value = get_facet_parent(the_field.name, document);+ }}std::unordered_map<std::string, size_t> ftoken_pos;diff --git a/src/index.cpp b/src/index.cppindex 82bcc5cb..3d64ce3b 100644--- a/src/index.cpp+++ b/src/index.cpp@@ -1340,6 +1340,7 @@ void Index::do_facets(std::vector<facet> & facets, facet_query_t & facet_query,}}} else {+ //LOG(INFO) << "Using hashing to find facets";bool facet_hash_index_exists = facet_index_v4->has_hash_index(facet_field.name);if(!facet_hash_index_exists) {continue;diff --git a/test/collection_optimized_faceting_test.cpp b/test/collection_optimized_faceting_test.cppindex 42bc630d..0b85224c 100644--- a/test/collection_optimized_faceting_test.cpp+++ b/test/collection_optimized_faceting_test.cpp@@ -1306,6 +1306,49 @@ TEST_F(CollectionOptimizedFacetingTest, FacetOnArrayFieldWithSpecialChars) {}}+TEST_F(CollectionOptimizedFacetingTest, FacetTestWithDeletedDoc) {+ std::vector<field> fields = {+ field("tags", field_types::STRING_ARRAY, true),+ field("points", field_types::INT32, true),+ };++ Collection* coll1 = collectionManager.create_collection("coll1", 1, fields).get();++ nlohmann::json doc;++ doc["id"] = "0";+ doc["tags"] = {"foobar"};+ doc["points"] = 10;+ ASSERT_TRUE(coll1->add(doc.dump()).ok());++ doc["id"] = "1";+ doc["tags"] = {"gamma"};+ doc["points"] = 10;+ ASSERT_TRUE(coll1->add(doc.dump()).ok());++ doc["id"] = "2";+ doc["tags"] = {"beta"};+ doc["points"] = 10;+ ASSERT_TRUE(coll1->add(doc.dump()).ok());++ doc["id"] = "3";+ doc["tags"] = {"alpha"};+ doc["points"] = 10;+ ASSERT_TRUE(coll1->add(doc.dump()).ok());++ coll1->remove("0");++ auto results = coll1->search("*", {},+ "", {"tags"}, {}, {2}, 10, 1, FREQUENCY, {true}, 1, spp::sparse_hash_set<std::string>(),+ spp::sparse_hash_set<std::string>(), 10, "", 30, 4, "", 20, {}, {}, {}, 0,+ "<mark>", "</mark>", {}, 1000, true, false, true, "", false, 6000 * 1000, 4, 7, fallback,+ 4, {off}, 3, 3, 2, 2, false, "", true, 0, max_score, 100, 0, 4294967295UL, VALUE).get();+++ ASSERT_EQ(1, results["facet_counts"].size());+ ASSERT_EQ(3, results["facet_counts"][0]["counts"].size());+}+TEST_F(CollectionOptimizedFacetingTest, StringLengthTest) {std::vector<field> fields = {field("tags", field_types::STRING_ARRAY, true),