diff --git a/include/facet_index.h b/include/facet_index.h index 33ad924e..0c681a3a 100644 --- a/include/facet_index.h +++ b/include/facet_index.h @@ -82,14 +82,16 @@ private: std::list counts; posting_list_t* seq_id_hashes = nullptr; spp::sparse_hash_map fhash_to_int64_map; + posting_list_t::iterator_t facet_index_it; bool has_value_index = true; bool has_hash_index = true; - facet_doc_ids_list_t() { + facet_doc_ids_list_t() : + seq_id_hashes(new posting_list_t(256)), + facet_index_it(seq_id_hashes->new_iterator()) { fvalue_seq_ids.clear(); counts.clear(); - seq_id_hashes = new posting_list_t(256); } facet_doc_ids_list_t(const facet_doc_ids_list_t& other) = delete; @@ -152,6 +154,8 @@ public: posting_list_t* get_facet_hash_index(const std::string& field_name); + posting_list_t::iterator_t* get_facet_index_it(const std::string& field_name); + //get fhash=>int64 map for stats const spp::sparse_hash_map& get_fhash_int64_map(const std::string& field_name); }; \ No newline at end of file diff --git a/src/facet_index.cpp b/src/facet_index.cpp index ff519fe5..7ab11481 100644 --- a/src/facet_index.cpp +++ b/src/facet_index.cpp @@ -344,6 +344,14 @@ posting_list_t* facet_index_t::get_facet_hash_index(const std::string &field_nam return nullptr; } +posting_list_t::iterator_t* facet_index_t::get_facet_index_it(const std::string& field_name) { + auto facet_index_it = facet_field_map.find(field_name); + if(facet_index_it != facet_field_map.end()) { + return &facet_index_it->second.facet_index_it; + } + return nullptr; +} + const spp::sparse_hash_map& facet_index_t::get_fhash_int64_map(const std::string& field_name) { const auto facet_field_map_it = facet_field_map.find(field_name); if(facet_field_map_it == facet_field_map.end()) { diff --git a/src/index.cpp b/src/index.cpp index 63d1ced1..0d6fe805 100644 --- a/src/index.cpp +++ b/src/index.cpp @@ -5894,23 +5894,24 @@ uint64_t Index::get_distinct_id(const std::vector& group_by_fields, continue; } - posting_list_t* facet_hash_index = facet_index_v4->get_facet_hash_index(field_name); std::vector facet_hashes; - posting_list_t::iterator_t facet_index_it = facet_hash_index->new_iterator(); - facet_index_it.skip_to(seq_id); + posting_list_t::iterator_t* facet_index_it = facet_index_v4->get_facet_index_it(field_name); + if(facet_index_it) { + facet_index_it->skip_to(seq_id); - if(facet_index_it.valid() && facet_index_it.id() == seq_id) { - posting_list_t::get_offsets(facet_index_it, facet_hashes); + if (facet_index_it->valid() && facet_index_it->id() == seq_id) { + posting_list_t::get_offsets(*facet_index_it, facet_hashes); - if(search_schema.at(field_name).is_array()) { - //LOG(INFO) << "combining hashes for facet array "; - for(size_t i = 0; i < facet_hashes.size(); i++) { - distinct_id = StringUtils::hash_combine(distinct_id, facet_hashes[i]); + if (search_schema.at(field_name).is_array()) { + //LOG(INFO) << "combining hashes for facet array "; + for (size_t i = 0; i < facet_hashes.size(); i++) { + distinct_id = StringUtils::hash_combine(distinct_id, facet_hashes[i]); + } + } else { + const auto &facet_hash = facet_hashes[0]; + //LOG(INFO) << "combining hashes for facet "; + distinct_id = StringUtils::hash_combine(distinct_id, facet_hash); } - } else { - const auto& facet_hash = facet_hashes[0]; - //LOG(INFO) << "combining hashes for facet "; - distinct_id = StringUtils::hash_combine(distinct_id, facet_hash); } } }