aboutsummaryrefslogtreecommitdiff
path: root/icing/join/join-processor.cc
diff options
context:
space:
mode:
authorAlex Saveliev <alexsav@google.com>2023-02-07 20:02:36 -0800
committerAlex Saveliev <alexsav@google.com>2023-02-07 20:25:19 -0800
commit5a41ca990be33387b0d5d15836a465bbe5ff5a28 (patch)
tree10e0e3d043aa1ba8effa3964ccf3287d83961cb0 /icing/join/join-processor.cc
parentcccafab8dfcae94d7072eb49ea971e3c688bdfc4 (diff)
downloadicing-5a41ca990be33387b0d5d15836a465bbe5ff5a28.tar.gz
Update icing from upstream
====================================================================== Adds a proto change for the delete propagation option ====================================================================== [ez] Change version to magic for PersistentHashMap ====================================================================== [iOS][testing][nitro] Disabling ICU language segmenter_test. ====================================================================== 1. Add support for segmentation in the QueryVisitor. ====================================================================== Support the new double list type in ScoreExpression ====================================================================== Pass JoinChildrenFetcher from IcingSearchEngine all the way down to ScoringVisitor ====================================================================== Refactor the logic of Icing Joins so that nested search and scoring will be performed before the parent ====================================================================== Add lite-index thread-safety tests. ====================================================================== Split IcingSearchEngineTest into separate tests to cover specific apis: ====================================================================== Fix index tests TearDown method. ====================================================================== Improve query concurrency by providing a finer-grained lock around the LiteIndex. ====================================================================== Fix Icing normalization bug ====================================================================== [ez] Fix integer overflow error for IntegerIndexStorage ====================================================================== [NumericSearch][Storage][11/x] Implement Reset and destructor for IntegerIndex ====================================================================== [NumericSearch][Storage][10/x] Add class IntegerIndex ====================================================================== Refactor NumericIndex based on PersistentStorage ====================================================================== Refactor IntegerIndexStorage based on PersistentStorage ====================================================================== Add "working_path" into PersistentStorage ====================================================================== Refactor PersistentHashMap based on PersistentStorage ====================================================================== Create virtual class PersistentStorage for refactoring ====================================================================== Avoids returning reference to local temporary object. ====================================================================== LSC: Clean up references to the legacy protobuf compat library ====================================================================== Fix time complexity regression for snippet retriever Bug: 256022027 Bug: 193919210 Bug: 266132035 Bug: 208654892 Bug: 261474063 Bug: 266103594 Bug: 146008613 Bug: 253182853 Bug: 266204868 Bug: 249829533 Bug: 266665956 Bug: 265258364 Change-Id: Ib2398c5097b6a2a57900e2ad4e3737502aa13820
Diffstat (limited to 'icing/join/join-processor.cc')
-rw-r--r--icing/join/join-processor.cc47
1 files changed, 24 insertions, 23 deletions
diff --git a/icing/join/join-processor.cc b/icing/join/join-processor.cc
index 7700397..ab32850 100644
--- a/icing/join/join-processor.cc
+++ b/icing/join/join-processor.cc
@@ -34,11 +34,17 @@
namespace icing {
namespace lib {
-libtextclassifier3::StatusOr<std::vector<JoinedScoredDocumentHit>>
-JoinProcessor::Join(
+libtextclassifier3::StatusOr<JoinChildrenFetcher>
+JoinProcessor::GetChildrenFetcher(
const JoinSpecProto& join_spec,
- std::vector<ScoredDocumentHit>&& parent_scored_document_hits,
std::vector<ScoredDocumentHit>&& child_scored_document_hits) {
+ if (join_spec.parent_property_expression() != kQualifiedIdExpr) {
+ // TODO(b/256022027): So far we only support kQualifiedIdExpr for
+ // parent_property_expression, we could support more.
+ return absl_ports::UnimplementedError(absl_ports::StrCat(
+ "Parent property expression must be ", kQualifiedIdExpr));
+ }
+
std::sort(
child_scored_document_hits.begin(), child_scored_document_hits.end(),
ScoredDocumentHitComparator(
@@ -59,7 +65,7 @@ JoinProcessor::Join(
// ScoredDocumentHits refer to. The values in this map are vectors of child
// ScoredDocumentHits that refer to a parent DocumentId.
std::unordered_map<DocumentId, std::vector<ScoredDocumentHit>>
- parent_id_to_child_map;
+ map_joinable_qualified_id;
for (const ScoredDocumentHit& child : child_scored_document_hits) {
std::string property_content = FetchPropertyExpressionValue(
child.document_id(), join_spec.child_property_expression());
@@ -84,14 +90,21 @@ JoinProcessor::Join(
DocumentId parent_doc_id = std::move(parent_doc_id_or).ValueOrDie();
// Since we've already sorted child_scored_document_hits, just simply omit
- // if the parent_id_to_child_map[parent_doc_id].size() has reached max
+ // if the map_joinable_qualified_id[parent_doc_id].size() has reached max
// joined child count.
- if (parent_id_to_child_map[parent_doc_id].size() <
+ if (map_joinable_qualified_id[parent_doc_id].size() <
join_spec.max_joined_child_count()) {
- parent_id_to_child_map[parent_doc_id].push_back(child);
+ map_joinable_qualified_id[parent_doc_id].push_back(child);
}
}
+ return JoinChildrenFetcher(join_spec, std::move(map_joinable_qualified_id));
+}
+libtextclassifier3::StatusOr<std::vector<JoinedScoredDocumentHit>>
+JoinProcessor::Join(
+ const JoinSpecProto& join_spec,
+ std::vector<ScoredDocumentHit>&& parent_scored_document_hits,
+ const JoinChildrenFetcher& join_children_fetcher) {
std::unique_ptr<AggregationScorer> aggregation_scorer =
AggregationScorer::Create(join_spec);
@@ -100,23 +113,11 @@ JoinProcessor::Join(
// Step 2: iterate through all parent documentIds and construct
// JoinedScoredDocumentHit for each by looking up
- // parent_id_to_child_map.
+ // join_children_fetcher.
for (ScoredDocumentHit& parent : parent_scored_document_hits) {
- DocumentId parent_doc_id = kInvalidDocumentId;
- if (join_spec.parent_property_expression() == kQualifiedIdExpr) {
- parent_doc_id = parent.document_id();
- } else {
- // TODO(b/256022027): So far we only support kQualifiedIdExpr for
- // parent_property_expression, we could support more.
- return absl_ports::UnimplementedError(absl_ports::StrCat(
- "Parent property expression must be ", kQualifiedIdExpr));
- }
-
- std::vector<ScoredDocumentHit> children;
- if (auto iter = parent_id_to_child_map.find(parent_doc_id);
- iter != parent_id_to_child_map.end()) {
- children = std::move(iter->second);
- }
+ ICING_ASSIGN_OR_RETURN(
+ std::vector<ScoredDocumentHit> children,
+ join_children_fetcher.GetChildren(parent.document_id()));
double final_score = aggregation_scorer->GetScore(parent, children);
joined_scored_document_hits.emplace_back(final_score, std::move(parent),