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
handle facet query with multiple tokens in value index
krunaleeb7521394fd
diff --git a/include/facet_index.h b/include/facet_index.hindex 33ad924e..fb3ce3b7 100644--- a/include/facet_index.h+++ b/include/facet_index.h@@ -133,7 +133,7 @@ public:size_t get_facet_count(const std::string& field_name);size_t intersect(facet& a_facet,- bool has_facet_query, const std::vector<std::string>& fvalue_searched_tokens,+ bool has_facet_query, const std::vector<std::vector<std::string>>& fvalue_searched_tokens,const uint32_t* result_ids, size_t result_id_len,size_t max_facet_count, std::map<std::string, docid_count_t>& found,bool is_wildcard_no_filter_query, const std::string& sort_order = "");diff --git a/include/field.h b/include/field.hindex da91f6d3..6407ee5f 100644--- a/include/field.h+++ b/include/field.h@@ -677,7 +677,7 @@ struct facet {struct facet_info_t {// facet hash => resolved tokensstd::unordered_map<uint64_t, std::vector<std::string>> hashes;- std::vector<std::string> fvalue_searched_tokens;+ std::vector<std::vector<std::string>> fvalue_searched_tokens;bool use_facet_query = false;bool should_compute_stats = false;bool use_value_index = false;diff --git a/src/facet_index.cpp b/src/facet_index.cppindex 9e4d6cd3..1b25d572 100644--- a/src/facet_index.cpp+++ b/src/facet_index.cpp@@ -158,7 +158,7 @@ size_t facet_index_t::get_facet_count(const std::string& field_name) {//returns the count of matching seq_ids from result arraysize_t facet_index_t::intersect(facet& a_facet,- bool has_facet_query, const std::vector<std::string>& fvalue_searched_tokens,+ bool has_facet_query, const std::vector<std::vector<std::string>>& fvalue_searched_tokens,const uint32_t* result_ids, size_t result_ids_len,size_t max_facet_count, std::map<std::string, docid_count_t>& found,bool is_wildcard_no_filter_query, const std::string& sort_order) {@@ -187,10 +187,17 @@ size_t facet_index_t::intersect(facet& a_facet,auto facet_str = facet_count_it->facet_value;transform(facet_str.begin(), facet_str.end(), facet_str.begin(), ::tolower);- for(const auto& searched_token: fvalue_searched_tokens) {- if(facet_str.find(searched_token) != std::string::npos) {+ for(const auto& searched_tokens : fvalue_searched_tokens) {+ uint16_t found_tokens_count = 0;+ for (const auto &searched_token: searched_tokens) {+ if (facet_str.find(searched_token) != std::string::npos) {+ found_tokens_count++;+ }+ }++ if (found_tokens_count == searched_tokens.size()) {+ a_facet.fvalue_tokens[facet_count_it->facet_value] = searched_tokens;found_search_token = true;- a_facet.fvalue_tokens[facet_count_it->facet_value] = fvalue_searched_tokens;break;}}diff --git a/src/index.cpp b/src/index.cppindex 8c7c8725..9a8b5960 100644--- a/src/index.cpp+++ b/src/index.cpp@@ -5166,9 +5166,7 @@ void Index::compute_facet_infos(const std::vector<facet>& facets, facet_query_t&// need to ensure that document ID actually contains searched_query tokens// since `field_result_ids` contains documents matched across all queries// value based index- for(const auto& val : searched_tokens) {- facet_infos[findex].fvalue_searched_tokens.emplace_back(val);- }+ facet_infos[findex].fvalue_searched_tokens.emplace_back(searched_tokens);}}