# Fts4

Artifact: [androidx.room3:room3-common](https://developer.android.com/jetpack/androidx/releases/room3) [View Source](https://cs.android.com/search?q=file:androidx/room3/Fts4.kt+class:androidx.room3.Fts4) 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 Fts4
  ```

*** ** * ** ***

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

FTS3 and FTS4 (https://www.sqlite.org/fts3.html) are SQLite virtual table modules 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 for the 'rowid' and 'languageid' properties.

Example:

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

| 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/Fts4#Fts4(kotlin.String,kotlin.Array,kotlin.reflect.KClass,kotlin.String,androidx.room3.FtsOptions.MatchInfo,kotlin.Array,kotlin.IntArray,androidx.room3.FtsOptions.Order)( 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<*>, languageId: https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-string/index.html, matchInfo: https://developer.android.com/reference/kotlin/androidx/room3/FtsOptions.MatchInfo, notIndexed: https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-array/index.html<https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-string/index.html>, prefix: https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-int-array/index.html, order: https://developer.android.com/reference/kotlin/androidx/room3/FtsOptions.Order )` | Cmn |

| ### Public properties |
|---|---|---|
| `https://kotlinlang.org/api/core/kotlin-stdlib/kotlin.reflect/-k-class/index.html<*>` | `https://developer.android.com/reference/kotlin/androidx/room3/Fts4#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/Fts4#languageId()` The column name to be used as 'languageid'. | Cmn |
| `https://developer.android.com/reference/kotlin/androidx/room3/FtsOptions.MatchInfo` | `https://developer.android.com/reference/kotlin/androidx/room3/Fts4#matchInfo()` The FTS version used to store text matching information. | 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/Fts4#notIndexed()` The list of column names on the FTS table that won't be indexed. | Cmn |
| `https://developer.android.com/reference/kotlin/androidx/room3/FtsOptions.Order` | `https://developer.android.com/reference/kotlin/androidx/room3/Fts4#order()` The preferred 'rowid' order of the FTS table. | Cmn |
| `https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-int-array/index.html` | `https://developer.android.com/reference/kotlin/androidx/room3/Fts4#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/Fts4#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/Fts4#tokenizerArgs()` Optional arguments to configure the defined tokenizer. | Cmn |

## Public constructors

### Fts4

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

```
Fts4(
    tokenizer: String = TOKENIZER_SIMPLE,
    tokenizerArgs: Array<String> = [],
    contentEntity: KClass<*> = Any::class,
    languageId: String = "",
    matchInfo: FtsOptions.MatchInfo = FtsOptions.MatchInfo.FTS4,
    notIndexed: Array<String> = [],
    prefix: IntArray = [],
    order: FtsOptions.Order = FtsOptions.Order.ASC
)
```

## 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 FTS4 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 FTS4 Tables](https://www.sqlite.org/fts3.html#_external_content_fts4_tables_) documentation for details.

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

### languageId

Cmn

```
val languageId: String
```

The column name to be used as 'languageid'.

Allows the FTS4 extension to use the defined column name to specify the language stored in each row. When this is defined a property of type `INTEGER` with the same name must exist in the class.

FTS queries are affected by defining this option, see [the languageid= option documentation](https://www.sqlite.org/fts3.html#the_languageid_option) for details.

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

### matchInfo

Cmn

```
val matchInfo: FtsOptions.MatchInfo
```

The FTS version used to store text matching information.

The default value is `https://developer.android.com/reference/kotlin/androidx/room3/FtsOptions.MatchInfo#FTS4`. Disk space consumption can be reduced by setting this option to FTS3, see [the matchinfo= option documentation](https://www.sqlite.org/fts3.html#the_matchinfo_option) for details.

| Returns |
|---|---|
| `https://developer.android.com/reference/kotlin/androidx/room3/FtsOptions.MatchInfo` | The match info version, either `https://developer.android.com/reference/kotlin/androidx/room3/FtsOptions.MatchInfo#FTS4` or `https://developer.android.com/reference/kotlin/androidx/room3/FtsOptions.MatchInfo#FTS3`. |

### notIndexed

Cmn

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

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

For details, see the [notindexed= option documentation](https://www.sqlite.org/fts3.html#the_notindexed_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. |

### order

Cmn

```
val order: FtsOptions.Order
```

The preferred 'rowid' order of the FTS table.

The default value is `https://developer.android.com/reference/kotlin/androidx/room3/FtsOptions.Order#ASC`. If many queries run against the FTS table use `ORDER BY row DESC` then it may improve performance to set this option to `https://developer.android.com/reference/kotlin/androidx/room3/FtsOptions.Order#DESC`, enabling the FTS module to store its data in a way that optimizes returning results in descending order by `rowid`.

| Returns |
|---|---|
| `https://developer.android.com/reference/kotlin/androidx/room3/FtsOptions.Order` | The preferred order, either `https://developer.android.com/reference/kotlin/androidx/room3/FtsOptions.Order#ASC` or `https://developer.android.com/reference/kotlin/androidx/room3/FtsOptions.Order#DESC`. |

### prefix

Cmn

```
val prefix: IntArray
```

The list of prefix sizes to index.

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

| 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_SIMPLE()`. Tokenizer arguments can be defined with `https://developer.android.com/reference/kotlin/androidx/room3/Fts4#(kotlin.String,kotlin.Array,kotlin.reflect.KClass,kotlin.String,androidx.room3.FtsOptions.MatchInfo,kotlin.Array,kotlin.IntArray,androidx.room3.FtsOptions.Order)`.

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

For details, see [SQLite tokernizers documentation](https://www.sqlite.org/fts3.html#tokenizer)

| 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_SIMPLE()`, `https://developer.android.com/reference/kotlin/androidx/room3/FtsOptions#TOKENIZER_PORTER()` and `https://developer.android.com/reference/kotlin/androidx/room3/FtsOptions#TOKENIZER_UNICODE61()`. |

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

### tokenizerArgs

Cmn

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

Optional arguments to configure the defined tokenizer.

Tokenizer arguments consist of an argument name, followed by an "=" character, followed by the option value. For example, `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/fts3.html#tokenizer) 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. |