aboutsummaryrefslogtreecommitdiff
path: root/icing/index/iterator/doc-hit-info-iterator-or_test.cc
diff options
context:
space:
mode:
authorAlex Saveliev <alexsav@google.com>2023-01-06 14:46:36 -0800
committerAlex Saveliev <alexsav@google.com>2023-01-06 14:46:36 -0800
commitec29b14d5a908748d6e0699df7c85842a95a7b3c (patch)
tree8e98a3ee5797ad466fc467a82de688a658566640 /icing/index/iterator/doc-hit-info-iterator-or_test.cc
parent44f12ef84cba5a719d101c3aec9f4962352098d9 (diff)
downloadicing-ec29b14d5a908748d6e0699df7c85842a95a7b3c.tar.gz
Update icing from upstream
Descriptions: ====================================================================== Apply aggregation score to join result and create JoinProcessorTest ====================================================================== Create AggregationScorerTest ====================================================================== Add an EqualsTermMatchInfo matcher to simplify tests that interact with this struct. ====================================================================== Refactor the QueryVisitor to return QueryResults. ====================================================================== Simplify ScoreExpression to ConstantScoreExpression if its evaluation does not depend on a document ====================================================================== Use rvalue and std::move for DocumentStore methods ====================================================================== Downgrade log messages for NOT_FOUND errors in Delete calls. ====================================================================== [NumericSearch][Storage][3.1/x] Add metadata file declaration (Crcs, Info) for IntegerIndexStorage ====================================================================== [NumericSearch][Storage][3.0/x] Declare class IntegerIndexStorage ====================================================================== Cleanup Import from //tools/build_defs/objc ====================================================================== Cleanup LSC: Remove `portable_proto_library()` targets ====================================================================== Bug: 256022027 Bug: 208654892 Bug: 261474063 Bug: 246628980 Bug: 249829533 Bug: 263373214 Change-Id: Ib5ca7efffd575254e14a14d54a45f4efd1e8d6c9
Diffstat (limited to 'icing/index/iterator/doc-hit-info-iterator-or_test.cc')
-rw-r--r--icing/index/iterator/doc-hit-info-iterator-or_test.cc145
1 files changed, 54 insertions, 91 deletions
diff --git a/icing/index/iterator/doc-hit-info-iterator-or_test.cc b/icing/index/iterator/doc-hit-info-iterator-or_test.cc
index 6e6872c..f487801 100644
--- a/icing/index/iterator/doc-hit-info-iterator-or_test.cc
+++ b/icing/index/iterator/doc-hit-info-iterator-or_test.cc
@@ -19,7 +19,6 @@
#include "gmock/gmock.h"
#include "gtest/gtest.h"
-#include "icing/index/iterator/doc-hit-info-iterator-and.h"
#include "icing/index/iterator/doc-hit-info-iterator-test-util.h"
#include "icing/index/iterator/doc-hit-info-iterator.h"
#include "icing/schema/section.h"
@@ -32,10 +31,8 @@ namespace lib {
namespace {
using ::testing::ElementsAre;
-using ::testing::ElementsAreArray;
using ::testing::Eq;
using ::testing::IsEmpty;
-using ::testing::SizeIs;
TEST(CreateAndIteratorTest, Or) {
// Basic test that we can create a working Or iterator. Further testing of
@@ -182,22 +179,21 @@ TEST(DocHitInfoIteratorOrTest, PopulateMatchedTermsStats) {
{
// Arbitrary section ids for the documents in the DocHitInfoIterators.
// Created to test correct section_id_mask behavior.
- SectionIdMask section_id_mask1 = 0b01010101; // hits in sections 0, 2, 4, 6
- std::array<Hit::TermFrequency, kTotalNumSections> term_frequencies1{
- 1, 0, 2, 0, 3, 0, 4, 0, 0, 0, 0, 0, 0, 0, 0, 0};
- SectionIdMask section_id_mask2 = 0b00000110; // hits in sections 1, 2
- std::array<Hit::TermFrequency, kTotalNumSections> term_frequencies2{
- 0, 2, 6, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0};
-
DocHitInfoTermFrequencyPair doc_hit_info1 = DocHitInfo(4);
doc_hit_info1.UpdateSection(/*section_id=*/0, /*hit_term_frequency=*/1);
doc_hit_info1.UpdateSection(/*section_id=*/2, /*hit_term_frequency=*/2);
doc_hit_info1.UpdateSection(/*section_id=*/4, /*hit_term_frequency=*/3);
doc_hit_info1.UpdateSection(/*section_id=*/6, /*hit_term_frequency=*/4);
+ SectionIdMask section_id_mask1 = 0b01010101; // hits in sections 0, 2, 4, 6
+ std::unordered_map<SectionId, Hit::TermFrequency>
+ expected_section_ids_tf_map1 = {{0, 1}, {2, 2}, {4, 3}, {6, 4}};
DocHitInfoTermFrequencyPair doc_hit_info2 = DocHitInfo(4);
doc_hit_info2.UpdateSection(/*section_id=*/1, /*hit_term_frequency=*/2);
doc_hit_info2.UpdateSection(/*section_id=*/2, /*hit_term_frequency=*/6);
+ SectionIdMask section_id_mask2 = 0b00000110; // hits in sections 1, 2
+ std::unordered_map<SectionId, Hit::TermFrequency>
+ expected_section_ids_tf_map2 = {{1, 2}, {2, 6}};
std::vector<DocHitInfoTermFrequencyPair> first_vector = {doc_hit_info1};
std::vector<DocHitInfoTermFrequencyPair> second_vector = {doc_hit_info2};
@@ -219,28 +215,23 @@ TEST(DocHitInfoIteratorOrTest, PopulateMatchedTermsStats) {
EXPECT_THAT(or_iter.doc_hit_info().document_id(), Eq(4));
or_iter.PopulateMatchedTermsStats(&matched_terms_stats);
- ASSERT_THAT(matched_terms_stats, SizeIs(2)); // 2 terms
- EXPECT_EQ(matched_terms_stats.at(0).term, "hi");
- EXPECT_EQ(matched_terms_stats.at(1).term, "hello");
- EXPECT_THAT(matched_terms_stats.at(0).term_frequencies,
- ElementsAreArray(term_frequencies1));
- EXPECT_EQ(matched_terms_stats.at(0).section_ids_mask, section_id_mask1);
- EXPECT_THAT(matched_terms_stats.at(1).term_frequencies,
- ElementsAreArray(term_frequencies2));
- EXPECT_EQ(matched_terms_stats.at(1).section_ids_mask, section_id_mask2);
+ EXPECT_THAT(
+ matched_terms_stats,
+ ElementsAre(
+ EqualsTermMatchInfo("hi", expected_section_ids_tf_map1),
+ EqualsTermMatchInfo("hello", expected_section_ids_tf_map2)));
EXPECT_FALSE(or_iter.Advance().ok());
}
{
// Arbitrary section ids for the documents in the DocHitInfoIterators.
// Created to test correct section_id_mask behavior.
- SectionIdMask section_id_mask1 = 0b00000101; // hits in sections 0, 2
- std::array<Hit::TermFrequency, kTotalNumSections> term_frequencies1{
- 1, 0, 2, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0};
-
DocHitInfoTermFrequencyPair doc_hit_info1 = DocHitInfo(4);
doc_hit_info1.UpdateSection(/*section_id=*/0, /*hit_term_frequency=*/1);
doc_hit_info1.UpdateSection(/*section_id=*/2, /*hit_term_frequency=*/2);
+ SectionIdMask section_id_mask1 = 0b00000101; // hits in sections 0, 2
+ std::unordered_map<SectionId, Hit::TermFrequency>
+ expected_section_ids_tf_map1 = {{0, 1}, {2, 2}};
std::vector<DocHitInfoTermFrequencyPair> first_vector = {doc_hit_info1};
std::vector<DocHitInfoTermFrequencyPair> second_vector = {doc_hit_info1};
@@ -262,33 +253,28 @@ TEST(DocHitInfoIteratorOrTest, PopulateMatchedTermsStats) {
EXPECT_THAT(or_iter.doc_hit_info().document_id(), Eq(4));
or_iter.PopulateMatchedTermsStats(&matched_terms_stats);
- ASSERT_THAT(matched_terms_stats, SizeIs(1)); // 1 term
- EXPECT_EQ(matched_terms_stats.at(0).term, "hi");
- EXPECT_THAT(matched_terms_stats.at(0).term_frequencies,
- ElementsAreArray(term_frequencies1));
- EXPECT_EQ(matched_terms_stats.at(0).section_ids_mask, section_id_mask1);
-
+ EXPECT_THAT(matched_terms_stats, ElementsAre(EqualsTermMatchInfo(
+ "hi", expected_section_ids_tf_map1)));
EXPECT_FALSE(or_iter.Advance().ok());
}
{
// Arbitrary section ids for the documents in the DocHitInfoIterators.
// Created to test correct section_id_mask behavior.
- SectionIdMask section_id_mask1 = 0b01010101; // hits in sections 0, 2, 4, 6
- std::array<Hit::TermFrequency, kTotalNumSections> term_frequencies1{
- 1, 0, 2, 0, 3, 0, 4, 0, 0, 0, 0, 0, 0, 0, 0, 0};
- SectionIdMask section_id_mask2 = 0b00000110; // hits in sections 1, 2
- std::array<Hit::TermFrequency, kTotalNumSections> term_frequencies2{
- 0, 2, 6, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0};
-
DocHitInfoTermFrequencyPair doc_hit_info1 = DocHitInfo(4);
doc_hit_info1.UpdateSection(/*section_id=*/0, /*hit_term_frequency=*/1);
doc_hit_info1.UpdateSection(/*section_id=*/2, /*hit_term_frequency=*/2);
doc_hit_info1.UpdateSection(/*section_id=*/4, /*hit_term_frequency=*/3);
doc_hit_info1.UpdateSection(/*section_id=*/6, /*hit_term_frequency=*/4);
+ SectionIdMask section_id_mask1 = 0b01010101; // hits in sections 0, 2, 4, 6
+ std::unordered_map<SectionId, Hit::TermFrequency>
+ expected_section_ids_tf_map1 = {{0, 1}, {2, 2}, {4, 3}, {6, 4}};
DocHitInfoTermFrequencyPair doc_hit_info2 = DocHitInfo(5);
doc_hit_info2.UpdateSection(/*section_id=*/1, /*hit_term_frequency=*/2);
doc_hit_info2.UpdateSection(/*section_id=*/2, /*hit_term_frequency=*/6);
+ SectionIdMask section_id_mask2 = 0b00000110; // hits in sections 1, 2
+ std::unordered_map<SectionId, Hit::TermFrequency>
+ expected_section_ids_tf_map2 = {{1, 2}, {2, 6}};
std::vector<DocHitInfoTermFrequencyPair> first_vector = {doc_hit_info1};
std::vector<DocHitInfoTermFrequencyPair> second_vector = {doc_hit_info2};
@@ -310,22 +296,17 @@ TEST(DocHitInfoIteratorOrTest, PopulateMatchedTermsStats) {
EXPECT_THAT(or_iter.doc_hit_info().document_id(), Eq(5));
or_iter.PopulateMatchedTermsStats(&matched_terms_stats);
- ASSERT_THAT(matched_terms_stats, SizeIs(1)); // 1 term
- EXPECT_EQ(matched_terms_stats.at(0).term, "hello");
- EXPECT_THAT(matched_terms_stats.at(0).term_frequencies,
- ElementsAreArray(term_frequencies2));
- EXPECT_EQ(matched_terms_stats.at(0).section_ids_mask, section_id_mask2);
+ EXPECT_THAT(matched_terms_stats,
+ ElementsAre(EqualsTermMatchInfo("hello",
+ expected_section_ids_tf_map2)));
ICING_EXPECT_OK(or_iter.Advance());
EXPECT_THAT(or_iter.doc_hit_info().document_id(), Eq(4));
matched_terms_stats.clear();
or_iter.PopulateMatchedTermsStats(&matched_terms_stats);
- ASSERT_THAT(matched_terms_stats, SizeIs(1)); // 1 term
- EXPECT_EQ(matched_terms_stats.at(0).term, "hi");
- EXPECT_THAT(matched_terms_stats.at(0).term_frequencies,
- ElementsAreArray(term_frequencies1));
- EXPECT_EQ(matched_terms_stats.at(0).section_ids_mask, section_id_mask1);
+ EXPECT_THAT(matched_terms_stats, ElementsAre(EqualsTermMatchInfo(
+ "hi", expected_section_ids_tf_map1)));
EXPECT_FALSE(or_iter.Advance().ok());
}
@@ -476,50 +457,44 @@ TEST(DocHitInfoIteratorOrNaryTest, PopulateMatchedTermsStats) {
// Arbitrary section ids/term frequencies for the documents in the
// DocHitInfoIterators.
// For term "hi", document 10 and 8
- SectionIdMask section_id_mask1_hi = 0b01000101; // hits in sections 0, 2, 6
- std::array<Hit::TermFrequency, kTotalNumSections> term_frequencies1_hi{
- 1, 0, 2, 0, 0, 0, 4, 0, 0, 0, 0, 0, 0, 0, 0, 0};
DocHitInfoTermFrequencyPair doc_hit_info1_hi = DocHitInfo(10);
doc_hit_info1_hi.UpdateSection(/*section_id=*/0, /*hit_term_frequency=*/1);
doc_hit_info1_hi.UpdateSection(/*section_id=*/2, /*hit_term_frequency=*/2);
doc_hit_info1_hi.UpdateSection(/*section_id=*/6, /*hit_term_frequency=*/4);
+ std::unordered_map<SectionId, Hit::TermFrequency>
+ expected_section_ids_tf_map1_hi = {{0, 1}, {2, 2}, {6, 4}};
- SectionIdMask section_id_mask2_hi = 0b00000110; // hits in sections 1, 2
- std::array<Hit::TermFrequency, kTotalNumSections> term_frequencies2_hi{
- 0, 2, 6, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0};
DocHitInfoTermFrequencyPair doc_hit_info2_hi = DocHitInfo(8);
doc_hit_info2_hi.UpdateSection(/*section_id=*/1, /*hit_term_frequency=*/2);
doc_hit_info2_hi.UpdateSection(/*section_id=*/2, /*hit_term_frequency=*/6);
+ std::unordered_map<SectionId, Hit::TermFrequency>
+ expected_section_ids_tf_map2_hi = {{1, 2}, {2, 6}};
// For term "hello", document 10 and 9
- SectionIdMask section_id_mask1_hello = 0b00001001; // hits in sections 0, 3
- std::array<Hit::TermFrequency, kTotalNumSections> term_frequencies1_hello{
- 2, 0, 0, 3, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0};
DocHitInfoTermFrequencyPair doc_hit_info1_hello = DocHitInfo(10);
doc_hit_info1_hello.UpdateSection(/*section_id=*/0, /*hit_term_frequency=*/2);
doc_hit_info1_hello.UpdateSection(/*section_id=*/3, /*hit_term_frequency=*/3);
+ std::unordered_map<SectionId, Hit::TermFrequency>
+ expected_section_ids_tf_map1_hello = {{0, 2}, {3, 3}};
- SectionIdMask section_id_mask2_hello = 0b00001100; // hits in sections 2, 3
- std::array<Hit::TermFrequency, kTotalNumSections> term_frequencies2_hello{
- 0, 0, 3, 2, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0};
DocHitInfoTermFrequencyPair doc_hit_info2_hello = DocHitInfo(9);
doc_hit_info2_hello.UpdateSection(/*section_id=*/2, /*hit_term_frequency=*/3);
doc_hit_info2_hello.UpdateSection(/*section_id=*/3, /*hit_term_frequency=*/2);
+ std::unordered_map<SectionId, Hit::TermFrequency>
+ expected_section_ids_tf_map2_hello = {{2, 3}, {3, 2}};
// For term "ciao", document 9 and 8
- SectionIdMask section_id_mask1_ciao = 0b00000011; // hits in sections 0, 1
- std::array<Hit::TermFrequency, kTotalNumSections> term_frequencies1_ciao{
- 2, 3, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0};
DocHitInfoTermFrequencyPair doc_hit_info1_ciao = DocHitInfo(9);
doc_hit_info1_ciao.UpdateSection(/*section_id=*/0, /*hit_term_frequency=*/2);
doc_hit_info1_ciao.UpdateSection(/*section_id=*/1, /*hit_term_frequency=*/3);
+ std::unordered_map<SectionId, Hit::TermFrequency>
+ expected_section_ids_tf_map1_ciao = {{0, 2}, {1, 3}};
- SectionIdMask section_id_mask2_ciao = 0b00011000; // hits in sections 3, 4
- std::array<Hit::TermFrequency, kTotalNumSections> term_frequencies2_ciao{
- 0, 0, 0, 3, 2, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0};
DocHitInfoTermFrequencyPair doc_hit_info2_ciao = DocHitInfo(8);
doc_hit_info2_ciao.UpdateSection(/*section_id=*/3, /*hit_term_frequency=*/3);
doc_hit_info2_ciao.UpdateSection(/*section_id=*/4, /*hit_term_frequency=*/2);
+ std::unordered_map<SectionId, Hit::TermFrequency>
+ expected_section_ids_tf_map2_ciao = {{3, 3}, {4, 2}};
std::vector<DocHitInfoTermFrequencyPair> first_vector = {doc_hit_info1_hi,
doc_hit_info2_hi};
@@ -549,45 +524,33 @@ TEST(DocHitInfoIteratorOrNaryTest, PopulateMatchedTermsStats) {
EXPECT_THAT(or_iter.doc_hit_info().document_id(), Eq(10));
or_iter.PopulateMatchedTermsStats(&matched_terms_stats);
- ASSERT_THAT(matched_terms_stats, SizeIs(2)); // 2 terms
- EXPECT_EQ(matched_terms_stats.at(0).term, "hi");
- EXPECT_THAT(matched_terms_stats.at(0).term_frequencies,
- ElementsAreArray(term_frequencies1_hi));
- EXPECT_EQ(matched_terms_stats.at(0).section_ids_mask, section_id_mask1_hi);
- EXPECT_EQ(matched_terms_stats.at(1).term, "hello");
- EXPECT_THAT(matched_terms_stats.at(1).term_frequencies,
- ElementsAreArray(term_frequencies1_hello));
- EXPECT_EQ(matched_terms_stats.at(1).section_ids_mask, section_id_mask1_hello);
+ EXPECT_THAT(
+ matched_terms_stats,
+ ElementsAre(
+ EqualsTermMatchInfo("hi", expected_section_ids_tf_map1_hi),
+ EqualsTermMatchInfo("hello", expected_section_ids_tf_map1_hello)));
ICING_EXPECT_OK(or_iter.Advance());
EXPECT_THAT(or_iter.doc_hit_info().document_id(), Eq(9));
matched_terms_stats.clear();
or_iter.PopulateMatchedTermsStats(&matched_terms_stats);
- ASSERT_THAT(matched_terms_stats, SizeIs(2)); // 2 terms
- EXPECT_EQ(matched_terms_stats.at(0).term, "hello");
- EXPECT_THAT(matched_terms_stats.at(0).term_frequencies,
- ElementsAreArray(term_frequencies2_hello));
- EXPECT_EQ(matched_terms_stats.at(0).section_ids_mask, section_id_mask2_hello);
- EXPECT_EQ(matched_terms_stats.at(1).term, "ciao");
- EXPECT_THAT(matched_terms_stats.at(1).term_frequencies,
- ElementsAreArray(term_frequencies1_ciao));
- EXPECT_EQ(matched_terms_stats.at(1).section_ids_mask, section_id_mask1_ciao);
+ EXPECT_THAT(
+ matched_terms_stats,
+ ElementsAre(
+ EqualsTermMatchInfo("hello", expected_section_ids_tf_map2_hello),
+ EqualsTermMatchInfo("ciao", expected_section_ids_tf_map1_ciao)));
ICING_EXPECT_OK(or_iter.Advance());
EXPECT_THAT(or_iter.doc_hit_info().document_id(), Eq(8));
matched_terms_stats.clear();
or_iter.PopulateMatchedTermsStats(&matched_terms_stats);
- ASSERT_THAT(matched_terms_stats, SizeIs(2)); // 2 terms
- EXPECT_EQ(matched_terms_stats.at(0).term, "hi");
- EXPECT_THAT(matched_terms_stats.at(0).term_frequencies,
- ElementsAreArray(term_frequencies2_hi));
- EXPECT_EQ(matched_terms_stats.at(0).section_ids_mask, section_id_mask2_hi);
- EXPECT_EQ(matched_terms_stats.at(1).term, "ciao");
- EXPECT_THAT(matched_terms_stats.at(1).term_frequencies,
- ElementsAreArray(term_frequencies2_ciao));
- EXPECT_EQ(matched_terms_stats.at(1).section_ids_mask, section_id_mask2_ciao);
+ EXPECT_THAT(
+ matched_terms_stats,
+ ElementsAre(
+ EqualsTermMatchInfo("hi", expected_section_ids_tf_map2_hi),
+ EqualsTermMatchInfo("ciao", expected_section_ids_tf_map2_ciao)));
EXPECT_FALSE(or_iter.Advance().ok());
}