Back to Redis

FT.SPELLCHECK

content/commands/ft.spellcheck.md

latest3.9 KB
Original Source

Perform spelling correction on a query, returning suggestions for misspelled terms

Examples

Required arguments

<details open> <summary><code>index</code></summary>

is index with the indexed terms.

</details> <details open> <summary><code>query</code></summary>

is search query.

</details>

See [Spellchecking]({{< relref "/develop/ai/search-and-query/advanced-concepts/spellcheck" >}}) for more details.

Optional arguments

<details open> <summary><code>TERMS</code></summary>

specifies an inclusion (INCLUDE) or exclusion (EXCLUDE) of a custom dictionary. To learn more about managing custom dictionaries, see [FT.DICTADD]({{< relref "commands/ft.dictadd/" >}}), [FT.DICTDEL]({{< relref "commands/ft.dictdel/" >}}), and [FT.DICTDUMP]({{< relref "commands/ft.dictdump/" >}}).

You can specify multiple inclusion and exclusion TERMS.

</details> <details open> <summary><code>DISTANCE</code></summary>

is maximum Levenshtein distance for spelling suggestions (default: 1, max: 4).

</details> <details open> <summary><code>DIALECT {dialect_version}</code></summary>

selects the dialect version under which to execute the query. If not specified, the query will execute under the default dialect version set during module initial loading or via [FT.CONFIG SET]({{< relref "commands/ft.config-set/" >}}) command.

</details>

Return

FT.SPELLCHECK returns an array reply, in which each element represents a misspelled term from the query. The misspelled terms are ordered by their order of appearance in the query. Each misspelled term, in turn, is a 3-element array consisting of the constant string TERM, the term itself and an array of suggestions for spelling corrections. Each element in the spelling corrections array consists of the score of the suggestion and the suggestion itself. The suggestions array, per misspelled term, is ordered in descending order by score. The score is calculated by dividing the number of documents in which the suggested term exists by the total number of documents in the index. Results can be normalized by dividing scores by the highest score.

Examples

<details open> <summary><b>Perform spelling correction on a query</b></summary>

{{< highlight bash >}} 127.0.0.1:6379> FT.SPELLCHECK idx held DISTANCE 2

    1. "TERM"
    2. "held"
        1. "0.66666666666666663"
        2. "hello"
        1. "0.33333333333333331"
        2. "help" {{< / highlight >}}
</details>

Redis Software and Redis Cloud compatibility

| Redis Software | Redis Cloud Flexible & Annual | Redis Cloud Free & Fixed | <span style="min-width: 9em; display: table-cell">Notes</span> | |:----------------------|:-----------------|:-----------------|:------| | <span title="Supported">✅ Supported</span> | <span title="Supported">✅ Supported</span> | <span title="Supported">✅ Supported</nobr></span> | |

Return information

{{< multitabs id="ft-spellcheck-return-info" tab1="RESP2" tab2="RESP3" >}}

One of the following:

  • [Array]({{< relref "/develop/reference/protocol-spec#arrays" >}}) of spell check results for each term.
  • [Simple error reply]({{< relref "/develop/reference/protocol-spec#simple-errors" >}}) in these cases: no such index.

-tab-sep-

One of the following:

  • [Map]({{< relref "/develop/reference/protocol-spec#maps" >}}) with a results key containing spell check results for each term.
  • [Simple error reply]({{< relref "/develop/reference/protocol-spec#simple-errors" >}}) in these cases: no such index.

{{< /multitabs >}}

See also

[FT.CONFIG SET]({{< relref "commands/ft.config-set/" >}}) | [FT.DICTADD]({{< relref "commands/ft.dictadd/" >}}) | [FT.DICTDEL]({{< relref "commands/ft.dictdel/" >}}) | [FT.DICTDUMP]({{< relref "commands/ft.dictdump/" >}})

  • [Spellchecking]({{< relref "/develop/ai/search-and-query/advanced-concepts/spellcheck" >}})
  • [RediSearch]({{< relref "/develop/ai/search-and-query/" >}})