JoinSpec
public
final
class
JoinSpec
extends Object
| java.lang.Object | |
| ↳ | android.app.appsearch.JoinSpec |
This class represents the specifications for the joining operation in search.
Joins are only possible for matching on the qualified id of an outer document and a property
value within a subquery document. In the subquery documents, these values may be referred to with
a property path such as "email.recipient.id" or "entityId" or a property expression. One such
property expression is QUALIFIED_ID, which refers to the document's combined package,
database, namespace, and id.
Take these outer query and subquery results for example:
Outer result {
id: id1
score: 5
}
Subquery result 1 {
id: id2
score: 2
entityId: pkg$db/ns#id1
notes: This is some doc
}
Subquery result 2 {
id: id3
score: 3
entityId: pkg$db/ns#id2
notes: This is another doc
}
In this example, subquery result 1 contains a property "entityId" whose value is
"pkg$db/ns#id1", referring to the outer result. If you call Builder with "entityId", we
will retrieve the value of the property "entityId" from the child document, which is
"pkg$db#ns/id1". Let's say the qualified id of the outer result is "pkg$db#ns/id1". This would
mean the subquery result 1 document will be matched to that parent document. This is done by
adding a SearchResult containing the child document to the top-level parent SearchResult.getJoinedResults().
If getChildPropertyExpression() is "notes", we will check the values of the notes
property in the subquery results. In subquery result 1, this values is "This is some doc", which
does not equal the qualified id of the outer query result. As such, subquery result 1 will not be
joined to the outer query result.
In terms of scoring, if SearchSpec#RANKING_STRATEGY_JOIN_AGGREGATE_SCORE is set in
SearchSpec#getRankingStrategy, the scores of the outer SearchResults can be influenced by
the ranking signals of the subquery results. For example, if the getAggregationScoringStrategy() is set to AGGREGATION_SCORING_MIN_RANKING_SIGNAL, the ranking signal of the outer SearchResult will be set to the minimum of the ranking signals of the subquery results. In this
case, it will be the minimum of 2 and 3, which is 2. If the getAggregationScoringStrategy() is set to AGGREGATION_SCORING_OUTER_RESULT_RANKING_SIGNAL, the ranking signal of the outer SearchResult will stay as it is.
Summary
Nested classes | |
|---|---|
class |
JoinSpec.Builder
Builder for |
Constants | |
|---|---|
int |
AGGREGATION_SCORING_AVG_RANKING_SIGNAL
Score the aggregation of joined documents using the average ranking signal. |
int |
AGGREGATION_SCORING_MAX_RANKING_SIGNAL
Score the aggregation of joined documents using the largest ranking signal. |
int |
AGGREGATION_SCORING_MIN_RANKING_SIGNAL
Score the aggregation of joined documents using the smallest ranking signal. |
int |
AGGREGATION_SCORING_OUTER_RESULT_RANKING_SIGNAL
Do not score the aggregation of joined documents. |
int |
AGGREGATION_SCORING_RESULT_COUNT
Score the aggregation of joined documents by counting the number of results. |
int |
AGGREGATION_SCORING_SUM_RANKING_SIGNAL
Score the aggregation of joined documents using the sum of ranking signal. |
String |
QUALIFIED_ID
A property expression referring to the combined package name, database name, namespace, and id of the document. |
Public methods | |
|---|---|
int
|
getAggregationScoringStrategy()
Gets the joined document list scoring strategy. |
String
|
getChildPropertyExpression()
The property expression that is used to get values from child documents, returned from the nested search. |
int
|
getMaxJoinedResultCount()
Returns the max amount of |
String
|
getNestedQuery()
Returns the query to run on the joined documents. |
SearchSpec
|
getNestedSearchSpec()
Returns the search spec used to retrieve the joined documents. |
Inherited methods | |
|---|---|
Constants
AGGREGATION_SCORING_AVG_RANKING_SIGNAL
public static final int AGGREGATION_SCORING_AVG_RANKING_SIGNAL
Score the aggregation of joined documents using the average ranking signal.
Constant Value: 3 (0x00000003)
AGGREGATION_SCORING_MAX_RANKING_SIGNAL
public static final int AGGREGATION_SCORING_MAX_RANKING_SIGNAL
Score the aggregation of joined documents using the largest ranking signal.
Constant Value: 4 (0x00000004)
AGGREGATION_SCORING_MIN_RANKING_SIGNAL
public static final int AGGREGATION_SCORING_MIN_RANKING_SIGNAL
Score the aggregation of joined documents using the smallest ranking signal.
Constant Value: 2 (0x00000002)
AGGREGATION_SCORING_OUTER_RESULT_RANKING_SIGNAL
public static final int AGGREGATION_SCORING_OUTER_RESULT_RANKING_SIGNAL
Do not score the aggregation of joined documents. This is for the case where we want to perform a join, but keep the parent ranking signal.
Constant Value: 0 (0x00000000)
AGGREGATION_SCORING_RESULT_COUNT
public static final int AGGREGATION_SCORING_RESULT_COUNT
Score the aggregation of joined documents by counting the number of results.
Constant Value: 1 (0x00000001)
AGGREGATION_SCORING_SUM_RANKING_SIGNAL
public static final int AGGREGATION_SCORING_SUM_RANKING_SIGNAL
Score the aggregation of joined documents using the sum of ranking signal.
Constant Value: 5 (0x00000005)
QUALIFIED_ID
public static final String QUALIFIED_ID
A property expression referring to the combined package name, database name, namespace, and id of the document.
For instance, if a document with an id of "id1" exists in the namespace "ns" within the database "db" created by package "pkg", this would evaluate to "pkg$db/ns#id1".
Constant Value: "this.qualifiedId()"
Public methods
getAggregationScoringStrategy
public int getAggregationScoringStrategy ()
Gets the joined document list scoring strategy.
The default scoring strategy is AGGREGATION_SCORING_OUTER_RESULT_RANKING_SIGNAL,
which specifies that the score of the outer parent document will be used.
getChildPropertyExpression
public String getChildPropertyExpression ()
The property expression that is used to get values from child documents, returned from the nested search. These values are then used to match them to parent documents. These are analogous to foreign keys.
| Returns | |
|---|---|
String |
the property expression to match in the child documents.
This value cannot be null. |
See also:
getMaxJoinedResultCount
public int getMaxJoinedResultCount ()
Returns the max amount of SearchResult objects that will be joined to the parent
document, with a default of 10 SearchResults.
| Returns | |
|---|---|
int |
|
getNestedQuery
public String getNestedQuery ()
Returns the query to run on the joined documents.
| Returns | |
|---|---|
String |
This value cannot be null. |
getNestedSearchSpec
public SearchSpec getNestedSearchSpec ()
Returns the search spec used to retrieve the joined documents.
If Builder#setNestedSearch is never called, this will return a SearchSpec
with all default values. This will match every document, as the nested search query will be
"" and no schema will be filtered out.
| Returns | |
|---|---|
SearchSpec |
This value cannot be null. |
Content and code samples on this page are subject to the licenses described in the Content License. Java and OpenJDK are trademarks or registered trademarks of Oracle and/or its affiliates.
Last updated 2023-02-08 UTC.