@RequiresFeature(enforcement = "androidx.appsearch.app.Features#isFeatureSupported", name = Features.JOIN_SPEC_AND_QUALIFIED_ID)
@Document(name = "builtin:Nickname")
@ExperimentalAppSearchApi
class Nickname


Represents an nickname document for another GenericDocument.

A nickname document has an indexed string field and a qualified id type that allows us to add aliases to the document referenced to by the qualified id type. This way we can match that document by a string that does not even appear in the original document.

Example: Adding a nickname "config" to the settings MobileApplication document

// Assume that the MobileApplication schema and Nickname schema have been set and settings is
// indexed as a MobileApplication document.

// Create the qualified ID for a settings app.
String settingsAppQualifiedId = DocumentIdUtil.createQualifiedId(
    "android",
    "apps-db",
    "apps",
    "com.android.settings");

// Index the "config" nickname document, linking it to the document for settings.
Nickname configNickname = new Nickname.Builder("configNs", "configId", settingsAppQualifiedId)
    .setAlternateNames(Collections.singletonList("config"))
    .build();

AppSearchBatchResult<String, Void> putResult = appSearchSession.putAsync(
    new PutDocumentsRequest.Builder().addDocuments(configNickname).build()).get();

// Assert the nickname has been indexed
if (!putResult.isSuccess()) {
   return;
}

SearchSpec nestedSearchSpec = new SearchSpec.Builder()
    .addFilterDocumentClass(Nickname.class)
    .build();

JoinSpec joinSpec = new JoinSpec.Builder("referencedQualifiedId")
    .setNestedSearch("config", nestedSearchSpec)
    .build();

SearchSpec searchSpec = new SearchSpec.Builder()
    .addFilterDocumentClass(MobileApplication.class)
    .setJoinSpec(joinSpec)
    .setRankingStrategy("len(this.childrenRankingSignals()) > 0")
    .build();

SearchResults searchResults = appSearchSession.search("", searchSpec);

// This will contain one SearchResult for the settings MobileApplication document.
List<SearchResult> results = searchResults.getNextPageAsync().get();
See also
JoinSpec

Summary

Nested types

Builder for Nickname.

Public functions

Boolean
equals(o: Any!)
(Mutable)List<String!>

Returns alternative names for a document.

String

Returns the appsearch document id for this item.

String

Returns the namespace (or logical grouping) for this item.

String

Returns the qualified id of the document these nicknames are for.

Int

Public functions

equals

fun equals(o: Any!): Boolean

getAlternateNames

Added in 1.2.0-alpha01
fun getAlternateNames(): (Mutable)List<String!>

Returns alternative names for a document. These are indexed. For example, you might have the alternative name "pay" for a wallet app.

getId

Added in 1.2.0-alpha01
fun getId(): String

Returns the appsearch document id for this item.

getNamespace

Added in 1.2.0-alpha01
fun getNamespace(): String

Returns the namespace (or logical grouping) for this item.

getReferencedQualifiedId

Added in 1.2.0-alpha01
fun getReferencedQualifiedId(): String

Returns the qualified id of the document these nicknames are for.

A qualified id is a string generated by package, database, namespace, and document id.

See also
DocumentIdUtil

hashCode

fun hashCode(): Int