JoinSpec


public final class JoinSpec
extends Object implements Parcelable

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 "this.qualifiedId()", which refers to the document's combined package, database, namespace, and id.

Note that in order for perform the join, the property referred to by getChildPropertyExpression() has to be a property with AppSearchSchema.StringPropertyConfig.getJoinableValueType set to AppSearchSchema.StringPropertyConfig.JOINABLE_VALUE_TYPE_QUALIFIED_ID. Otherwise no documents will be joined to any SearchResult.

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