aboutsummaryrefslogtreecommitdiff
path: root/icing/index/iterator/doc-hit-info-iterator-section-restrict_test.cc
diff options
context:
space:
mode:
Diffstat (limited to 'icing/index/iterator/doc-hit-info-iterator-section-restrict_test.cc')
-rw-r--r--icing/index/iterator/doc-hit-info-iterator-section-restrict_test.cc247
1 files changed, 133 insertions, 114 deletions
diff --git a/icing/index/iterator/doc-hit-info-iterator-section-restrict_test.cc b/icing/index/iterator/doc-hit-info-iterator-section-restrict_test.cc
index c765e6d..ee65fe1 100644
--- a/icing/index/iterator/doc-hit-info-iterator-section-restrict_test.cc
+++ b/icing/index/iterator/doc-hit-info-iterator-section-restrict_test.cc
@@ -15,6 +15,7 @@
#include "icing/index/iterator/doc-hit-info-iterator-section-restrict.h"
#include <memory>
+#include <set>
#include <string>
#include <utility>
#include <vector>
@@ -101,13 +102,14 @@ class DocHitInfoIteratorSectionRestrictTest : public ::testing::Test {
ICING_ASSERT_OK_AND_ASSIGN(
DocumentStore::CreateResult create_result,
- DocumentStore::Create(&filesystem_, test_dir_, &fake_clock_,
- schema_store_.get(),
- /*force_recovery_and_revalidate_documents=*/false,
- /*namespace_id_fingerprint=*/false,
- PortableFileBackedProtoLog<
- DocumentWrapper>::kDeflateCompressionLevel,
- /*initialize_stats=*/nullptr));
+ DocumentStore::Create(
+ &filesystem_, test_dir_, &fake_clock_, schema_store_.get(),
+ /*force_recovery_and_revalidate_documents=*/false,
+ /*namespace_id_fingerprint=*/false, /*pre_mapping_fbv=*/false,
+ /*use_persistent_hash_map=*/false,
+ PortableFileBackedProtoLog<
+ DocumentWrapper>::kDeflateCompressionLevel,
+ /*initialize_stats=*/nullptr));
document_store_ = std::move(create_result.document_store);
}
@@ -149,48 +151,50 @@ TEST_F(DocHitInfoIteratorSectionRestrictTest,
auto original_iterator =
std::make_unique<DocHitInfoIteratorDummy>(doc_hit_infos, "hi");
- original_iterator->set_hit_intersect_section_ids_mask(
- original_section_id_mask);
+ original_iterator->set_hit_section_ids_mask(original_section_id_mask);
// Filtering for the indexed section name (which has a section id of 0) should
// get a result.
- DocHitInfoIteratorSectionRestrict section_restrict_iterator(
- std::move(original_iterator), document_store_.get(), schema_store_.get(),
- /*target_sections=*/{indexed_section_0},
- fake_clock_.GetSystemTimeMilliseconds());
+ std::unique_ptr<DocHitInfoIterator> section_restrict_iterator =
+ DocHitInfoIteratorSectionRestrict::ApplyRestrictions(
+ std::move(original_iterator), document_store_.get(),
+ schema_store_.get(),
+ /*target_sections=*/{indexed_section_0},
+ fake_clock_.GetSystemTimeMilliseconds());
std::vector<TermMatchInfo> matched_terms_stats;
- section_restrict_iterator.PopulateMatchedTermsStats(&matched_terms_stats);
+ section_restrict_iterator->PopulateMatchedTermsStats(&matched_terms_stats);
EXPECT_THAT(matched_terms_stats, IsEmpty());
- ICING_EXPECT_OK(section_restrict_iterator.Advance());
- EXPECT_THAT(section_restrict_iterator.doc_hit_info().document_id(),
+ ICING_EXPECT_OK(section_restrict_iterator->Advance());
+ EXPECT_THAT(section_restrict_iterator->doc_hit_info().document_id(),
Eq(document_id));
SectionIdMask expected_section_id_mask = 0b00000001; // hits in sections 0
- EXPECT_EQ(section_restrict_iterator.hit_intersect_section_ids_mask(),
+ EXPECT_EQ(section_restrict_iterator->doc_hit_info().hit_section_ids_mask(),
expected_section_id_mask);
- section_restrict_iterator.PopulateMatchedTermsStats(&matched_terms_stats);
+ section_restrict_iterator->PopulateMatchedTermsStats(&matched_terms_stats);
std::unordered_map<SectionId, Hit::TermFrequency>
expected_section_ids_tf_map = {{0, 1}};
EXPECT_THAT(matched_terms_stats, ElementsAre(EqualsTermMatchInfo(
"hi", expected_section_ids_tf_map)));
- EXPECT_FALSE(section_restrict_iterator.Advance().ok());
+ EXPECT_FALSE(section_restrict_iterator->Advance().ok());
}
TEST_F(DocHitInfoIteratorSectionRestrictTest, EmptyOriginalIterator) {
std::unique_ptr<DocHitInfoIterator> original_iterator_empty =
std::make_unique<DocHitInfoIteratorDummy>();
- DocHitInfoIteratorSectionRestrict filtered_iterator(
- std::move(original_iterator_empty), document_store_.get(),
- schema_store_.get(), /*target_sections=*/{},
- fake_clock_.GetSystemTimeMilliseconds());
+ std::unique_ptr<DocHitInfoIterator> filtered_iterator =
+ DocHitInfoIteratorSectionRestrict::ApplyRestrictions(
+ std::move(original_iterator_empty), document_store_.get(),
+ schema_store_.get(), /*target_sections=*/std::set<std::string>(),
+ fake_clock_.GetSystemTimeMilliseconds());
- EXPECT_THAT(GetDocumentIds(&filtered_iterator), IsEmpty());
+ EXPECT_THAT(GetDocumentIds(filtered_iterator.get()), IsEmpty());
std::vector<TermMatchInfo> matched_terms_stats;
- filtered_iterator.PopulateMatchedTermsStats(&matched_terms_stats);
+ filtered_iterator->PopulateMatchedTermsStats(&matched_terms_stats);
EXPECT_THAT(matched_terms_stats, IsEmpty());
}
@@ -209,12 +213,14 @@ TEST_F(DocHitInfoIteratorSectionRestrictTest, IncludesHitWithMatchingSection) {
std::make_unique<DocHitInfoIteratorDummy>(doc_hit_infos);
// Filtering for the indexed section name should get a result
- DocHitInfoIteratorSectionRestrict section_restrict_iterator(
- std::move(original_iterator), document_store_.get(), schema_store_.get(),
- /*target_sections=*/{indexed_section_0},
- fake_clock_.GetSystemTimeMilliseconds());
-
- EXPECT_THAT(GetDocumentIds(&section_restrict_iterator),
+ std::unique_ptr<DocHitInfoIterator> section_restrict_iterator =
+ DocHitInfoIteratorSectionRestrict::ApplyRestrictions(
+ std::move(original_iterator), document_store_.get(),
+ schema_store_.get(),
+ /*target_sections=*/{indexed_section_0},
+ fake_clock_.GetSystemTimeMilliseconds());
+
+ EXPECT_THAT(GetDocumentIds(section_restrict_iterator.get()),
ElementsAre(document_id));
}
@@ -235,18 +241,18 @@ TEST_F(DocHitInfoIteratorSectionRestrictTest,
std::make_unique<DocHitInfoIteratorDummy>(doc_hit_infos);
// Filter for both target_sections
- DocHitInfoIteratorSectionRestrict section_restrict_iterator(
- std::move(original_iterator), document_store_.get(), schema_store_.get(),
- /*target_sections=*/{indexed_section_0, indexed_section_1},
- fake_clock_.GetSystemTimeMilliseconds());
-
- ICING_ASSERT_OK(section_restrict_iterator.Advance());
+ std::unique_ptr<DocHitInfoIterator> section_restrict_iterator =
+ DocHitInfoIteratorSectionRestrict::ApplyRestrictions(
+ std::move(original_iterator), document_store_.get(),
+ schema_store_.get(),
+ /*target_sections=*/{indexed_section_0, indexed_section_1},
+ fake_clock_.GetSystemTimeMilliseconds());
+
+ ICING_ASSERT_OK(section_restrict_iterator->Advance());
std::vector<SectionId> expected_section_ids = {kIndexedSectionId0,
kIndexedSectionId1};
- EXPECT_THAT(section_restrict_iterator.doc_hit_info(),
+ EXPECT_THAT(section_restrict_iterator->doc_hit_info(),
EqualsDocHitInfo(document_id, expected_section_ids));
- EXPECT_THAT(section_restrict_iterator.hit_intersect_section_ids_mask(),
- Eq(section_id_mask));
}
TEST_F(DocHitInfoIteratorSectionRestrictTest,
@@ -266,17 +272,17 @@ TEST_F(DocHitInfoIteratorSectionRestrictTest,
std::make_unique<DocHitInfoIteratorDummy>(doc_hit_infos);
// Filter for both target_sections
- DocHitInfoIteratorSectionRestrict section_restrict_iterator(
- std::move(original_iterator), document_store_.get(), schema_store_.get(),
- /*target_sections=*/{indexed_section_1},
- fake_clock_.GetSystemTimeMilliseconds());
-
- ICING_ASSERT_OK(section_restrict_iterator.Advance());
+ std::unique_ptr<DocHitInfoIterator> section_restrict_iterator =
+ DocHitInfoIteratorSectionRestrict::ApplyRestrictions(
+ std::move(original_iterator), document_store_.get(),
+ schema_store_.get(),
+ /*target_sections=*/{indexed_section_1},
+ fake_clock_.GetSystemTimeMilliseconds());
+
+ ICING_ASSERT_OK(section_restrict_iterator->Advance());
std::vector<SectionId> expected_section_ids = {kIndexedSectionId1};
- EXPECT_THAT(section_restrict_iterator.doc_hit_info(),
+ EXPECT_THAT(section_restrict_iterator->doc_hit_info(),
EqualsDocHitInfo(document_id, expected_section_ids));
- EXPECT_THAT(section_restrict_iterator.hit_intersect_section_ids_mask(),
- Eq(1U << kIndexedSectionId1));
}
TEST_F(DocHitInfoIteratorSectionRestrictTest,
@@ -295,17 +301,17 @@ TEST_F(DocHitInfoIteratorSectionRestrictTest,
std::make_unique<DocHitInfoIteratorDummy>(doc_hit_infos);
// Filter for both target_sections
- DocHitInfoIteratorSectionRestrict section_restrict_iterator(
- std::move(original_iterator), document_store_.get(), schema_store_.get(),
- /*target_sections=*/{indexed_section_0, indexed_section_1},
- fake_clock_.GetSystemTimeMilliseconds());
-
- ICING_ASSERT_OK(section_restrict_iterator.Advance());
+ std::unique_ptr<DocHitInfoIterator> section_restrict_iterator =
+ DocHitInfoIteratorSectionRestrict::ApplyRestrictions(
+ std::move(original_iterator), document_store_.get(),
+ schema_store_.get(),
+ /*target_sections=*/{indexed_section_0, indexed_section_1},
+ fake_clock_.GetSystemTimeMilliseconds());
+
+ ICING_ASSERT_OK(section_restrict_iterator->Advance());
std::vector<SectionId> expected_section_ids = {kIndexedSectionId1};
- EXPECT_THAT(section_restrict_iterator.doc_hit_info(),
+ EXPECT_THAT(section_restrict_iterator->doc_hit_info(),
EqualsDocHitInfo(document_id, expected_section_ids));
- EXPECT_THAT(section_restrict_iterator.hit_intersect_section_ids_mask(),
- Eq(1U << kIndexedSectionId1));
}
TEST_F(DocHitInfoIteratorSectionRestrictTest, NoMatchingDocumentFilterData) {
@@ -316,13 +322,15 @@ TEST_F(DocHitInfoIteratorSectionRestrictTest, NoMatchingDocumentFilterData) {
std::make_unique<DocHitInfoIteratorDummy>(doc_hit_infos);
// Filtering for the indexed section name should get a result
- DocHitInfoIteratorSectionRestrict section_restrict_iterator(
- std::move(original_iterator), document_store_.get(), schema_store_.get(),
- /*target_sections=*/{""}, fake_clock_.GetSystemTimeMilliseconds());
+ std::unique_ptr<DocHitInfoIterator> section_restrict_iterator =
+ DocHitInfoIteratorSectionRestrict::ApplyRestrictions(
+ std::move(original_iterator), document_store_.get(),
+ schema_store_.get(),
+ /*target_sections=*/{""}, fake_clock_.GetSystemTimeMilliseconds());
- EXPECT_THAT(GetDocumentIds(&section_restrict_iterator), IsEmpty());
+ EXPECT_THAT(GetDocumentIds(section_restrict_iterator.get()), IsEmpty());
std::vector<TermMatchInfo> matched_terms_stats;
- section_restrict_iterator.PopulateMatchedTermsStats(&matched_terms_stats);
+ section_restrict_iterator->PopulateMatchedTermsStats(&matched_terms_stats);
EXPECT_THAT(matched_terms_stats, IsEmpty());
}
@@ -342,14 +350,16 @@ TEST_F(DocHitInfoIteratorSectionRestrictTest,
std::make_unique<DocHitInfoIteratorDummy>(doc_hit_infos);
// Filtering for the indexed section name should get a result
- DocHitInfoIteratorSectionRestrict section_restrict_iterator(
- std::move(original_iterator), document_store_.get(), schema_store_.get(),
- /*target_sections=*/{"some_section_name"},
- fake_clock_.GetSystemTimeMilliseconds());
-
- EXPECT_THAT(GetDocumentIds(&section_restrict_iterator), IsEmpty());
+ std::unique_ptr<DocHitInfoIterator> section_restrict_iterator =
+ DocHitInfoIteratorSectionRestrict::ApplyRestrictions(
+ std::move(original_iterator), document_store_.get(),
+ schema_store_.get(),
+ /*target_sections=*/{"some_section_name"},
+ fake_clock_.GetSystemTimeMilliseconds());
+
+ EXPECT_THAT(GetDocumentIds(section_restrict_iterator.get()), IsEmpty());
std::vector<TermMatchInfo> matched_terms_stats;
- section_restrict_iterator.PopulateMatchedTermsStats(&matched_terms_stats);
+ section_restrict_iterator->PopulateMatchedTermsStats(&matched_terms_stats);
EXPECT_THAT(matched_terms_stats, IsEmpty());
}
@@ -367,14 +377,16 @@ TEST_F(DocHitInfoIteratorSectionRestrictTest,
std::unique_ptr<DocHitInfoIterator> original_iterator =
std::make_unique<DocHitInfoIteratorDummy>(doc_hit_infos);
- DocHitInfoIteratorSectionRestrict section_restrict_iterator(
- std::move(original_iterator), document_store_.get(), schema_store_.get(),
- /*target_sections=*/{indexed_section_0},
- fake_clock_.GetSystemTimeMilliseconds());
+ std::unique_ptr<DocHitInfoIterator> section_restrict_iterator =
+ DocHitInfoIteratorSectionRestrict::ApplyRestrictions(
+ std::move(original_iterator), document_store_.get(),
+ schema_store_.get(),
+ /*target_sections=*/{indexed_section_0},
+ fake_clock_.GetSystemTimeMilliseconds());
- EXPECT_THAT(GetDocumentIds(&section_restrict_iterator), IsEmpty());
+ EXPECT_THAT(GetDocumentIds(section_restrict_iterator.get()), IsEmpty());
std::vector<TermMatchInfo> matched_terms_stats;
- section_restrict_iterator.PopulateMatchedTermsStats(&matched_terms_stats);
+ section_restrict_iterator->PopulateMatchedTermsStats(&matched_terms_stats);
EXPECT_THAT(matched_terms_stats, IsEmpty());
}
@@ -390,42 +402,42 @@ TEST_F(DocHitInfoIteratorSectionRestrictTest,
// Create a hit that exists in a different section, so it shouldn't match any
// section filters
std::vector<DocHitInfo> doc_hit_infos = {
- DocHitInfo(document_id, kSectionIdMaskNone << not_matching_section_id)};
+ DocHitInfo(document_id, UINT64_C(1) << not_matching_section_id)};
std::unique_ptr<DocHitInfoIterator> original_iterator =
std::make_unique<DocHitInfoIteratorDummy>(doc_hit_infos);
- DocHitInfoIteratorSectionRestrict section_restrict_iterator(
- std::move(original_iterator), document_store_.get(), schema_store_.get(),
- /*target_sections=*/{indexed_section_0},
- fake_clock_.GetSystemTimeMilliseconds());
+ std::unique_ptr<DocHitInfoIterator> section_restrict_iterator =
+ DocHitInfoIteratorSectionRestrict::ApplyRestrictions(
+ std::move(original_iterator), document_store_.get(),
+ schema_store_.get(),
+ /*target_sections=*/{indexed_section_0},
+ fake_clock_.GetSystemTimeMilliseconds());
- EXPECT_THAT(GetDocumentIds(&section_restrict_iterator), IsEmpty());
+ EXPECT_THAT(GetDocumentIds(section_restrict_iterator.get()), IsEmpty());
std::vector<TermMatchInfo> matched_terms_stats;
- section_restrict_iterator.PopulateMatchedTermsStats(&matched_terms_stats);
+ section_restrict_iterator->PopulateMatchedTermsStats(&matched_terms_stats);
EXPECT_THAT(matched_terms_stats, IsEmpty());
}
-TEST_F(DocHitInfoIteratorSectionRestrictTest, GetNumBlocksInspected) {
+TEST_F(DocHitInfoIteratorSectionRestrictTest, GetCallStats) {
+ DocHitInfoIterator::CallStats original_call_stats(
+ /*num_leaf_advance_calls_lite_index_in=*/2,
+ /*num_leaf_advance_calls_main_index_in=*/5,
+ /*num_leaf_advance_calls_integer_index_in=*/3,
+ /*num_leaf_advance_calls_no_index_in=*/1,
+ /*num_blocks_inspected_in=*/4); // arbitrary value
auto original_iterator = std::make_unique<DocHitInfoIteratorDummy>();
- original_iterator->SetNumBlocksInspected(5);
+ original_iterator->SetCallStats(original_call_stats);
- DocHitInfoIteratorSectionRestrict section_restrict_iterator(
- std::move(original_iterator), document_store_.get(), schema_store_.get(),
- /*target_sections=*/{""}, fake_clock_.GetSystemTimeMilliseconds());
+ std::unique_ptr<DocHitInfoIterator> section_restrict_iterator =
+ DocHitInfoIteratorSectionRestrict::ApplyRestrictions(
+ std::move(original_iterator), document_store_.get(),
+ schema_store_.get(),
+ /*target_sections=*/{""}, fake_clock_.GetSystemTimeMilliseconds());
- EXPECT_THAT(section_restrict_iterator.GetNumBlocksInspected(), Eq(5));
-}
-
-TEST_F(DocHitInfoIteratorSectionRestrictTest, GetNumLeafAdvanceCalls) {
- auto original_iterator = std::make_unique<DocHitInfoIteratorDummy>();
- original_iterator->SetNumLeafAdvanceCalls(6);
-
- DocHitInfoIteratorSectionRestrict section_restrict_iterator(
- std::move(original_iterator), document_store_.get(), schema_store_.get(),
- /*target_sections=*/{""}, fake_clock_.GetSystemTimeMilliseconds());
-
- EXPECT_THAT(section_restrict_iterator.GetNumLeafAdvanceCalls(), Eq(6));
+ EXPECT_THAT(section_restrict_iterator->GetCallStats(),
+ Eq(original_call_stats));
}
TEST_F(DocHitInfoIteratorSectionRestrictTest,
@@ -443,12 +455,10 @@ TEST_F(DocHitInfoIteratorSectionRestrictTest,
// Anything that's not 0, which is the indexed property
SectionId not_matching_section_id = 2;
- // Build an interator tree like:
- // Restrict
- // |
+ // Build an iterator tree like:
// AND
// / \
- // [1, 1],[2, 2] [3, 2]
+ // [1, 1],[2, 2] [3, 2]
std::vector<DocHitInfo> left_infos = {
DocHitInfo(document_id1, 1U << matching_section_id),
DocHitInfo(document_id2, 1U << not_matching_section_id)};
@@ -459,14 +469,21 @@ TEST_F(DocHitInfoIteratorSectionRestrictTest,
std::make_unique<DocHitInfoIteratorDummy>(left_infos);
std::unique_ptr<DocHitInfoIterator> right_iterator =
std::make_unique<DocHitInfoIteratorDummy>(right_infos, "term", 10);
-
std::unique_ptr<DocHitInfoIterator> original_iterator =
std::make_unique<DocHitInfoIteratorAnd>(std::move(left_iterator),
std::move(right_iterator));
- DocHitInfoIteratorSectionRestrict section_restrict_iterator(
- std::move(original_iterator), document_store_.get(), schema_store_.get(),
- {indexed_section_0}, fake_clock_.GetSystemTimeMilliseconds());
+ // After applying section restriction:
+ // AND
+ // / \
+ // Restrict Restrict
+ // | |
+ // [1, 1],[2, 2] [3, 2]
+ std::unique_ptr<DocHitInfoIterator> section_restrict_iterator =
+ DocHitInfoIteratorSectionRestrict::ApplyRestrictions(
+ std::move(original_iterator), document_store_.get(),
+ schema_store_.get(), {indexed_section_0},
+ fake_clock_.GetSystemTimeMilliseconds());
// The trimmed tree.
// Restrict
@@ -474,12 +491,12 @@ TEST_F(DocHitInfoIteratorSectionRestrictTest,
// [1, 1],[2, 2]
ICING_ASSERT_OK_AND_ASSIGN(
DocHitInfoIterator::TrimmedNode node,
- std::move(section_restrict_iterator).TrimRightMostNode());
+ std::move(*section_restrict_iterator).TrimRightMostNode());
EXPECT_THAT(GetDocumentIds(node.iterator_.get()), ElementsAre(document_id1));
EXPECT_THAT(node.term_, Eq("term"));
EXPECT_THAT(node.term_start_index_, Eq(10));
- EXPECT_THAT(node.target_section_, Eq(""));
+ EXPECT_THAT(node.target_section_, Eq(indexed_section_0));
}
TEST_F(DocHitInfoIteratorSectionRestrictTest, TrimSectionRestrictIterator) {
@@ -504,14 +521,16 @@ TEST_F(DocHitInfoIteratorSectionRestrictTest, TrimSectionRestrictIterator) {
std::unique_ptr<DocHitInfoIterator> original_iterator =
std::make_unique<DocHitInfoIteratorDummy>(doc_infos, "term", 10);
- DocHitInfoIteratorSectionRestrict section_restrict_iterator(
- std::move(original_iterator), document_store_.get(), schema_store_.get(),
- {indexed_section_0}, fake_clock_.GetSystemTimeMilliseconds());
+ std::unique_ptr<DocHitInfoIterator> section_restrict_iterator =
+ DocHitInfoIteratorSectionRestrict::ApplyRestrictions(
+ std::move(original_iterator), document_store_.get(),
+ schema_store_.get(), {indexed_section_0},
+ fake_clock_.GetSystemTimeMilliseconds());
// The trimmed tree has null iterator but has target section.
ICING_ASSERT_OK_AND_ASSIGN(
DocHitInfoIterator::TrimmedNode node,
- std::move(section_restrict_iterator).TrimRightMostNode());
+ std::move(*section_restrict_iterator).TrimRightMostNode());
EXPECT_THAT(node.iterator_, testing::IsNull());
EXPECT_THAT(node.term_, Eq("term"));