This commit is contained in:
krunal1313 2023-04-19 10:29:16 +05:30
parent c6a2c7946b
commit 1f68572179
4 changed files with 4 additions and 61 deletions

View File

@ -190,7 +190,6 @@ struct search_args {
struct offsets_facet_hashes_t {
std::unordered_map<std::string, std::vector<uint32_t>> offsets;
//std::vector<uint32_t> facet_hashes;
};
struct index_record {

View File

@ -15,7 +15,7 @@ uint32_t facet_index_t::insert(const std::string& field, const std::string& valu
fis.index = index;
facet_index_map.emplace(sv, fis);
}else {
auto ids = facet_index_map[sv].id_list_ptr;
auto ids = it->id_list_ptr;
if (!ids_t::contains(ids, id)) {
ids_t::upsert(ids, id);
facet_index_map[sv].id_list_ptr = ids;

View File

@ -320,15 +320,15 @@ void Index::compute_token_offsets_facets(index_record& record,
if(the_field.type == field_types::STRING) {
tokenize_string_with_facets(document[field_name], is_facet, the_field,
local_symbols_to_index, local_token_separators,
offset_facet_hashes.offsets/*, offset_facet_hashes.facet_hashes*/);
offset_facet_hashes.offsets);
} else {
tokenize_string_array_with_facets(document[field_name], is_facet, the_field,
local_symbols_to_index, local_token_separators,
offset_facet_hashes.offsets/*, offset_facet_hashes.facet_hashes*/);
offset_facet_hashes.offsets);
}
}
if(!offset_facet_hashes.offsets.empty() /*|| !offset_facet_hashes.facet_hashes.empty()*/) {
if(!offset_facet_hashes.offsets.empty()) {
record.field_index.emplace(field_name, std::move(offset_facet_hashes));
}
}
@ -3234,7 +3234,6 @@ Option<bool> Index::search(std::vector<query_tokens_t>& field_query_tokens, cons
bool estimate_facets = (facet_sample_percent < 100 && all_result_ids_len > facet_sample_threshold);
if(!facets.empty()) {
//const size_t num_threads = std::min(concurrency, all_result_ids_len);
const size_t num_threads = 1;
const size_t window_size = (num_threads == 0) ? 0 :

View File

@ -1574,58 +1574,3 @@ TEST_F(CollectionFacetingTest, FacetOnArrayFieldWithSpecialChars) {
}
}
}
TEST_F(CollectionFacetingTest, FacetIndexRefactor) {
Collection *coll_array_fields;
std::ifstream infile(std::string(ROOT_DIR)+"test/numeric_array_documents.jsonl");
std::vector<field> fields = {field("name", field_types::STRING, false),
field("name_facet", field_types::STRING, true),
field("age", field_types::INT32, true),
field("years", field_types::INT32_ARRAY, true),
field("rating", field_types::FLOAT, true),
field("timestamps", field_types::INT64_ARRAY, true),
field("tags", field_types::STRING_ARRAY, true)};
std::vector<sort_by> sort_fields = { sort_by("age", "DESC") };
coll_array_fields = collectionManager.get_collection("coll_array_fields").get();
if(coll_array_fields == nullptr) {
coll_array_fields = collectionManager.create_collection("coll_array_fields", 4, fields, "age").get();
}
std::string json_line;
while (std::getline(infile, json_line)) {
nlohmann::json document = nlohmann::json::parse(json_line);
document["name_facet"] = document["name"];
const std::string & patched_json_line = document.dump();
coll_array_fields->add(patched_json_line);
}
infile.close();
query_fields = {"name"};
std::vector<std::string> facets = {"tags"};
// single facet with no filters
nlohmann::json results = coll_array_fields->search("Jeremy", query_fields, "", facets, sort_fields, {0}, 10, 1, FREQUENCY, {false}).get();
ASSERT_EQ(5, results["hits"].size());
ASSERT_EQ(1, results["facet_counts"].size());
ASSERT_EQ(4, results["facet_counts"][0].size());
ASSERT_EQ(4, results["facet_counts"][0]["counts"].size());
ASSERT_EQ("tags", results["facet_counts"][0]["field_name"]);
ASSERT_STREQ("gold", results["facet_counts"][0]["counts"][0]["value"].get<std::string>().c_str());
ASSERT_EQ(3, (int) results["facet_counts"][0]["counts"][0]["count"]);
ASSERT_STREQ("silver", results["facet_counts"][0]["counts"][1]["value"].get<std::string>().c_str());
ASSERT_EQ(3, (int) results["facet_counts"][0]["counts"][1]["count"]);
ASSERT_STREQ("bronze", results["facet_counts"][0]["counts"][2]["value"].get<std::string>().c_str());
ASSERT_EQ(2, (int) results["facet_counts"][0]["counts"][2]["count"]);
ASSERT_STREQ("FINE PLATINUM", results["facet_counts"][0]["counts"][3]["value"].get<std::string>().c_str());
ASSERT_EQ(1, (int) results["facet_counts"][0]["counts"][3]["count"]);
}