aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorGrace Zhao <gracezrx@google.com>2022-11-07 13:55:21 -0800
committerGrace Zhao <gracezrx@google.com>2022-11-07 14:11:30 -0800
commit0cdc7152cbee44a55b800ef1ac4cb4ee609c0389 (patch)
treea3f7dab2dac08831328558dec51939dd75de25a1
parentd0795655ecf1aac89bb1802f4e1d3f5fb7dcb2b0 (diff)
downloadicing-0cdc7152cbee44a55b800ef1ac4cb4ee609c0389.tar.gz
Fix g3 sync for merge to androidx-main
Change invalid type int32 to use int32_t. Remove advanced-query-processor files as they're not yet ready for Jetpack. Change-Id: I5cb9db2e14d13141c07055705bb7fa2d4d181cd2
-rw-r--r--icing/jni/icing-search-engine-jni.cc4
-rw-r--r--icing/query/advanced-query-processor.cc211
-rw-r--r--icing/query/advanced-query-processor.h113
3 files changed, 2 insertions, 326 deletions
diff --git a/icing/jni/icing-search-engine-jni.cc b/icing/jni/icing-search-engine-jni.cc
index 5a30dd8..283c6f5 100644
--- a/icing/jni/icing-search-engine-jni.cc
+++ b/icing/jni/icing-search-engine-jni.cc
@@ -243,7 +243,7 @@ Java_com_google_android_icing_IcingSearchEngine_nativeGetNextPage(
const std::unique_ptr<const icing::lib::Clock> clock =
std::make_unique<icing::lib::Clock>();
- int32 java_to_native_jni_latency_ms =
+ int32_t java_to_native_jni_latency_ms =
clock->GetSystemTimeMilliseconds() - java_to_native_start_timestamp_ms;
icing::lib::SearchResultProto next_page_result_proto =
@@ -297,7 +297,7 @@ Java_com_google_android_icing_IcingSearchEngine_nativeSearch(
const std::unique_ptr<const icing::lib::Clock> clock =
std::make_unique<icing::lib::Clock>();
- int32 java_to_native_jni_latency_ms =
+ int32_t java_to_native_jni_latency_ms =
clock->GetSystemTimeMilliseconds() - java_to_native_start_timestamp_ms;
icing::lib::SearchResultProto search_result_proto =
diff --git a/icing/query/advanced-query-processor.cc b/icing/query/advanced-query-processor.cc
deleted file mode 100644
index 9914605..0000000
--- a/icing/query/advanced-query-processor.cc
+++ /dev/null
@@ -1,211 +0,0 @@
-// Copyright (C) 2022 Google LLC
-//
-// Licensed under the Apache License, Version 2.0 (the "License");
-// you may not use this file except in compliance with the License.
-// You may obtain a copy of the License at
-//
-// http://www.apache.org/licenses/LICENSE-2.0
-//
-// Unless required by applicable law or agreed to in writing, software
-// distributed under the License is distributed on an "AS IS" BASIS,
-// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
-// See the License for the specific language governing permissions and
-// limitations under the License.
-
-#include "icing/query/advanced-query-processor.h"
-
-#include "icing/index/iterator/doc-hit-info-iterator-all-document-id.h"
-#include "icing/index/iterator/doc-hit-info-iterator-and.h"
-#include "icing/index/iterator/doc-hit-info-iterator-filter.h"
-#include "icing/index/iterator/doc-hit-info-iterator-not.h"
-#include "icing/index/iterator/doc-hit-info-iterator-or.h"
-#include "icing/index/iterator/doc-hit-info-iterator-section-restrict.h"
-#include "icing/query/list_filter/list-filter-parser-factory.h"
-#include "icing/query/list_filter/list-filter-parser.h"
-#include "icing/query/query-terms.h"
-#include "icing/query/query-utils.h"
-#include "icing/schema/section-manager.h"
-
-namespace icing {
-namespace lib {
-
-namespace {
-
-void AddTermRestrict(SectionRestrictQueryTermsMap& query_terms,
- const std::string& section, std::string_view term) {
- auto itr = query_terms.find(section);
- if (itr == query_terms.end()) {
- query_terms.insert({section, {std::string(term)}});
- } else {
- itr->second.insert(std::string(term));
- }
-}
-
-std::string RetrievePropertyPath(const Expr& expr) {
- // Two things about the way paths are stored in the parser make it difficult
- // reconstruct the path.
- // 1. The path is in reverse order, so "recipient.contact.email" would be
- // provided in order of ["email", "contact", "recipient"]
- // 2. The base object ("recipient" in the example) is an Identity, while the
- // subsequent fields are Selects. So "recipient.contact.email" would be
- // provided as [ Select{"email"}, Select{"contact"}, Ident{"recipient"} ]
- const Expr* cur_expr = &expr;
- std::vector<std::string_view> path_parts;
- while (cur_expr->expr_kind_case() != Expr::kIdentExpr) {
- // This must be part of a nested path. Keep processing the Selects until we
- // reach the base (the Ident).
- path_parts.push_back(cur_expr->select_expr().field());
- cur_expr = &cur_expr->select_expr().operand();
- }
- path_parts.push_back(cur_expr->ident_expr().name());
- return absl_ports::StrJoin(path_parts.rbegin(), path_parts.rend(),
- kPropertySeparator,
- absl_ports::DefaultFormatter());
-}
-
-} // namespace
-
-libtextclassifier3::StatusOr<std::unique_ptr<AdvancedQueryProcessor>>
-AdvancedQueryProcessor::Create(Index* index,
- const LanguageSegmenter* language_segmenter,
- const Normalizer* normalizer,
- const DocumentStore* document_store,
- const SchemaStore* schema_store) {
- ICING_RETURN_ERROR_IF_NULL(index);
- ICING_RETURN_ERROR_IF_NULL(language_segmenter);
- ICING_RETURN_ERROR_IF_NULL(normalizer);
- ICING_RETURN_ERROR_IF_NULL(document_store);
- ICING_RETURN_ERROR_IF_NULL(schema_store);
-
- return std::unique_ptr<AdvancedQueryProcessor>(new AdvancedQueryProcessor(
- index, language_segmenter, normalizer, document_store, schema_store));
-}
-
-libtextclassifier3::StatusOr<QueryResults> AdvancedQueryProcessor::ParseSearch(
- const SearchSpecProto& search_spec,
- ScoringSpecProto::RankingStrategy::Code ranking_strategy) {
- filter_options_ = GetFilterOptions(search_spec);
- term_match_type_ = search_spec.term_match_type();
- ranking_strategy_ = ranking_strategy;
-
- QueryResults results;
- std::unique_ptr<ListFilterParser> parser = list_filter_parser_factory::Create(
- list_filter_parser_factory::ParserType::kCloud);
- Expr parsed_expr = parser->Parse(search_spec.query());
- QueryTermIteratorsMap* query_term_iterators =
- (ranking_strategy_ == ScoringSpecProto::RankingStrategy::RELEVANCE_SCORE)
- ? &results.query_term_iterators
- : nullptr;
- ICING_ASSIGN_OR_RETURN(results.root_iterator,
- TraverseTree(parsed_expr, "", &results.query_terms,
- query_term_iterators));
- return results;
-}
-
-libtextclassifier3::StatusOr<std::unique_ptr<DocHitInfoIterator>>
-AdvancedQueryProcessor::HandleLeaf(const Constant& constant,
- const std::string& property_filter,
- SectionRestrictQueryTermsMap* query_terms,
- QueryTermIteratorsMap* term_iterators) {
- std::string normalized_text =
- normalizer_.NormalizeTerm(constant.string_value());
- if (term_iterators != nullptr) {
- // Only need to populate term iterators if we're doing relevance scoring.
- ICING_ASSIGN_OR_RETURN(
- std::unique_ptr<DocHitInfoIterator> term_iterator,
- index_.GetIterator(
- normalized_text, kSectionIdMaskAll, term_match_type_,
- /*need_hit_term_frequency=*/ranking_strategy_ ==
- ScoringSpecProto::RankingStrategy::RELEVANCE_SCORE));
- term_iterator = std::make_unique<DocHitInfoIteratorFilter>(
- std::move(term_iterator), &document_store_, &schema_store_,
- filter_options_);
- (*term_iterators)[normalized_text] = std::move(term_iterator);
- }
-
- if (query_terms != nullptr) {
- AddTermRestrict(*query_terms, property_filter, normalized_text);
- }
-
- ICING_ASSIGN_OR_RETURN(
- std::unique_ptr<DocHitInfoIterator> term_iterator,
- index_.GetIterator(
- normalized_text, kSectionIdMaskAll, term_match_type_,
- /*need_hit_term_frequency=*/ranking_strategy_ ==
- ScoringSpecProto::RankingStrategy::RELEVANCE_SCORE));
- if (!property_filter.empty()) {
- term_iterator = std::make_unique<DocHitInfoIteratorSectionRestrict>(
- std::move(term_iterator), &document_store_, &schema_store_,
- property_filter);
- }
- return term_iterator;
-}
-
-libtextclassifier3::StatusOr<std::unique_ptr<DocHitInfoIterator>>
-AdvancedQueryProcessor::TraverseTree(const Expr::Call& call,
- const std::string& property_filter,
- SectionRestrictQueryTermsMap* query_terms,
- QueryTermIteratorsMap* term_iterators) {
- if (call.function() == "_&&_") {
- std::vector<std::unique_ptr<DocHitInfoIterator>> sub_itrs;
- sub_itrs.reserve(call.args_size());
- for (const Expr& arg_expr : call.args()) {
- ICING_ASSIGN_OR_RETURN(
- std::unique_ptr<DocHitInfoIterator> sub_itr,
- TraverseTree(arg_expr, property_filter, query_terms, term_iterators));
- sub_itrs.push_back(std::move(sub_itr));
- }
- return CreateAndIterator(std::move(sub_itrs));
- } else if (call.function() == "_||_") {
- std::vector<std::unique_ptr<DocHitInfoIterator>> sub_itrs;
- sub_itrs.reserve(call.args_size());
- for (const Expr& arg_expr : call.args()) {
- ICING_ASSIGN_OR_RETURN(
- std::unique_ptr<DocHitInfoIterator> sub_itr,
- TraverseTree(arg_expr, property_filter, query_terms, term_iterators));
- sub_itrs.push_back(std::move(sub_itr));
- }
- return CreateOrIterator(std::move(sub_itrs));
- } else if (call.function() == "NOT") {
- ICING_ASSIGN_OR_RETURN(std::unique_ptr<DocHitInfoIterator> sub_itr,
- TraverseTree(call.args(0), property_filter,
- /*query_terms=*/nullptr,
- /*term_iterators=*/nullptr));
- return std::make_unique<DocHitInfoIteratorNot>(
- std::move(sub_itr), document_store_.last_added_document_id());
- } else if (call.function() == ":") {
- std::string property_path = RetrievePropertyPath(call.args(0));
- return TraverseTree(call.args(1), property_path, query_terms,
- term_iterators);
- } else {
- return absl_ports::UnimplementedError(IcingStringUtil::StringPrintf(
- "Function %s NOT IMPLEMENTED", call.function().c_str()));
- }
-}
-
-// Traverse the subtree starting at parsed_expr.
-libtextclassifier3::StatusOr<std::unique_ptr<DocHitInfoIterator>>
-AdvancedQueryProcessor::TraverseTree(const Expr& parsed_expr,
- const std::string& property_filter,
- SectionRestrictQueryTermsMap* query_terms,
- QueryTermIteratorsMap* term_iterators) {
- switch (parsed_expr.expr_kind_case()) {
- case Expr::kConstExpr:
- return HandleLeaf(parsed_expr.const_expr(), property_filter, query_terms,
- term_iterators);
- case Expr::kCallExpr:
- return TraverseTree(parsed_expr.call_expr(), property_filter, query_terms,
- term_iterators);
- case Expr::EXPR_KIND_NOT_SET:
- return std::make_unique<DocHitInfoIteratorAllDocumentId>(
- document_store_.last_added_document_id());
- case Expr::kSelectExpr:
- case Expr::kIdentExpr:
- return absl_ports::UnimplementedError(IcingStringUtil::StringPrintf(
- "Expression type %d NOT IMPLEMENTED",
- static_cast<int>(parsed_expr.expr_kind_case())));
- }
-}
-
-} // namespace lib
-} // namespace icing
diff --git a/icing/query/advanced-query-processor.h b/icing/query/advanced-query-processor.h
deleted file mode 100644
index bd55899..0000000
--- a/icing/query/advanced-query-processor.h
+++ /dev/null
@@ -1,113 +0,0 @@
-// Copyright (C) 2022 Google LLC
-//
-// Licensed under the Apache License, Version 2.0 (the "License");
-// you may not use this file except in compliance with the License.
-// You may obtain a copy of the License at
-//
-// http://www.apache.org/licenses/LICENSE-2.0
-//
-// Unless required by applicable law or agreed to in writing, software
-// distributed under the License is distributed on an "AS IS" BASIS,
-// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
-// See the License for the specific language governing permissions and
-// limitations under the License.
-
-#ifndef ICING_QUERY_ADVANCED_QUERY_PROCESSOR_H_
-#define ICING_QUERY_ADVANCED_QUERY_PROCESSOR_H_
-
-#include <memory>
-#include <string>
-
-#include "icing/text_classifier/lib3/utils/base/statusor.h"
-#include "icing/index/index.h"
-#include "icing/index/iterator/doc-hit-info-iterator.h"
-#include "icing/proto/search.pb.h"
-#include "icing/query/list_filter/syntax.pb.h"
-#include "icing/query/query-results.h"
-#include "icing/query/query-terms.h"
-#include "icing/query/query-utils.h"
-#include "icing/schema/schema-store.h"
-#include "icing/store/document-store.h"
-#include "icing/tokenization/language-segmenter.h"
-#include "icing/transform/normalizer.h"
-
-namespace icing {
-namespace lib {
-
-// Processes SearchSpecProtos and retrieves the specified DocHitInfos that
-// satisfies the query and its restrictions. This does not perform any scoring,
-// and returns matched documents in a descending DocumentId order.
-class AdvancedQueryProcessor {
- public:
- // Factory function to create a QueryProcessor which does not take ownership
- // of any input components, and all pointers must refer to valid objects that
- // outlive the created QueryProcessor instance.
- //
- // Returns:
- // An QueryProcessor on success
- // FAILED_PRECONDITION if any of the pointers is null.
- static libtextclassifier3::StatusOr<std::unique_ptr<AdvancedQueryProcessor>>
- Create(Index* index, const LanguageSegmenter* language_segmenter,
- const Normalizer* normalizer, const DocumentStore* document_store,
- const SchemaStore* schema_store);
-
- // Parse the search configurations (including the query, any additional
- // filters, etc.) in the SearchSpecProto into one DocHitInfoIterator.
- //
- // Returns:
- // On success,
- // - One iterator that represents the entire query
- // - A map representing the query terms and any section restrictions
- // INVALID_ARGUMENT if query syntax is incorrect and cannot be tokenized
- // INTERNAL_ERROR on all other errors
- libtextclassifier3::StatusOr<QueryResults> ParseSearch(
- const SearchSpecProto& search_spec,
- ScoringSpecProto::RankingStrategy::Code ranking_strategy);
-
- private:
- explicit AdvancedQueryProcessor(Index* index,
- const LanguageSegmenter* language_segmenter,
- const Normalizer* normalizer,
- const DocumentStore* document_store,
- const SchemaStore* schema_store)
- : index_(*index),
- language_segmenter_(*language_segmenter),
- normalizer_(*normalizer),
- document_store_(*document_store),
- schema_store_(*schema_store),
- ranking_strategy_(ScoringSpecProto::RankingStrategy::NONE),
- term_match_type_(TermMatchType::UNKNOWN) {}
-
- libtextclassifier3::StatusOr<std::unique_ptr<DocHitInfoIterator>>
- TraverseTree(const Expr& parsed_expr, const std::string& property_filter,
- SectionRestrictQueryTermsMap* query_terms_out,
- QueryTermIteratorsMap* term_iterators_out);
-
- libtextclassifier3::StatusOr<std::unique_ptr<DocHitInfoIterator>>
- TraverseTree(const Expr::Call& call, const std::string& property_filter,
- SectionRestrictQueryTermsMap* query_terms_out,
- QueryTermIteratorsMap* term_iterators_out);
-
- libtextclassifier3::StatusOr<std::unique_ptr<DocHitInfoIterator>> HandleLeaf(
- const Constant& constant, const std::string& property_filter,
- SectionRestrictQueryTermsMap* query_terms_out,
- QueryTermIteratorsMap* term_iterators_out);
-
- // Not const because we could modify/sort the hit buffer in the lite index at
- // query time.
- Index& index_;
- const LanguageSegmenter& language_segmenter_;
- const Normalizer& normalizer_;
- const DocumentStore& document_store_;
- const SchemaStore& schema_store_;
-
- // Cached values
- DocHitInfoIteratorFilter::Options filter_options_;
- ScoringSpecProto::RankingStrategy::Code ranking_strategy_;
- TermMatchType::Code term_match_type_;
-};
-
-} // namespace lib
-} // namespace icing
-
-#endif // ICING_QUERY_ADVANCED_QUERY_PROCESSOR_H_