Skip to content

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

merge v0.26-facets

krunal7c6132837432
diff --cc include/facet_index.h
index cbca1da9,c7e2e288..058e3b12
--- a/include/facet_index.h
+++ b/include/facet_index.h
@@@ -125,9 -126,11 +126,11 @@@ public
size_t get_facet_count(const std::string& field_name);
- size_t intersect(const std::string& val, const uint32_t* result_ids, size_t result_id_len,
+ size_t intersect(facet& a_facet,
+ bool has_facet_query, const 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, uint32_t>& found,
- bool is_wildcard_no_filter_query);
+ bool is_wildcard_no_filter_query, const std::string& sort_order = "");
size_t get_facet_indexes(const std::string& field,
std::map<uint32_t, std::vector<uint32_t>>& seqid_countIndexes);
diff --cc src/facet_index.cpp
index 8c6fe69c,ca0805a4..f7749de3
--- a/src/facet_index.cpp
+++ b/src/facet_index.cpp
@@@ -147,12 -145,14 +147,14 @@@ size_t facet_index_t::get_facet_count(c
}
//returns the count of matching seq_ids from result array
- size_t facet_index_t::intersect(const std::string& field, const uint32_t* result_ids, size_t result_ids_len,
+ size_t facet_index_t::intersect(facet& a_facet,
+ bool has_facet_query, const 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, uint32_t>& found,
- bool is_wildcard_no_filter_query) {
+ bool is_wildcard_no_filter_query, const std::string& sort_order) {
//LOG (INFO) << "intersecting field " << field;
- const auto& facet_field_it = facet_field_map.find(field);
+ const auto& facet_field_it = facet_field_map.find(a_facet.field_name);
if(facet_field_it == facet_field_map.end()) {
return 0;
}
@@@ -167,15 -167,34 +169,32 @@@
size_t max_facets = is_wildcard_no_filter_query ? std::min((size_t)max_facet_count, counter_list.size()) :
std::min((size_t)2 * max_facet_count, counter_list.size());
- for(const auto& facet_count : counter_list) {
- //LOG(INFO) << "checking ids in facet_value " << facet_count.facet_value << " having total count "
- // << facet_count.count << ", is_wildcard_no_filter_query: " << is_wildcard_no_filter_query;
+ auto intersect_fn = [&] (std::list<facet_count_t>::const_iterator facet_count_it) {
uint32_t count = 0;
+ if(has_facet_query) {
+ bool found_search_token = false;
- auto facet_str = facet_count.facet_value;
++ 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) {
+ found_search_token = true;
- a_facet.fvalue_tokens[facet_count.facet_value] = fvalue_searched_tokens;
++ a_facet.fvalue_tokens[facet_count_it->facet_value] = fvalue_searched_tokens;
+ break;
+ }
+ }
+
+ if(!found_search_token) {
- continue;
++ return;
+ }
+ }
- if(is_wildcard_no_filter_query) {
- count = facet_count.count;
+ if (is_wildcard_no_filter_query) {
+ count = facet_count_it->count;
} else {
- auto ids = facet_index_map.at(facet_count.facet_value).seq_ids;
- if(!ids) {
- continue;
+ auto ids = facet_index_map.at(facet_count_it->facet_value).seq_ids;
+ if (!ids) {
+ return;
}
count = ids_t::intersect_count(ids, result_ids, result_ids_len);
}
diff --cc src/index.cpp
index 369cc75f,dd42727c..aa4b465b
--- a/src/index.cpp
+++ b/src/index.cpp
@@@ -1287,11 -1291,10 +1291,12 @@@ void Index::do_facets(std::vector<facet
a_facet.is_intersected = true;
std::map<std::string, uint32_t> facet_results;
+ std::string sort_order = a_facet.is_sort_by_alpha ? a_facet.sort_order : "";
- facet_index_v4->intersect(facet_field.name, result_ids,
+ facet_index_v4->intersect(a_facet, use_facet_query,
+ facet_infos[findex].fvalue_searched_tokens, result_ids,
- results_size, max_facet_count, facet_results, is_wildcard_no_filter_query);
+ results_size, max_facet_count, facet_results,
+ is_wildcard_no_filter_query, sort_order);
for(const auto& kv : facet_results) {
//range facet processing
@@@ -2747,7 -2741,7 +2748,7 @@@ Option<bool> Index::search(std::vector<
if (filter_result_iterator->is_valid &&
!filter_result_iterator->reference.empty()) {
// The doc_id must be valid otherwise it would've been filtered out upstream.
-- filter_result_iterator->skip_to(doc_id);
++ filter_result_iterator->skip_to(seq_id);
kv.reference_filter_results = std::move(filter_result_iterator->reference);
filter_result_iterator->reset();
}