diff options
Diffstat (limited to 'icing/query')
-rw-r--r-- | icing/query/query-processor_benchmark.cc | 2 | ||||
-rw-r--r-- | icing/query/query-processor_test.cc | 16 | ||||
-rw-r--r-- | icing/query/suggestion-processor.cc | 11 | ||||
-rw-r--r-- | icing/query/suggestion-processor.h | 2 | ||||
-rw-r--r-- | icing/query/suggestion-processor_test.cc | 80 |
5 files changed, 58 insertions, 53 deletions
diff --git a/icing/query/query-processor_benchmark.cc b/icing/query/query-processor_benchmark.cc index bdd40aa..e48fe78 100644 --- a/icing/query/query-processor_benchmark.cc +++ b/icing/query/query-processor_benchmark.cc @@ -16,7 +16,6 @@ #include "gmock/gmock.h" #include "third_party/absl/flags/flag.h" #include "icing/document-builder.h" -#include "icing/helpers/icu/icu-data-file-helper.h" #include "icing/index/index.h" #include "icing/proto/term.pb.h" #include "icing/query/query-processor.h" @@ -24,6 +23,7 @@ #include "icing/schema/section.h" #include "icing/store/document-id.h" #include "icing/testing/common-matchers.h" +#include "icing/testing/icu-data-file-helper.h" #include "icing/testing/test-data.h" #include "icing/testing/tmp-directory.h" #include "icing/tokenization/language-segmenter-factory.h" diff --git a/icing/query/query-processor_test.cc b/icing/query/query-processor_test.cc index daeb479..950f739 100644 --- a/icing/query/query-processor_test.cc +++ b/icing/query/query-processor_test.cc @@ -23,7 +23,6 @@ #include "gtest/gtest.h" #include "icing/document-builder.h" #include "icing/file/filesystem.h" -#include "icing/helpers/icu/icu-data-file-helper.h" #include "icing/index/hit/doc-hit-info.h" #include "icing/index/index.h" #include "icing/index/iterator/doc-hit-info-iterator-test-util.h" @@ -40,6 +39,7 @@ #include "icing/store/document-store.h" #include "icing/testing/common-matchers.h" #include "icing/testing/fake-clock.h" +#include "icing/testing/icu-data-file-helper.h" #include "icing/testing/jni-test-helpers.h" #include "icing/testing/test-data.h" #include "icing/testing/tmp-directory.h" @@ -61,16 +61,16 @@ using ::testing::SizeIs; using ::testing::Test; using ::testing::UnorderedElementsAre; -constexpr PropertyConfigProto_DataType_Code TYPE_STRING = - PropertyConfigProto_DataType_Code_STRING; +constexpr PropertyConfigProto::DataType::Code TYPE_STRING = + PropertyConfigProto::DataType::STRING; -constexpr PropertyConfigProto_Cardinality_Code CARDINALITY_OPTIONAL = - PropertyConfigProto_Cardinality_Code_OPTIONAL; +constexpr PropertyConfigProto::Cardinality::Code CARDINALITY_OPTIONAL = + PropertyConfigProto::Cardinality::OPTIONAL; -constexpr StringIndexingConfig_TokenizerType_Code TOKENIZER_PLAIN = - StringIndexingConfig_TokenizerType_Code_PLAIN; +constexpr StringIndexingConfig::TokenizerType::Code TOKENIZER_PLAIN = + StringIndexingConfig::TokenizerType::PLAIN; -constexpr TermMatchType_Code MATCH_EXACT = TermMatchType_Code_EXACT_ONLY; +constexpr TermMatchType::Code MATCH_EXACT = TermMatchType::EXACT_ONLY; class QueryProcessorTest : public Test { protected: diff --git a/icing/query/suggestion-processor.cc b/icing/query/suggestion-processor.cc index 9c60810..cfa53f6 100644 --- a/icing/query/suggestion-processor.cc +++ b/icing/query/suggestion-processor.cc @@ -35,7 +35,7 @@ SuggestionProcessor::Create(Index* index, libtextclassifier3::StatusOr<std::vector<TermMetadata>> SuggestionProcessor::QuerySuggestions( const icing::lib::SuggestionSpecProto& suggestion_spec, - const std::vector<NamespaceId>& namespace_ids) { + const NamespaceChecker* namespace_checker) { // We use query tokenizer to tokenize the give prefix, and we only use the // last token to be the suggestion prefix. ICING_ASSIGN_OR_RETURN( @@ -73,8 +73,11 @@ SuggestionProcessor::QuerySuggestions( // lowercase. ICING_ASSIGN_OR_RETURN( std::vector<TermMetadata> terms, - index_.FindTermsByPrefix(normalizer_.NormalizeTerm(last_token), - namespace_ids, suggestion_spec.num_to_return())); + index_.FindTermsByPrefix( + normalizer_.NormalizeTerm(last_token), + suggestion_spec.num_to_return(), + suggestion_spec.scoring_spec().scoring_match_type(), + namespace_checker)); for (TermMetadata& term : terms) { term.content = query_prefix + term.content; @@ -90,4 +93,4 @@ SuggestionProcessor::SuggestionProcessor( normalizer_(*normalizer) {} } // namespace lib -} // namespace icing
\ No newline at end of file +} // namespace icing diff --git a/icing/query/suggestion-processor.h b/icing/query/suggestion-processor.h index b10dc84..088863e 100644 --- a/icing/query/suggestion-processor.h +++ b/icing/query/suggestion-processor.h @@ -48,7 +48,7 @@ class SuggestionProcessor { // INTERNAL_ERROR on all other errors libtextclassifier3::StatusOr<std::vector<TermMetadata>> QuerySuggestions( const SuggestionSpecProto& suggestion_spec, - const std::vector<NamespaceId>& namespace_ids); + const NamespaceChecker* namespace_checker); private: explicit SuggestionProcessor(Index* index, diff --git a/icing/query/suggestion-processor_test.cc b/icing/query/suggestion-processor_test.cc index 5e62277..ba4c90a 100644 --- a/icing/query/suggestion-processor_test.cc +++ b/icing/query/suggestion-processor_test.cc @@ -15,10 +15,11 @@ #include "icing/query/suggestion-processor.h" #include "gmock/gmock.h" -#include "icing/helpers/icu/icu-data-file-helper.h" #include "icing/store/document-store.h" +#include "icing/testing/always-true-namespace-checker-impl.h" #include "icing/testing/common-matchers.h" #include "icing/testing/fake-clock.h" +#include "icing/testing/icu-data-file-helper.h" #include "icing/testing/jni-test-helpers.h" #include "icing/testing/test-data.h" #include "icing/testing/tmp-directory.h" @@ -80,7 +81,6 @@ class SuggestionProcessorTest : public Test { DocumentStore::CreateResult create_result, DocumentStore::Create(&filesystem_, store_dir_, &fake_clock_, schema_store_.get())); - document_store_ = std::move(create_result.document_store); } libtextclassifier3::Status AddTokenToIndex( @@ -93,7 +93,6 @@ class SuggestionProcessorTest : public Test { } void TearDown() override { - document_store_.reset(); filesystem_.DeleteDirectoryRecursively(test_dir_.c_str()); } @@ -103,7 +102,6 @@ class SuggestionProcessorTest : public Test { std::unique_ptr<Index> index_; std::unique_ptr<LanguageSegmenter> language_segmenter_; std::unique_ptr<Normalizer> normalizer_; - std::unique_ptr<DocumentStore> document_store_; std::unique_ptr<SchemaStore> schema_store_; std::unique_ptr<const JniCache> jni_cache_ = GetTestJniCache(); FakeClock fake_clock_; @@ -131,9 +129,10 @@ TEST_F(SuggestionProcessorTest, PrependedPrefixTokenTest) { "prefix token should be prepended to the suggestion f"); suggestion_spec.set_num_to_return(10); - ICING_ASSERT_OK_AND_ASSIGN(std::vector<TermMetadata> terms, - suggestion_processor->QuerySuggestions( - suggestion_spec, /*namespace_ids=*/{})); + AlwaysTrueNamespaceCheckerImpl impl; + ICING_ASSERT_OK_AND_ASSIGN( + std::vector<TermMetadata> terms, + suggestion_processor->QuerySuggestions(suggestion_spec, &impl)); EXPECT_THAT(terms.at(0).content, "prefix token should be prepended to the suggestion foo"); } @@ -152,9 +151,10 @@ TEST_F(SuggestionProcessorTest, NonExistentPrefixTest) { suggestion_spec.set_prefix("nonExistTerm"); suggestion_spec.set_num_to_return(10); - ICING_ASSERT_OK_AND_ASSIGN(std::vector<TermMetadata> terms, - suggestion_processor->QuerySuggestions( - suggestion_spec, /*namespace_ids=*/{})); + AlwaysTrueNamespaceCheckerImpl impl; + ICING_ASSERT_OK_AND_ASSIGN( + std::vector<TermMetadata> terms, + suggestion_processor->QuerySuggestions(suggestion_spec, &impl)); EXPECT_THAT(terms, IsEmpty()); } @@ -173,9 +173,10 @@ TEST_F(SuggestionProcessorTest, PrefixTrailingSpaceTest) { suggestion_spec.set_prefix("f "); suggestion_spec.set_num_to_return(10); - ICING_ASSERT_OK_AND_ASSIGN(std::vector<TermMetadata> terms, - suggestion_processor->QuerySuggestions( - suggestion_spec, /*namespace_ids=*/{})); + AlwaysTrueNamespaceCheckerImpl impl; + ICING_ASSERT_OK_AND_ASSIGN( + std::vector<TermMetadata> terms, + suggestion_processor->QuerySuggestions(suggestion_spec, &impl)); EXPECT_THAT(terms, IsEmpty()); } @@ -193,28 +194,26 @@ TEST_F(SuggestionProcessorTest, NormalizePrefixTest) { SuggestionSpecProto suggestion_spec; suggestion_spec.set_prefix("F"); suggestion_spec.set_num_to_return(10); + + AlwaysTrueNamespaceCheckerImpl impl; ICING_ASSERT_OK_AND_ASSIGN( std::vector<TermMetadata> terms, - suggestion_processor->QuerySuggestions(suggestion_spec, - /*namespace_ids=*/{})); + suggestion_processor->QuerySuggestions(suggestion_spec, &impl)); EXPECT_THAT(terms.at(0).content, "foo"); suggestion_spec.set_prefix("fO"); ICING_ASSERT_OK_AND_ASSIGN( - terms, suggestion_processor->QuerySuggestions(suggestion_spec, - /*namespace_ids=*/{})); + terms, suggestion_processor->QuerySuggestions(suggestion_spec, &impl)); EXPECT_THAT(terms.at(0).content, "foo"); suggestion_spec.set_prefix("Fo"); ICING_ASSERT_OK_AND_ASSIGN( - terms, suggestion_processor->QuerySuggestions(suggestion_spec, - /*namespace_ids=*/{})); + terms, suggestion_processor->QuerySuggestions(suggestion_spec, &impl)); EXPECT_THAT(terms.at(0).content, "foo"); suggestion_spec.set_prefix("FO"); ICING_ASSERT_OK_AND_ASSIGN( - terms, suggestion_processor->QuerySuggestions(suggestion_spec, - /*namespace_ids=*/{})); + terms, suggestion_processor->QuerySuggestions(suggestion_spec, &impl)); EXPECT_THAT(terms.at(0).content, "foo"); } @@ -235,9 +234,10 @@ TEST_F(SuggestionProcessorTest, OrOperatorPrefixTest) { suggestion_spec.set_prefix("f OR"); suggestion_spec.set_num_to_return(10); - ICING_ASSERT_OK_AND_ASSIGN(std::vector<TermMetadata> terms, - suggestion_processor->QuerySuggestions( - suggestion_spec, /*namespace_ids=*/{})); + AlwaysTrueNamespaceCheckerImpl impl; + ICING_ASSERT_OK_AND_ASSIGN( + std::vector<TermMetadata> terms, + suggestion_processor->QuerySuggestions(suggestion_spec, &impl)); // Last Operator token will be used to query suggestion EXPECT_THAT(terms.at(0).content, "f original"); @@ -256,19 +256,20 @@ TEST_F(SuggestionProcessorTest, ParenthesesOperatorPrefixTest) { suggestion_spec.set_prefix("{f}"); suggestion_spec.set_num_to_return(10); - ICING_ASSERT_OK_AND_ASSIGN(std::vector<TermMetadata> terms, - suggestion_processor->QuerySuggestions( - suggestion_spec, /*namespace_ids=*/{})); + AlwaysTrueNamespaceCheckerImpl impl; + ICING_ASSERT_OK_AND_ASSIGN( + std::vector<TermMetadata> terms, + suggestion_processor->QuerySuggestions(suggestion_spec, &impl)); EXPECT_THAT(terms, IsEmpty()); suggestion_spec.set_prefix("[f]"); - ICING_ASSERT_OK_AND_ASSIGN(terms, suggestion_processor->QuerySuggestions( - suggestion_spec, /*namespace_ids=*/{})); + ICING_ASSERT_OK_AND_ASSIGN( + terms, suggestion_processor->QuerySuggestions(suggestion_spec, &impl)); EXPECT_THAT(terms, IsEmpty()); suggestion_spec.set_prefix("(f)"); - ICING_ASSERT_OK_AND_ASSIGN(terms, suggestion_processor->QuerySuggestions( - suggestion_spec, /*namespace_ids=*/{})); + ICING_ASSERT_OK_AND_ASSIGN( + terms, suggestion_processor->QuerySuggestions(suggestion_spec, &impl)); EXPECT_THAT(terms, IsEmpty()); } @@ -286,15 +287,15 @@ TEST_F(SuggestionProcessorTest, OtherSpecialPrefixTest) { suggestion_spec.set_prefix("f:"); suggestion_spec.set_num_to_return(10); - ICING_ASSERT_OK_AND_ASSIGN(std::vector<TermMetadata> terms, - suggestion_processor->QuerySuggestions( - suggestion_spec, /*namespace_ids=*/{})); + AlwaysTrueNamespaceCheckerImpl impl; + ICING_ASSERT_OK_AND_ASSIGN( + std::vector<TermMetadata> terms, + suggestion_processor->QuerySuggestions(suggestion_spec, &impl)); EXPECT_THAT(terms, IsEmpty()); suggestion_spec.set_prefix("f-"); ICING_ASSERT_OK_AND_ASSIGN( - terms, suggestion_processor->QuerySuggestions(suggestion_spec, - /*namespace_ids=*/{})); + terms, suggestion_processor->QuerySuggestions(suggestion_spec, &impl)); EXPECT_THAT(terms, IsEmpty()); } @@ -312,9 +313,10 @@ TEST_F(SuggestionProcessorTest, InvalidPrefixTest) { suggestion_spec.set_prefix("OR OR - :"); suggestion_spec.set_num_to_return(10); - ICING_ASSERT_OK_AND_ASSIGN(std::vector<TermMetadata> terms, - suggestion_processor->QuerySuggestions( - suggestion_spec, /*namespace_ids=*/{})); + AlwaysTrueNamespaceCheckerImpl impl; + ICING_ASSERT_OK_AND_ASSIGN( + std::vector<TermMetadata> terms, + suggestion_processor->QuerySuggestions(suggestion_spec, &impl)); EXPECT_THAT(terms, IsEmpty()); } |