# Fts5

Artifact: [androidx.room3:room3-common](https://developer.android.com/jetpack/androidx/releases/room3) [View Source](https://cs.android.com/search?q=file:androidx/room3/Fts5.kt+class:androidx.room3.Fts5) Added in [3.0.0](https://developer.android.com/jetpack/androidx/releases/room3#3.0.0)

*** ** * ** ***

Common/AllAndroid/JVMNative/C/iOSJavaScript
- Cmn

  ```
  @Target(allowedTargets = [AnnotationTarget.CLASS])
  @Retention(value = AnnotationRetention.BINARY)
  annotation Fts5
  ```

*** ** * ** ***

Marks an `https://developer.android.com/reference/kotlin/androidx/room3/Entity` annotated class as a FTS5 entity. This class will have a mapping SQLite FTS5 table in the database.

[FTS5](https://www.sqlite.org/fts5.html) is a SQLite virtual table module that allows full-text searches to be performed on a set of documents.

An FTS entity table always has a column named `rowid` that is the equivalent of an `INTEGER PRIMARY KEY`. Therefore, an FTS entity can only have a single property annotated with `https://developer.android.com/reference/kotlin/androidx/room3/PrimaryKey`, it must be named `rowid` and must be of `INTEGER` affinity. The property can be optionally omitted in the class but can still be used in queries.

All properties in an FTS entity are of `TEXT` affinity, except the 'rowid' property.

Example:

```kotlin
@Entity
@Fts5
data class Mail (
  @PrimaryKey
  @ColumnInfo(name = "rowid")
  val rowId: Long,
  val subject: String,
  val body: String
)
```

**Warning** : The availability of FTS5 is based on the driver used for the database. For Android specifically the `https://developer.android.com/reference/kotlin/androidx/sqlite/driver/bundled/BundledSQLiteDriver` supports FTS5.

| See also |
|---|---|
| `https://developer.android.com/reference/kotlin/androidx/room3/Entity` |   |
| `https://developer.android.com/reference/kotlin/androidx/room3/Dao` |   |
| `https://developer.android.com/reference/kotlin/androidx/room3/Database` |   |
| `https://developer.android.com/reference/kotlin/androidx/room3/PrimaryKey` |   |
| `https://developer.android.com/reference/kotlin/androidx/room3/ColumnInfo` |   |

## Summary

| ### Public constructors |
|---|---|
| `https://developer.android.com/reference/kotlin/androidx/room3/Fts5#Fts5(kotlin.String,kotlin.Array,kotlin.reflect.KClass,kotlin.String,kotlin.IntArray,kotlin.Boolean,androidx.room3.FtsOptions.Detail,kotlin.Array)( tokenizer: https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-string/index.html, tokenizerArgs: https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-array/index.html<https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-string/index.html>, contentEntity: https://kotlinlang.org/api/core/kotlin-stdlib/kotlin.reflect/-k-class/index.html<*>, contentRowId: https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-string/index.html, prefix: https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-int-array/index.html, hasColumnSize: https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-boolean/index.html, detail: https://developer.android.com/reference/kotlin/androidx/room3/FtsOptions.Detail, notIndexed: https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-array/index.html<https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-string/index.html> )` | Cmn |

| ### Public properties |
|---|---|---|
| `https://kotlinlang.org/api/core/kotlin-stdlib/kotlin.reflect/-k-class/index.html<*>` | `https://developer.android.com/reference/kotlin/androidx/room3/Fts5#contentEntity()` The external content entity who's mapping table will be used as content for the FTS table. | Cmn |
| `https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-string/index.html` | `https://developer.android.com/reference/kotlin/androidx/room3/Fts5#contentRowId()` The column name to be used as 'content_rowid'. | Cmn |
| `https://developer.android.com/reference/kotlin/androidx/room3/FtsOptions.Detail` | `https://developer.android.com/reference/kotlin/androidx/room3/Fts5#detail()` The 'detail' option affects what is stored in the virtual table. | Cmn |
| `https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-boolean/index.html` | `https://developer.android.com/reference/kotlin/androidx/room3/Fts5#hasColumnSize()` Enable or disable storing column sizes. | Cmn |
| `https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-array/index.html<https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-string/index.html>` | `https://developer.android.com/reference/kotlin/androidx/room3/Fts5#notIndexed()` The list of column names on the FTS table that won't be indexed. | Cmn |
| `https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-int-array/index.html` | `https://developer.android.com/reference/kotlin/androidx/room3/Fts5#prefix()` The list of prefix sizes to index. | Cmn |
| `https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-string/index.html` | `https://developer.android.com/reference/kotlin/androidx/room3/Fts5#tokenizer()` The tokenizer to be used in the FTS table. | Cmn |
| `https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-array/index.html<https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-string/index.html>` | `https://developer.android.com/reference/kotlin/androidx/room3/Fts5#tokenizerArgs()` Optional arguments to configure the defined tokenizer. | Cmn |

## Public constructors

### Fts5

Cmn Added in [3.0.0](https://developer.android.com/jetpack/androidx/releases/room3#3.0.0)

```
Fts5(
    tokenizer: String = TOKENIZER_UNICODE61,
    tokenizerArgs: Array<String> = [],
    contentEntity: KClass<*> = Any::class,
    contentRowId: String = "",
    prefix: IntArray = [],
    hasColumnSize: Boolean = true,
    detail: FtsOptions.Detail = FtsOptions.Detail.FULL,
    notIndexed: Array<String> = []
)
```

## Public properties

### contentEntity

Cmn

```
val contentEntity: KClass<*>
```

The external content entity who's mapping table will be used as content for the FTS table.

Declaring this value makes the mapping FTS table of this entity operate in "external content" mode. In such mode the FTS table does not store its own content but instead uses the data in the entity mapped table defined in this value. This option allows FTS5 to forego storing the text being indexed which can be used to achieve significant space savings.

In "external mode" the content table and the FTS table need to be synced. Room will create the necessary triggers to keep the tables in sync. Therefore, all write operations should be performed against the content entity table and not the FTS table.

The content sync triggers created by Room will be removed before migrations are executed and are re-created once migrations are complete. This prevents the triggers from interfering with migrations but means that if data needs to be migrated then write operations might need to be done in both the FTS and content tables.

See the [External Content FTS5 Tables](https://www.sqlite.org/fts5.html#external_content_tables) documentation for details.

| Returns |
|---|---|
| `https://kotlinlang.org/api/core/kotlin-stdlib/kotlin.reflect/-k-class/index.html<*>` | The external content entity. |

### contentRowId

Cmn

```
val contentRowId: String
```

The column name to be used as 'content_rowid'.

Declaring this value without setting `https://developer.android.com/reference/kotlin/androidx/room3/Fts5#(kotlin.String,kotlin.Array,kotlin.reflect.KClass,kotlin.String,kotlin.IntArray,kotlin.Boolean,androidx.room3.FtsOptions.Detail,kotlin.Array)` is an error.

For details, see the [content_rowid= option documentation](https://www.sqlite.org/fts5.html#external_content_tables).

| Returns |
|---|---|
| `https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-string/index.html` | The column name to be used as 'content_rowid'. |

### detail

Cmn

```
val detail: FtsOptions.Detail
```

The 'detail' option affects what is stored in the virtual table.

Using values other than `https://developer.android.com/reference/kotlin/androidx/room3/FtsOptions.Detail#FULL` will reduce the space consumed but will also affect the FTS capabilities and efficiency. The default value is `https://developer.android.com/reference/kotlin/androidx/room3/FtsOptions.Detail#FULL`.

For details, see the [detail= option documentation](https://www.sqlite.org/fts5.html#the_detail_option).

| Returns |
|---|---|
| `https://developer.android.com/reference/kotlin/androidx/room3/FtsOptions.Detail` | The 'detail' option. |

### hasColumnSize

Cmn

```
val hasColumnSize: Boolean
```

Enable or disable storing column sizes. Defaults to `true`.

For details, see the [columnsize= option documentation](https://www.sqlite.org/fts5.html#the_columnsize_option).

| Returns |
|---|---|
| `https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-boolean/index.html` | The 'columnsize' option. |

### notIndexed

Cmn

```
val notIndexed: Array<String>
```

The list of column names on the FTS table that won't be indexed.

For details, see the [UNINDEXED column option documentation](https://www.sqlite.org/fts5.html#the_unindexed_column_option).

| Returns |
|---|---|
| `https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-array/index.html<https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-string/index.html>` | A list of column names that will not be indexed by the FTS extension. |

### prefix

Cmn

```
val prefix: IntArray
```

The list of prefix sizes to index.

For details, [the prefix= option documentation](https://www.sqlite.org/fts5.html#prefix_indexes).

| Returns |
|---|---|
| `https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-int-array/index.html` | A list of non-zero positive prefix sizes to index. |

### tokenizer

Cmn

```
val tokenizer: String
```

The tokenizer to be used in the FTS table.

The default value is `https://developer.android.com/reference/kotlin/androidx/room3/FtsOptions#TOKENIZER_UNICODE61()`. Tokenizer arguments can be defined with `https://developer.android.com/reference/kotlin/androidx/room3/Fts5#(kotlin.String,kotlin.Array,kotlin.reflect.KClass,kotlin.String,kotlin.IntArray,kotlin.Boolean,androidx.room3.FtsOptions.Detail,kotlin.Array)`.

If a custom tokenizer is used, the tokenizer and its arguments are not verified at compile time.

For details, see [SQLite tokenizers documentation](https://www.sqlite.org/fts5.html#tokenizers)

| Returns |
|---|---|
| `https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-string/index.html` | The tokenizer to use on the FTS table. Built-in available tokenizers are `https://developer.android.com/reference/kotlin/androidx/room3/FtsOptions#TOKENIZER_UNICODE61()`, `https://developer.android.com/reference/kotlin/androidx/room3/FtsOptions#TOKENIZER_PORTER()`, `https://developer.android.com/reference/kotlin/androidx/room3/FtsOptions#TOKENIZER_ASCII()` and `https://developer.android.com/reference/kotlin/androidx/room3/FtsOptions#TOKENIZER_TRIGRAM()`. |

| See also |
|---|---|
| `https://developer.android.com/reference/kotlin/androidx/room3/Fts5#(kotlin.String,kotlin.Array,kotlin.reflect.KClass,kotlin.String,kotlin.IntArray,kotlin.Boolean,androidx.room3.FtsOptions.Detail,kotlin.Array)` |   |

### tokenizerArgs

Cmn

```
val tokenizerArgs: Array<String>
```

Optional arguments to configure the defined tokenizer.

Tokenizer arguments are a white-space series of values represented on this annotation value list. For example, `tokenizerArgs = ["separators", "'.'"]` defines the dot character as an additional separator when using the `https://developer.android.com/reference/kotlin/androidx/room3/FtsOptions#TOKENIZER_UNICODE61()` tokenizer.

The available arguments that can be defined depend on the tokenizer defined, see the [SQLite tokenizers documentation](https://www.sqlite.org/fts5.html#tokenizers) for details.

| Returns |
|---|---|
| `https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-array/index.html<https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-string/index.html>` | A list of tokenizer arguments strings. |