diff options
Diffstat (limited to 'icing/result/result-state-v2_test.cc')
-rw-r--r-- | icing/result/result-state-v2_test.cc | 177 |
1 files changed, 21 insertions, 156 deletions
diff --git a/icing/result/result-state-v2_test.cc b/icing/result/result-state-v2_test.cc index 4f16e7f..8706b6d 100644 --- a/icing/result/result-state-v2_test.cc +++ b/icing/result/result-state-v2_test.cc @@ -18,27 +18,18 @@ #include <cstdint> #include <memory> #include <string> -#include <unordered_map> -#include <unordered_set> #include <vector> #include "gtest/gtest.h" #include "icing/absl_ports/mutex.h" #include "icing/file/filesystem.h" -#include "icing/portable/equals-proto.h" #include "icing/proto/document.pb.h" #include "icing/proto/schema.pb.h" -#include "icing/proto/scoring.pb.h" #include "icing/proto/search.pb.h" -#include "icing/proto/term.pb.h" -#include "icing/result/projection-tree.h" -#include "icing/result/snippet-context.h" #include "icing/schema/schema-store.h" #include "icing/scoring/priority-queue-scored-document-hits-ranker.h" #include "icing/scoring/scored-document-hit.h" -#include "icing/scoring/scored-document-hits-ranker.h" #include "icing/store/document-store.h" -#include "icing/store/namespace-id.h" #include "icing/testing/common-matchers.h" #include "icing/testing/tmp-directory.h" #include "icing/util/clock.h" @@ -47,26 +38,11 @@ namespace icing { namespace lib { namespace { -using ::icing::lib::portable_equals_proto::EqualsProto; using ::testing::ElementsAre; using ::testing::Eq; -using ::testing::IsEmpty; using ::testing::Pair; using ::testing::UnorderedElementsAre; -SearchSpecProto CreateSearchSpec(TermMatchType::Code match_type) { - SearchSpecProto search_spec; - search_spec.set_term_match_type(match_type); - return search_spec; -} - -ScoringSpecProto CreateScoringSpec(bool is_descending_order) { - ScoringSpecProto scoring_spec; - scoring_spec.set_order_by(is_descending_order ? ScoringSpecProto::Order::DESC - : ScoringSpecProto::Order::ASC); - return scoring_spec; -} - ResultSpecProto CreateResultSpec( int num_per_page, ResultSpecProto::ResultGroupingType result_group_type) { ResultSpecProto result_spec; @@ -133,14 +109,13 @@ TEST_F(ResultStateV2Test, ShouldInitializeValuesAccordingToSpecs) { CreateResultSpec(/*num_per_page=*/2, ResultSpecProto::NAMESPACE); result_spec.set_num_total_bytes_per_page_threshold(4096); + // Adjustment info is not important in this test. ResultStateV2 result_state( std::make_unique< PriorityQueueScoredDocumentHitsRanker<ScoredDocumentHit>>( - std::vector<ScoredDocumentHit>(), - /*is_descending=*/true), - /*query_terms=*/{}, CreateSearchSpec(TermMatchType::EXACT_ONLY), - CreateScoringSpec(/*is_descending_order=*/true), result_spec, - document_store()); + std::vector<ScoredDocumentHit>(), /*is_descending=*/true), + /*parent_adjustment_info=*/nullptr, /*child_adjustment_info=*/nullptr, + result_spec, document_store()); absl_ports::shared_lock l(&result_state.mutex); @@ -156,14 +131,14 @@ TEST_F(ResultStateV2Test, ShouldInitializeValuesAccordingToDefaultSpecs) { ASSERT_THAT(default_result_spec.num_total_bytes_per_page_threshold(), Eq(std::numeric_limits<int32_t>::max())); + // Adjustment info is not important in this test. ResultStateV2 result_state( std::make_unique< PriorityQueueScoredDocumentHitsRanker<ScoredDocumentHit>>( std::vector<ScoredDocumentHit>(), /*is_descending=*/true), - /*query_terms=*/{}, CreateSearchSpec(TermMatchType::EXACT_ONLY), - CreateScoringSpec(/*is_descending_order=*/true), default_result_spec, - document_store()); + /*parent_adjustment_info=*/nullptr, /*child_adjustment_info=*/nullptr, + default_result_spec, document_store()); absl_ports::shared_lock l(&result_state.mutex); @@ -174,116 +149,6 @@ TEST_F(ResultStateV2Test, ShouldInitializeValuesAccordingToDefaultSpecs) { Eq(default_result_spec.num_total_bytes_per_page_threshold())); } -TEST_F(ResultStateV2Test, ShouldReturnSnippetContextAccordingToSpecs) { - ResultSpecProto result_spec = - CreateResultSpec(/*num_per_page=*/2, ResultSpecProto::NAMESPACE); - result_spec.mutable_snippet_spec()->set_num_to_snippet(5); - result_spec.mutable_snippet_spec()->set_num_matches_per_property(5); - result_spec.mutable_snippet_spec()->set_max_window_utf32_length(5); - - SectionRestrictQueryTermsMap query_terms_map; - query_terms_map.emplace("term1", std::unordered_set<std::string>()); - - ResultStateV2 result_state( - std::make_unique< - PriorityQueueScoredDocumentHitsRanker<ScoredDocumentHit>>( - std::vector<ScoredDocumentHit>(), - /*is_descending=*/true), - query_terms_map, CreateSearchSpec(TermMatchType::EXACT_ONLY), - CreateScoringSpec(/*is_descending_order=*/true), result_spec, - document_store()); - - absl_ports::shared_lock l(&result_state.mutex); - - const SnippetContext snippet_context = result_state.snippet_context(); - - // Snippet context should be derived from the specs above. - EXPECT_TRUE(snippet_context.query_terms.find("term1") != - snippet_context.query_terms.end()); - EXPECT_THAT(snippet_context.snippet_spec, - EqualsProto(result_spec.snippet_spec())); - EXPECT_THAT(snippet_context.match_type, Eq(TermMatchType::EXACT_ONLY)); - - // The same copy can be fetched multiple times. - const SnippetContext snippet_context2 = result_state.snippet_context(); - EXPECT_TRUE(snippet_context2.query_terms.find("term1") != - snippet_context2.query_terms.end()); - EXPECT_THAT(snippet_context2.snippet_spec, - EqualsProto(result_spec.snippet_spec())); - EXPECT_THAT(snippet_context2.match_type, Eq(TermMatchType::EXACT_ONLY)); -} - -TEST_F(ResultStateV2Test, NoSnippetingShouldReturnNull) { - ResultSpecProto result_spec = - CreateResultSpec(/*num_per_page=*/2, ResultSpecProto::NAMESPACE); - // Setting num_to_snippet to 0 so that snippeting info won't be - // stored. - result_spec.mutable_snippet_spec()->set_num_to_snippet(0); - result_spec.mutable_snippet_spec()->set_num_matches_per_property(5); - result_spec.mutable_snippet_spec()->set_max_window_utf32_length(5); - - SectionRestrictQueryTermsMap query_terms_map; - query_terms_map.emplace("term1", std::unordered_set<std::string>()); - - ResultStateV2 result_state( - std::make_unique< - PriorityQueueScoredDocumentHitsRanker<ScoredDocumentHit>>( - std::vector<ScoredDocumentHit>(), - /*is_descending=*/true), - query_terms_map, CreateSearchSpec(TermMatchType::EXACT_ONLY), - CreateScoringSpec(/*is_descending_order=*/true), result_spec, - document_store()); - - absl_ports::shared_lock l(&result_state.mutex); - - const SnippetContext snippet_context = result_state.snippet_context(); - EXPECT_THAT(snippet_context.query_terms, IsEmpty()); - EXPECT_THAT( - snippet_context.snippet_spec, - EqualsProto(ResultSpecProto::SnippetSpecProto::default_instance())); - EXPECT_THAT(snippet_context.match_type, TermMatchType::UNKNOWN); -} - -TEST_F(ResultStateV2Test, ShouldConstructProjectionTreeMapAccordingToSpecs) { - // Create a ResultSpec with type property mask. - ResultSpecProto result_spec = - CreateResultSpec(/*num_per_page=*/2, ResultSpecProto::NAMESPACE); - TypePropertyMask* email_type_property_mask = - result_spec.add_type_property_masks(); - email_type_property_mask->set_schema_type("Email"); - email_type_property_mask->add_paths("sender.name"); - email_type_property_mask->add_paths("sender.emailAddress"); - TypePropertyMask* phone_type_property_mask = - result_spec.add_type_property_masks(); - phone_type_property_mask->set_schema_type("Phone"); - phone_type_property_mask->add_paths("caller"); - TypePropertyMask* wildcard_type_property_mask = - result_spec.add_type_property_masks(); - wildcard_type_property_mask->set_schema_type( - std::string(ProjectionTree::kSchemaTypeWildcard)); - wildcard_type_property_mask->add_paths("wild.card"); - - ResultStateV2 result_state( - std::make_unique< - PriorityQueueScoredDocumentHitsRanker<ScoredDocumentHit>>( - std::vector<ScoredDocumentHit>(), - /*is_descending=*/true), - /*query_terms=*/{}, CreateSearchSpec(TermMatchType::EXACT_ONLY), - CreateScoringSpec(/*is_descending_order=*/true), result_spec, - document_store()); - - absl_ports::shared_lock l(&result_state.mutex); - - const std::unordered_map<std::string, ProjectionTree>& projection_tree_map = - result_state.projection_tree_map(); - EXPECT_THAT(projection_tree_map, - UnorderedElementsAre( - Pair("Email", ProjectionTree(*email_type_property_mask)), - Pair("Phone", ProjectionTree(*phone_type_property_mask)), - Pair(std::string(ProjectionTree::kSchemaTypeWildcard), - ProjectionTree(*wildcard_type_property_mask)))); -} - TEST_F(ResultStateV2Test, ShouldConstructNamespaceGroupIdMapAndGroupResultLimitsAccordingToSpecs) { // Create 3 docs under namespace1, namespace2, namespace3. @@ -342,14 +207,14 @@ TEST_F(ResultStateV2Test, int32_t entry_id3, document_store().GetResultGroupingEntryId( result_grouping_type, "namespace3", "Document")); + // Adjustment info is not important in this test. ResultStateV2 result_state( std::make_unique< PriorityQueueScoredDocumentHitsRanker<ScoredDocumentHit>>( std::vector<ScoredDocumentHit>(), /*is_descending=*/true), - /*query_terms=*/{}, CreateSearchSpec(TermMatchType::EXACT_ONLY), - CreateScoringSpec(/*is_descending_order=*/true), result_spec, - document_store()); + /*parent_adjustment_info=*/nullptr, /*child_adjustment_info=*/nullptr, + result_spec, document_store()); absl_ports::shared_lock l(&result_state.mutex); @@ -374,14 +239,14 @@ TEST_F(ResultStateV2Test, ShouldUpdateNumTotalHits) { AddScoredDocument(/*document_id=*/4), AddScoredDocument(/*document_id=*/3)}; + // Adjustment info is not important in this test. // Creates a ResultState with 5 ScoredDocumentHits. ResultStateV2 result_state( std::make_unique< PriorityQueueScoredDocumentHitsRanker<ScoredDocumentHit>>( std::move(scored_document_hits), /*is_descending=*/true), - /*query_terms=*/{}, CreateSearchSpec(TermMatchType::EXACT_ONLY), - CreateScoringSpec(/*is_descending_order=*/true), + /*parent_adjustment_info=*/nullptr, /*child_adjustment_info=*/nullptr, CreateResultSpec(/*num_per_page=*/5, ResultSpecProto::NAMESPACE), document_store()); @@ -408,14 +273,14 @@ TEST_F(ResultStateV2Test, ShouldUpdateNumTotalHitsWhenDestructed) { num_total_hits() = 2; { + // Adjustment info is not important in this test. // Creates a ResultState with 5 ScoredDocumentHits. ResultStateV2 result_state1( std::make_unique< PriorityQueueScoredDocumentHitsRanker<ScoredDocumentHit>>( std::move(scored_document_hits1), /*is_descending=*/true), - /*query_terms=*/{}, CreateSearchSpec(TermMatchType::EXACT_ONLY), - CreateScoringSpec(/*is_descending_order=*/true), + /*parent_adjustment_info=*/nullptr, /*child_adjustment_info=*/nullptr, CreateResultSpec(/*num_per_page=*/5, ResultSpecProto::NAMESPACE), document_store()); @@ -425,14 +290,14 @@ TEST_F(ResultStateV2Test, ShouldUpdateNumTotalHitsWhenDestructed) { ASSERT_THAT(num_total_hits(), Eq(7)); { + // Adjustment info is not important in this test. // Creates another ResultState with 2 ScoredDocumentHits. ResultStateV2 result_state2( std::make_unique< PriorityQueueScoredDocumentHitsRanker<ScoredDocumentHit>>( std::move(scored_document_hits2), /*is_descending=*/true), - /*query_terms=*/{}, CreateSearchSpec(TermMatchType::EXACT_ONLY), - CreateScoringSpec(/*is_descending_order=*/true), + /*parent_adjustment_info=*/nullptr, /*child_adjustment_info=*/nullptr, CreateResultSpec(/*num_per_page=*/5, ResultSpecProto::NAMESPACE), document_store()); @@ -457,13 +322,13 @@ TEST_F(ResultStateV2Test, ShouldNotUpdateNumTotalHitsWhenNotRegistered) { // Creates a ResultState with 5 ScoredDocumentHits. { + // Adjustment info is not important in this test. ResultStateV2 result_state( std::make_unique< PriorityQueueScoredDocumentHitsRanker<ScoredDocumentHit>>( std::move(scored_document_hits), /*is_descending=*/true), - /*query_terms=*/{}, CreateSearchSpec(TermMatchType::EXACT_ONLY), - CreateScoringSpec(/*is_descending_order=*/true), + /*parent_adjustment_info=*/nullptr, /*child_adjustment_info=*/nullptr, CreateResultSpec(/*num_per_page=*/5, ResultSpecProto::NAMESPACE), document_store()); @@ -488,14 +353,14 @@ TEST_F(ResultStateV2Test, ShouldDecrementOriginalNumTotalHitsWhenReregister) { AddScoredDocument(/*document_id=*/4), AddScoredDocument(/*document_id=*/3)}; + // Adjustment info is not important in this test. // Creates a ResultState with 5 ScoredDocumentHits. ResultStateV2 result_state( std::make_unique< PriorityQueueScoredDocumentHitsRanker<ScoredDocumentHit>>( std::move(scored_document_hits), /*is_descending=*/true), - /*query_terms=*/{}, CreateSearchSpec(TermMatchType::EXACT_ONLY), - CreateScoringSpec(/*is_descending_order=*/true), + /*parent_adjustment_info=*/nullptr, /*child_adjustment_info=*/nullptr, CreateResultSpec(/*num_per_page=*/5, ResultSpecProto::NAMESPACE), document_store()); @@ -520,4 +385,4 @@ TEST_F(ResultStateV2Test, ShouldDecrementOriginalNumTotalHitsWhenReregister) { } // namespace } // namespace lib -} // namespace icing
\ No newline at end of file +} // namespace icing |