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
provide list of fields to fetch parents
krunale38aad57a259
diff --git a/include/collection.h b/include/collection.hindex e169ce76..95c4b235 100644--- a/include/collection.h+++ b/include/collection.h@@ -477,7 +477,7 @@ public:const size_t remote_embedding_timeout_ms = 30000,const size_t remote_embedding_num_try = 2,const std::string& stopwords_set="",- bool facet_return_parent = false) const;+ const std::vector<std::string>& facet_return_parent = {}) const;Option<bool> get_filter_ids(const std::string & filter_query, filter_result_t& filter_result) const;diff --git a/src/collection.cpp b/src/collection.cppindex 01e71954..07e7a58d 100644--- a/src/collection.cpp+++ b/src/collection.cpp@@ -1124,7 +1124,7 @@ Option<nlohmann::json> Collection::search(std::string raw_query,const size_t remote_embedding_timeout_ms,const size_t remote_embedding_num_try,const std::string& stopwords_set,- bool facet_return_parent) const {+ const std::vector<std::string>& facet_return_parent) const {std::shared_lock lock(mutex);@@ -2091,7 +2091,8 @@ Option<nlohmann::json> Collection::search(std::string raw_query,}}- if(facet_return_parent && the_field.nested) {+ if(the_field.nested &&+ (std::find(facet_return_parent.begin(), facet_return_parent.end(), the_field.name) != facet_return_parent.end())) {value = get_facet_parent(the_field.name, document);}diff --git a/src/collection_manager.cpp b/src/collection_manager.cppindex c0248507..58eac68c 100644--- a/src/collection_manager.cpp+++ b/src/collection_manager.cpp@@ -805,6 +805,8 @@ Option<bool> CollectionManager::do_search(std::map<std::string, std::string>& reconst char *FACET_QUERY_NUM_TYPOS = "facet_query_num_typos";const char *MAX_FACET_VALUES = "max_facet_values";+ const char *FACET_RETURN_PARENT = "facet_return_parent";+const char *VECTOR_QUERY = "vector_query";const char* REMOTE_EMBEDDING_TIMEOUT_MS = "remote_embedding_timeout_ms";@@ -933,6 +935,8 @@ Option<bool> CollectionManager::do_search(std::map<std::string, std::string>& resize_t offset = 0;token_ordering token_order = NOT_SET;+ std::vector<std::string> facet_return_parent;+std::string vector_query;std::vector<std::string> include_fields_vec;@@ -1029,6 +1033,7 @@ Option<bool> CollectionManager::do_search(std::map<std::string, std::string>& re{GROUP_BY, &group_by_fields},{INCLUDE_FIELDS, &include_fields_vec},{EXCLUDE_FIELDS, &exclude_fields_vec},+ {FACET_RETURN_PARENT, &facet_return_parent},};std::unordered_map<std::string, std::vector<uint32_t>*> int_list_values = {@@ -1218,7 +1223,8 @@ Option<bool> CollectionManager::do_search(std::map<std::string, std::string>& reHASH,remote_embedding_timeout_ms,remote_embedding_num_try,- stopwords_set+ stopwords_set,+ facet_return_parent);uint64_t timeMillis = std::chrono::duration_cast<std::chrono::milliseconds>(diff --git a/test/collection_faceting_test.cpp b/test/collection_faceting_test.cppindex fee96a9b..5aa5ced9 100644--- a/test/collection_faceting_test.cpp+++ b/test/collection_faceting_test.cpp@@ -1682,7 +1682,7 @@ TEST_F(CollectionFacetingTest, FacetingReturnParent) {2, 2, false, "",true, 0, max_score, 100,0, 0, HASH, 30000,- 2, "",true);+ 2, "", {"value.color"});if(!search_op.ok()) {LOG(ERROR) << search_op.error();@@ -1694,7 +1694,7 @@ TEST_F(CollectionFacetingTest, FacetingReturnParent) {ASSERT_EQ("{\"b\":0,\"color\":\"red\",\"g\":0,\"r\":255}", results["facet_counts"][0]["counts"][0]["value"]);ASSERT_EQ("{\"b\":255,\"color\":\"blue\",\"g\":0,\"r\":0}", results["facet_counts"][0]["counts"][1]["value"]);- //not passing facet_return_parent will only return facet value, not immediate parent+ //not passing facet_fields in facet_return_parent list will only return facet value, not immediate parent for those fieldsearch_op = coll1->search("*", {},"", {"value.color"},{}, {2}, 10, 1,FREQUENCY, {true},1, spp::sparse_hash_set<std::string>(),@@ -1708,7 +1708,7 @@ TEST_F(CollectionFacetingTest, FacetingReturnParent) {2, 2, false, "",true, 0, max_score, 100,0, 0, HASH, 30000,- 2, "",false);+ 2, "", {"value.r", "value.g", "value.b"});if(!search_op.ok()) {LOG(ERROR) << search_op.error();@@ -1719,6 +1719,36 @@ TEST_F(CollectionFacetingTest, FacetingReturnParent) {ASSERT_EQ(2, results["facet_counts"][0]["counts"].size());ASSERT_EQ("red", results["facet_counts"][0]["counts"][0]["value"]);ASSERT_EQ("blue", results["facet_counts"][0]["counts"][1]["value"]);++ search_op = coll1->search("*", {},"", {"value.color", "value.r"},+ {}, {2}, 10, 1,FREQUENCY, {true},+ 1, spp::sparse_hash_set<std::string>(),+ spp::sparse_hash_set<std::string>(),10, "",+ 30, 4, "",+ Index::TYPO_TOKENS_THRESHOLD, "", "",{},+ 3, "<mark>", "</mark>", {},+ UINT32_MAX, true, false, true,+ "", false, 6000*1000, 4, 7,+ fallback, 4, {off}, INT16_MAX, INT16_MAX,+ 2, 2, false, "",+ true, 0, max_score, 100,+ 0, 0, HASH, 30000,+ 2, "", {"value.r", "value.g", "value.b"});++ if(!search_op.ok()) {+ LOG(ERROR) << search_op.error();+ FAIL();+ }+ results = search_op.get();+ ASSERT_EQ(2, results["facet_counts"].size());++ ASSERT_EQ(2, results["facet_counts"][0]["counts"].size());+ ASSERT_EQ("red", results["facet_counts"][0]["counts"][0]["value"]);+ ASSERT_EQ("blue", results["facet_counts"][0]["counts"][1]["value"]);++ ASSERT_EQ(2, results["facet_counts"][1]["counts"].size());+ ASSERT_EQ("{\"b\":0,\"color\":\"red\",\"g\":0,\"r\":255}", results["facet_counts"][1]["counts"][0]["value"]);+ ASSERT_EQ("{\"b\":255,\"color\":\"blue\",\"g\":0,\"r\":0}", results["facet_counts"][1]["counts"][1]["value"]);}TEST_F(CollectionFacetingTest, FacetingReturnParentDeepNested) {@@ -1772,7 +1802,7 @@ TEST_F(CollectionFacetingTest, FacetingReturnParentDeepNested) {2, 2, false, "",true, 0, max_score, 100,0, 0, HASH, 30000,- 2, "",true);+ 2, "", {"product.specification.detail.width"});if(!search_op.ok()) {LOG(ERROR) << search_op.error();