From 1f68572179dd7ae060084953b45caa0173f2d93d Mon Sep 17 00:00:00 2001 From: krunal1313 Date: Wed, 19 Apr 2023 10:29:16 +0530 Subject: [PATCH] clean up --- include/index.h | 1 - src/facet_index.cpp | 2 +- src/index.cpp | 7 ++-- test/collection_faceting_test.cpp | 55 ------------------------------- 4 files changed, 4 insertions(+), 61 deletions(-) diff --git a/include/index.h b/include/index.h index b2b1f8c4..3e3a2cf9 100644 --- a/include/index.h +++ b/include/index.h @@ -190,7 +190,6 @@ struct search_args { struct offsets_facet_hashes_t { std::unordered_map> offsets; - //std::vector facet_hashes; }; struct index_record { diff --git a/src/facet_index.cpp b/src/facet_index.cpp index 3a8902da..cccb01ec 100644 --- a/src/facet_index.cpp +++ b/src/facet_index.cpp @@ -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; diff --git a/src/index.cpp b/src/index.cpp index cd7e7abd..67432d69 100644 --- a/src/index.cpp +++ b/src/index.cpp @@ -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 Index::search(std::vector& 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 : diff --git a/test/collection_faceting_test.cpp b/test/collection_faceting_test.cpp index a85f7def..8872759f 100644 --- a/test/collection_faceting_test.cpp +++ b/test/collection_faceting_test.cpp @@ -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 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_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 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().c_str()); - ASSERT_EQ(3, (int) results["facet_counts"][0]["counts"][0]["count"]); - - ASSERT_STREQ("silver", results["facet_counts"][0]["counts"][1]["value"].get().c_str()); - ASSERT_EQ(3, (int) results["facet_counts"][0]["counts"][1]["count"]); - - ASSERT_STREQ("bronze", results["facet_counts"][0]["counts"][2]["value"].get().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().c_str()); - ASSERT_EQ(1, (int) results["facet_counts"][0]["counts"][3]["count"]); -} \ No newline at end of file