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
Extend use of max_candidates to facet searching as well.
Kishore Nallan0ed59f623041
diff --git a/include/index.h b/include/index.hindex da64f7ed..0bcda7e2 100644--- a/include/index.h+++ b/include/index.h@@ -872,6 +872,7 @@ public:const size_t facet_query_num_typos,const uint32_t* all_result_ids, const size_t& all_result_ids_len,const std::vector<std::string>& group_by_fields,+ size_t max_candidates,std::vector<facet_info_t>& facet_infos) const;void resolve_space_as_typos(std::vector<std::string>& qtokens, const std::string& field_name,diff --git a/src/index.cpp b/src/index.cppindex bd36cec6..b9da716a 100644--- a/src/index.cpp+++ b/src/index.cpp@@ -2524,7 +2524,7 @@ void Index::search(std::vector<query_tokens_t>& field_query_tokens, const std::vstd::vector<facet_info_t> facet_infos(facets.size());compute_facet_infos(facets, facet_query, facet_query_num_typos, all_result_ids, all_result_ids_len,- group_by_fields, facet_infos);+ group_by_fields, max_candidates, facet_infos);std::vector<std::vector<facet>> facet_batches(num_threads);for(size_t i = 0; i < num_threads; i++) {@@ -2609,7 +2609,7 @@ void Index::search(std::vector<query_tokens_t>& field_query_tokens, const std::vstd::vector<facet_info_t> facet_infos(facets.size());compute_facet_infos(facets, facet_query, facet_query_num_typos,- &included_ids_vec[0], included_ids_vec.size(), group_by_fields, facet_infos);+ &included_ids_vec[0], included_ids_vec.size(), group_by_fields, max_candidates, facet_infos);do_facets(facets, facet_query, facet_infos, group_limit, group_by_fields, &included_ids_vec[0], included_ids_vec.size());all_result_ids_len += curated_topster->size;@@ -3665,6 +3665,7 @@ void Index::compute_facet_infos(const std::vector<facet>& facets, facet_query_t&const size_t facet_query_num_typos,const uint32_t* all_result_ids, const size_t& all_result_ids_len,const std::vector<std::string>& group_by_fields,+ const size_t max_candidates,std::vector<facet_info_t>& facet_infos) const {if(all_result_ids_len == 0) {@@ -3727,7 +3728,7 @@ void Index::compute_facet_infos(const std::vector<facet>& facets, facet_query_t&facet_field, facet_field.faceted_name(),all_result_ids, all_result_ids_len, {}, {}, -1, facet_query_num_typos, searched_queries, topster,groups_processed, &field_result_ids, field_result_ids_len, field_num_results, 0, group_by_fields,- false, 4, query_hashes, MAX_SCORE, true, 0, 1, false, -1, 3, 1000, 4);+ false, 4, query_hashes, MAX_SCORE, true, 0, 1, false, -1, 3, 1000, max_candidates);//LOG(INFO) << "searched_queries.size: " << searched_queries.size();diff --git a/test/collection_faceting_test.cpp b/test/collection_faceting_test.cppindex b395f659..a8152ad0 100644--- a/test/collection_faceting_test.cpp+++ b/test/collection_faceting_test.cpp@@ -839,6 +839,41 @@ TEST_F(CollectionFacetingTest, FacetQueryOnStringArray) {collectionManager.drop_collection("coll1");}+TEST_F(CollectionFacetingTest, FacetQueryReturnAllCandidates) {+ std::vector<field> fields = {field("title", field_types::STRING, true),+ field("points", field_types::INT32, false)};++ std::vector<sort_by> sort_fields = {sort_by("points", "DESC")};++ Collection* coll1 = collectionManager.create_collection("coll1", 4, fields, "points").get();++ std::vector<std::string> titles = {+ "everest", "evergreen", "everlast", "estrange", "energy", "extra"+ };++ for(size_t i=0; i < titles.size(); i++) {+ nlohmann::json doc;+ doc["id"] = std::to_string(i);+ doc["points"] = i;+ doc["title"] = titles[i];+ ASSERT_TRUE(coll1->add(doc.dump()).ok());+ }++ auto res_op = coll1->search("*", {}, "", {"title"}, sort_fields, {0}, 10, 1,+ token_ordering::FREQUENCY, {true}, 10, spp::sparse_hash_set<std::string>(),+ spp::sparse_hash_set<std::string>(), 10, "title:e", 30, 5,+ "", 10, {}, {}, {}, 0,+ "<mark>", "</mark>", {}, 1000, true, false, true, "", false, 6000 * 1000, 4, 7, true,+ 10, {off}, 32767, 32767, 2,+ false, false);++ ASSERT_TRUE(res_op.ok());++ auto results = res_op.get();+ ASSERT_EQ(6, results["facet_counts"][0]["counts"].size());+ collectionManager.drop_collection("coll1");+}+TEST_F(CollectionFacetingTest, FacetValuesShouldBeNormalized) {std::vector<field> fields = {field("brand", field_types::STRING, true),};