# Nickname

Artifact: [androidx.appsearch:appsearch-builtin-types](https://developer.android.com/jetpack/androidx/releases/appsearch) [View Source](https://cs.android.com/search?q=file:androidx/appsearch/builtintypes/Nickname.java+class:androidx.appsearch.builtintypes.Nickname) Added in [1.2.0-alpha02](https://developer.android.com/jetpack/androidx/releases/appsearch#1.2.0-alpha02)

*** ** * ** ***


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

<br />

*** ** * ** ***

Represents an nickname document for another `https://developer.android.com/reference/kotlin/androidx/appsearch/app/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 `https://developer.android.com/reference/kotlin/androidx/appsearch/builtintypes/MobileApplication` document

```kotlin
// 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 |
|---|---|
| `https://developer.android.com/reference/kotlin/androidx/appsearch/app/JoinSpec` |   |

## Summary

| ### Nested types |
|---|
| `class https://developer.android.com/reference/kotlin/androidx/appsearch/builtintypes/Nickname.Builder` Builder for `https://developer.android.com/reference/kotlin/androidx/appsearch/builtintypes/Nickname`. |

| ### Public functions |
|---|---|
| `https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-boolean/index.html` | `https://developer.android.com/reference/kotlin/androidx/appsearch/builtintypes/Nickname#equals(java.lang.Object)(o: https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-any/index.html!)` |
| `(https://kotlinlang.org/api/core/kotlin-stdlib/kotlin.collections/-mutable-list/index.html)https://kotlinlang.org/api/core/kotlin-stdlib/kotlin.collections/-list/index.html<https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-string/index.html!>` | `https://developer.android.com/reference/kotlin/androidx/appsearch/builtintypes/Nickname#getAlternateNames()()` Returns alternative names for a document. |
| `https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-string/index.html` | `https://developer.android.com/reference/kotlin/androidx/appsearch/builtintypes/Nickname#getId()()` Returns the appsearch document id for this item. |
| `https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-string/index.html` | `https://developer.android.com/reference/kotlin/androidx/appsearch/builtintypes/Nickname#getNamespace()()` Returns the namespace (or logical grouping) for this item. |
| `https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-string/index.html` | `https://developer.android.com/reference/kotlin/androidx/appsearch/builtintypes/Nickname#getReferencedQualifiedId()()` Returns the qualified id of the document these nicknames are for. |
| `https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-int/index.html` | `https://developer.android.com/reference/kotlin/androidx/appsearch/builtintypes/Nickname#hashCode()()` |

## Public functions

### equals

```
fun equals(o: Any!): Boolean
```

### getAlternateNames

Added in [1.2.0-alpha02](https://developer.android.com/jetpack/androidx/releases/appsearch#1.2.0-alpha02)

```
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-alpha02](https://developer.android.com/jetpack/androidx/releases/appsearch#1.2.0-alpha02)

```
fun getId(): String
```

Returns the appsearch document id for this item.

### getNamespace

Added in [1.2.0-alpha02](https://developer.android.com/jetpack/androidx/releases/appsearch#1.2.0-alpha02)

```
fun getNamespace(): String
```

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

### getReferencedQualifiedId

Added in [1.2.0-alpha02](https://developer.android.com/jetpack/androidx/releases/appsearch#1.2.0-alpha02)

```
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 |
|---|---|
| `https://developer.android.com/reference/kotlin/androidx/appsearch/util/DocumentIdUtil#createQualifiedId(java.lang.String,java.lang.String,androidx.appsearch.app.GenericDocument)` |   |

### hashCode

```
fun hashCode(): Int
```