diff options
author | Terry Wang <tytytyww@google.com> | 2023-01-23 14:54:45 -0800 |
---|---|---|
committer | Terry Wang <tytytyww@google.com> | 2023-01-23 14:54:45 -0800 |
commit | cccafab8dfcae94d7072eb49ea971e3c688bdfc4 (patch) | |
tree | c5658335e3a0287ab3a7b25a3f18585920515f75 /icing/monkey_test | |
parent | ec29b14d5a908748d6e0699df7c85842a95a7b3c (diff) | |
download | icing-cccafab8dfcae94d7072eb49ea971e3c688bdfc4.tar.gz |
Update Icing from upstream.
Descriptions:
======================================================================
Fix time complexity regression for snippet retriever
======================================================================
Add support for QueryTerms SectionRestrict Map in Advanced Query.
======================================================================
[NumericSearch][Storage][9/x] Create unit tests for AddKeys and
GetIterator
======================================================================
[NumericSearch][Storage][8/x] Add options
======================================================================
Fix the stack overflow issue for icing advanced scoring/query
parsers/visitors by limiting the number of tokens allowed
======================================================================
Improves the has joinspec check
======================================================================
Fix the bug of DocHitInfoIteratorTermMain found by monkey test
======================================================================
Rename tests defined in DestructibleDirectoryTest to include
"directory" instead of "file".
======================================================================
Support projection in icing monkey test
======================================================================
[NumericSearch][Storage][7/x] Implement iterator for query
======================================================================
[NumericSearch][Storage][6/x] Implement AddKeys
======================================================================
Add support for relevance scoring by enabling term_frequency retrieval
in DocHitInfoIterators and by populating the QueryTermIteratorsMap.
======================================================================
[JoinableCache][1/x] Compute SchemaDelta for joinable properties
======================================================================
[NumericSearch][Storage][5/x] PersistToDisk
======================================================================
[NumericSearch][Storage][4.1/x] Create unit tests for initialize
======================================================================
[NumericSearch][Storage][4.0/x] Implement Create and Initialize functions
======================================================================
Rename PostingListUsedSerializer related classes
Bug: 193244409
Bug: 208654892
Bug: 246984163
Bug: 249829533
Bug: 256022027
Bug: 265258364
Bug: 265834832
Change-Id: Ibc7011a793ef5ed09eace0fb05d168adf5b4faca
Diffstat (limited to 'icing/monkey_test')
-rw-r--r-- | icing/monkey_test/icing-monkey-test-runner.cc | 76 |
1 files changed, 60 insertions, 16 deletions
diff --git a/icing/monkey_test/icing-monkey-test-runner.cc b/icing/monkey_test/icing-monkey-test-runner.cc index e7c0bdf..db518bd 100644 --- a/icing/monkey_test/icing-monkey-test-runner.cc +++ b/icing/monkey_test/icing-monkey-test-runner.cc @@ -113,7 +113,22 @@ ResultSpecProto::SnippetSpecProto GenerateRandomSnippetSpecProto( return snippet_spec; } -ResultSpecProto GenerateRandomResultSpecProto(MonkeyTestRandomEngine* random) { +TypePropertyMask GenerateTypePropertyMask( + MonkeyTestRandomEngine* random, const SchemaTypeConfigProto& type_config) { + TypePropertyMask type_property_mask; + type_property_mask.set_schema_type(type_config.schema_type()); + for (const auto& properties : type_config.properties()) { + // 25% chance of adding the current property to the mask. + std::uniform_int_distribution<> dist(0, 3); + if (dist(*random) == 0) { + type_property_mask.add_paths(properties.property_name()); + } + } + return type_property_mask; +} + +ResultSpecProto GenerateRandomResultSpecProto(MonkeyTestRandomEngine* random, + const SchemaProto* schema) { std::uniform_int_distribution<> dist(0, 4); ResultSpecProto result_spec; // 1/5 chance of getting one of 1, 4, 16, 64, 256 @@ -121,6 +136,18 @@ ResultSpecProto GenerateRandomResultSpecProto(MonkeyTestRandomEngine* random) { result_spec.set_num_per_page(num_per_page); *result_spec.mutable_snippet_spec() = GenerateRandomSnippetSpecProto(random, result_spec); + + // 1/5 chance of enabling projection. + if (dist(*random) == 0) { + for (const SchemaTypeConfigProto& type_config : schema->types()) { + // 25% chance of adding the current type to the projection. + std::uniform_int_distribution<> dist(0, 3); + if (dist(*random) == 0) { + *result_spec.add_type_property_masks() = + GenerateTypePropertyMask(random, type_config); + } + } + } return result_spec; } @@ -338,26 +365,37 @@ void IcingMonkeyTestRunner::DoDeleteByQuery() { } void IcingMonkeyTestRunner::DoSearch() { - SearchSpecProto search_spec = - GenerateRandomSearchSpecProto(&random_, document_generator_.get()); - ScoringSpecProto scoring_spec = GenerateRandomScoringSpec(&random_); - ResultSpecProto result_spec = GenerateRandomResultSpecProto(&random_); - const ResultSpecProto::SnippetSpecProto& snippet_spec = - result_spec.snippet_spec(); - - ICING_LOG(INFO) << "Monkey searching by query: " << search_spec.query() - << ", term_match_type: " << search_spec.term_match_type(); - ICING_VLOG(1) << "search_spec:\n" << search_spec.DebugString(); - ICING_VLOG(1) << "scoring_spec:\n" << scoring_spec.DebugString(); - ICING_VLOG(1) << "result_spec:\n" << result_spec.DebugString(); + std::unique_ptr<SearchSpecProto> search_spec = + std::make_unique<SearchSpecProto>( + GenerateRandomSearchSpecProto(&random_, document_generator_.get())); + std::unique_ptr<ScoringSpecProto> scoring_spec = + std::make_unique<ScoringSpecProto>(GenerateRandomScoringSpec(&random_)); + std::unique_ptr<ResultSpecProto> result_spec = + std::make_unique<ResultSpecProto>(GenerateRandomResultSpecProto( + &random_, in_memory_icing_->GetSchema())); + const ResultSpecProto::SnippetSpecProto snippet_spec = + result_spec->snippet_spec(); + bool is_projection_enabled = !result_spec->type_property_masks().empty(); + + ICING_LOG(INFO) << "Monkey searching by query: " << search_spec->query() + << ", term_match_type: " << search_spec->term_match_type(); + ICING_VLOG(1) << "search_spec:\n" << search_spec->DebugString(); + ICING_VLOG(1) << "scoring_spec:\n" << scoring_spec->DebugString(); + ICING_VLOG(1) << "result_spec:\n" << result_spec->DebugString(); std::vector<DocumentProto> exp_documents = - in_memory_icing_->Search(search_spec); + in_memory_icing_->Search(*search_spec); SearchResultProto search_result = - icing_->Search(search_spec, scoring_spec, result_spec); + icing_->Search(*search_spec, *scoring_spec, *result_spec); ASSERT_THAT(search_result.status(), ProtoIsOk()); + // Delete all of the specs used in the search. GetNextPage should have no + // problem because it shouldn't be keeping any references to them. + search_spec.reset(); + scoring_spec.reset(); + result_spec.reset(); + std::vector<DocumentProto> actual_documents; int num_snippeted = 0; while (true) { @@ -382,7 +420,7 @@ void IcingMonkeyTestRunner::DoSearch() { if (exp_documents.size() >= 30000) { return; } - if (snippet_spec.num_matches_per_property() > 0) { + if (snippet_spec.num_matches_per_property() > 0 && !is_projection_enabled) { ASSERT_THAT(num_snippeted, Eq(std::min<uint32_t>(exp_documents.size(), snippet_spec.num_to_snippet()))); @@ -391,6 +429,12 @@ void IcingMonkeyTestRunner::DoSearch() { SortDocuments(actual_documents); ASSERT_THAT(actual_documents, SizeIs(exp_documents.size())); for (int i = 0; i < exp_documents.size(); ++i) { + if (is_projection_enabled) { + ASSERT_THAT(actual_documents[i].namespace_(), + Eq(exp_documents[i].namespace_())); + ASSERT_THAT(actual_documents[i].uri(), Eq(exp_documents[i].uri())); + continue; + } ASSERT_THAT(actual_documents[i], EqualsProto(exp_documents[i])); } ICING_LOG(INFO) << exp_documents.size() << " documents found by query."; |