Completes #4364 together with #4756, which did the Python side. ## Changes - `Index.fts()` / `FtsOptions` and `tokenize()` gain `analyzer` (`"text"` or `"code"`), `splitIdentifiers`, `splitOnNumerics`, `preserveOriginal` and `indexOperators`. All are optional, so existing indexes and calls behave as before. - Validation matches the Python SDK: `analyzer: "code"` with a `baseTokenizer` other than `"code"` or `"simple"` is rejected, `analyzer: "text"` with `baseTokenizer: "code"` is rejected, and turning on a code flag without the code analyzer is rejected. Passing a flag as `false` is always allowed. The checks live in one helper used by both `fts` and `tokenize`. - The option docs state the defaults (`analyzer: "code"` alone keeps identifiers whole; `splitOnNumerics` and `preserveOriginal` only matter with `splitIdentifiers: true`) and link the two Lance limitations noted on #4756 (lance#9674 and lance#9658). Shared presets can still include extra fields. For example, a preset can carry the index name for `createIndex()` alongside the analyzer options used by `Index.fts()` and `tokenize()`. ## Tests The Node tests check exact tokens from both the named index and standalone tokenization, whole identifiers, subword matches, shared presets and invalid combinations of known options. With the rebuilt native addon, the full local Jest run passed 2,045 tests across 37 suites, with 27 tests skipped. TypeScript checks, lint and API reference regeneration also passed. --------- Co-authored-by: Xuanwo <github@xuanwo.io>
4.4 KiB
@lancedb/lancedb • Docs
@lancedb/lancedb / FtsOptions
Interface: FtsOptions
Options to create a full text search index
Properties
analyzer?
optional analyzer: "code" | "text";
The analyzer family to use.
"code" selects the code analyzer, which is the same as
baseTokenizer: "code". "text" selects a text-family analyzer with the
selected baseTokenizer. When it is not set, the analyzer is inferred
from baseTokenizer.
"code" cannot be combined with a baseTokenizer other than "simple" or
"code", and "text" cannot be combined with baseTokenizer: "code".
asciiFolding?
optional asciiFolding: boolean;
whether to remove punctuation
baseTokenizer?
optional baseTokenizer: BaseTokenizer;
The tokenizer to use when building the index. The default is "simple".
The following tokenizers are available:
"simple" - Simple tokenizer. This tokenizer splits the text into tokens using whitespace and punctuation as a delimiter.
"whitespace" - Whitespace tokenizer. This tokenizer splits the text into tokens using whitespace as a delimiter.
"raw" - Raw tokenizer. This tokenizer does not split the text into tokens and indexes the entire text as a single token.
"code" - Code tokenizer. This tokenizer keeps snake_case and camelCase identifiers as single tokens.
"icu" - ICU dictionary-based word segmentation.
"icu/split" - ICU segmentation with simple-style delimiter splitting.
blockSize?
optional blockSize: 128 | 256;
Number of documents per compressed posting block.
The default is 128. Supported values are 128 and 256. A value of 256 uses the experimental FTS V3 format and may introduce breaking changes.
customStopWords?
optional customStopWords: string[];
Custom stop words that replace the built-in list for language.
This option only affects tokenization when removeStopWords is true.
undefined keeps the built-in language list. An empty array explicitly
replaces it with no stop words.
indexOperators?
optional indexOperators: boolean;
Index code operators such as ::, -> and !=.
The code analyzer default is false.
language?
optional language: string;
language for stemming and stop words
this is only used when stem or remove_stop_words is true
lowercase?
optional lowercase: boolean;
whether to lowercase tokens
maxTokenLength?
optional maxTokenLength: number;
maximum token length tokens longer than this length will be ignored
ngramMaxLength?
optional ngramMaxLength: number;
ngram max length
ngramMinLength?
optional ngramMinLength: number;
ngram min length
prefixOnly?
optional prefixOnly: boolean;
whether to only index the prefix of the token for ngram tokenizer
preserveOriginal?
optional preserveOriginal: boolean;
Also index the complete identifier next to its subwords.
The code analyzer default is true, but this only takes effect when
splitIdentifiers is true.
removeStopWords?
optional removeStopWords: boolean;
whether to remove stop words
splitIdentifiers?
optional splitIdentifiers: boolean;
Split code identifiers such as camelCase and snake_case into subwords.
Setting this to true requires the code analyzer. The default is false, so
analyzer: "code" alone keeps identifiers whole.
Note: with the default preserveOriginal, partial-identifier AND and
phrase queries on JSON columns can miss matches
(https://github.com/lance-format/lance/issues/9674). Spell phrase queries
with the same identifier boundaries as the indexed text
(https://github.com/lance-format/lance/issues/9658).
splitOnNumerics?
optional splitOnNumerics: boolean;
Split identifier subwords at letter and number boundaries, for example
utf8 into utf and 8.
The code analyzer default is true, but this only takes effect when
splitIdentifiers is true.
stem?
optional stem: boolean;
whether to stem tokens
withPosition?
optional withPosition: boolean;
Whether to build the index with positions. True by default. If set to false, the index will not store the positions of the tokens in the text, which will make the index smaller and faster to build, but will not support phrase queries.