diff options
author | Tim Barron <tjbarron@google.com> | 2023-03-09 18:56:43 -0800 |
---|---|---|
committer | Tim Barron <tjbarron@google.com> | 2023-03-09 18:56:43 -0800 |
commit | 3fe6aa4251989fb27863fdbf51e18d8c1f9e42dd (patch) | |
tree | be7ee8f21e62dcd3c30d394aafa6c9c2d0a6a56e /icing/icing-search-engine_suggest_test.cc | |
parent | 53032446fec369125a6dc47c9f66435e4a62410b (diff) | |
download | icing-3fe6aa4251989fb27863fdbf51e18d8c1f9e42dd.tar.gz |
Update Icing from upstream.
Descriptions:
======================================================================
Integrate Advanced Query w/ Suggest, make ADVANCED_QUERY default parser.
======================================================================
BUG: 208654892
Change-Id: I53889482e844648ec65565f9a7f7c8faa89baa7c
Diffstat (limited to 'icing/icing-search-engine_suggest_test.cc')
-rw-r--r-- | icing/icing-search-engine_suggest_test.cc | 92 |
1 files changed, 90 insertions, 2 deletions
diff --git a/icing/icing-search-engine_suggest_test.cc b/icing/icing-search-engine_suggest_test.cc index 6973ad0..b3aeafc 100644 --- a/icing/icing-search-engine_suggest_test.cc +++ b/icing/icing-search-engine_suggest_test.cc @@ -12,8 +12,6 @@ // See the License for the specific language governing permissions and // limitations under the License. -#include "icing/icing-search-engine.h" - #include <cstdint> #include <limits> #include <memory> @@ -25,6 +23,7 @@ #include "gtest/gtest.h" #include "icing/document-builder.h" #include "icing/file/filesystem.h" +#include "icing/icing-search-engine.h" #include "icing/jni/jni-cache.h" #include "icing/portable/endian.h" #include "icing/portable/equals-proto.h" @@ -1508,6 +1507,95 @@ TEST_F(IcingSearchEngineSuggestTest, UnorderedElementsAre(EqualsProto(suggestionBarCatSubjectFoo))); } +TEST_F(IcingSearchEngineSuggestTest, SearchSuggestionsTest_InvalidPrefixTest) { + IcingSearchEngine icing(GetDefaultIcingOptions(), GetTestJniCache()); + ASSERT_THAT(icing.Initialize().status(), ProtoIsOk()); + ASSERT_THAT(icing.SetSchema(CreatePersonAndEmailSchema()).status(), + ProtoIsOk()); + + DocumentProto document1 = + DocumentBuilder() + .SetKey("namespace1", "uri1") + .SetSchema("Email") + .SetCreationTimestampMs(10) + .AddStringProperty("subject", "bar fo") // "bar fo" + .AddStringProperty("body", "fool") + .Build(); + DocumentProto document2 = + DocumentBuilder() + .SetKey("namespace1", "uri2") + .SetSchema("Email") + .SetCreationTimestampMs(10) + .AddStringProperty("subject", "bar cat foo") // "bar cat fool" + .AddStringProperty("body", "fool") + .Build(); + DocumentProto document3 = DocumentBuilder() + .SetKey("namespace1", "uri3") + .SetSchema("Email") + .SetCreationTimestampMs(10) + .AddStringProperty("subject", "fool") // "fool" + .AddStringProperty("body", "fool") + .Build(); + ASSERT_THAT(icing.Put(document1).status(), ProtoIsOk()); + ASSERT_THAT(icing.Put(document2).status(), ProtoIsOk()); + ASSERT_THAT(icing.Put(document3).status(), ProtoIsOk()); + + // Search for "f OR" + SuggestionSpecProto suggestion_spec; + suggestion_spec.set_prefix("f OR"); + suggestion_spec.set_num_to_return(10); + suggestion_spec.mutable_scoring_spec()->set_scoring_match_type( + TermMatchType::PREFIX); + suggestion_spec.mutable_scoring_spec()->set_rank_by( + SuggestionScoringSpecProto::SuggestionRankingStrategy::DOCUMENT_COUNT); + + SuggestionResponse response = icing.SearchSuggestions(suggestion_spec); + if (SearchSpecProto::default_instance().search_type() == + SearchSpecProto::SearchType::ICING_RAW_QUERY) { + EXPECT_THAT(response.status(), ProtoIsOk()); + EXPECT_THAT(response.suggestions(), IsEmpty()); + } else { + EXPECT_THAT(response.status(), + ProtoStatusIs(StatusProto::INVALID_ARGUMENT)); + EXPECT_THAT(response.suggestions(), IsEmpty()); + } + + // TODO(b/208654892): Update handling for hyphens to only consider it a hyphen + // within a TEXT token (rather than a MINUS token) when surrounded on both + // sides by TEXT rather than just preceded by TEXT. + // Search for "f-" + suggestion_spec.set_prefix("f-"); + response = icing.SearchSuggestions(suggestion_spec); + EXPECT_THAT(response.status(), ProtoIsOk()); + EXPECT_THAT(response.suggestions(), IsEmpty()); + + // Search for "f:" + suggestion_spec.set_prefix("f:"); + response = icing.SearchSuggestions(suggestion_spec); + if (SearchSpecProto::default_instance().search_type() == + SearchSpecProto::SearchType::ICING_RAW_QUERY) { + EXPECT_THAT(response.status(), ProtoIsOk()); + EXPECT_THAT(response.suggestions(), IsEmpty()); + } else { + EXPECT_THAT(response.status(), + ProtoStatusIs(StatusProto::INVALID_ARGUMENT)); + EXPECT_THAT(response.suggestions(), IsEmpty()); + } + + // Search for "OR OR - :" + suggestion_spec.set_prefix("OR OR - :"); + response = icing.SearchSuggestions(suggestion_spec); + if (SearchSpecProto::default_instance().search_type() == + SearchSpecProto::SearchType::ICING_RAW_QUERY) { + EXPECT_THAT(response.status(), ProtoIsOk()); + EXPECT_THAT(response.suggestions(), IsEmpty()); + } else { + EXPECT_THAT(response.status(), + ProtoStatusIs(StatusProto::INVALID_ARGUMENT)); + EXPECT_THAT(response.suggestions(), IsEmpty()); + } +} + } // namespace } // namespace lib } // namespace icing |