Pacote
    Preparing search index...

    Interface Options<Document, SummaryField, IndexField>

    Configuration options for creating a search index.

    interface Options<
        Document extends Record<string, unknown>,
        SummaryField extends keyof Document = keyof Document,
        IndexField extends keyof Document = keyof Document,
    > {
        errorRate?: number;
        fields: Record<IndexField, number> | IndexField[];
        ngrams?: number;
        preprocess?: PreprocessFunction<Document, IndexField>;
        seed?: number;
        stemmer?: StemmerFunction;
        stopwords?: StopwordsFunction;
        summary: SummaryField[];
        termFrequencyBuckets?: number[];
        tokenizer?: TokenizerFunction;
    }

    Type Parameters

    • Document extends Record<string, unknown>

      The type of document being indexed.

    • SummaryField extends keyof Document = keyof Document

      The document keys that can be returned in search results.

    • IndexField extends keyof Document = keyof Document

      The document keys to be indexed for searching.

    Index
    errorRate?: number

    Determines the desired error rate. A lower number yields more reliable results but makes the index larger. The value defaults to 0.0001 (or 0.01%).

    fields: Record<IndexField, number> | IndexField[]

    The fields to index, provided as an array or as a record of field keys and weight values.

    ngrams?: number

    Indexes n-grams beyond the single text tokens. A value of 2 indexes digrams, a value of 3 indexes digrams and trigrams, and so forth. This allows seaching the index for simple phrases (a phrase search is entered "between quotes"). Indexing n-grams will increase the size of the generated indices roughly by a factor of n. Default value is 1 (no n-grams are indexed).

    Preprocessing function, executed before all others. The function serialises each field as a string and optionally process it before indexing. For example, you might use this function to strip HTML from a field value. By default, this class simply converts the field value into a string.

    seed?: number

    Hash seed to use in Ribbon filters, defaults to 0x00c0ffee.

    stemmer?: StemmerFunction

    Allows plugging in a custom stemming function. By default, this class does not change text tokens.

    stopwords?: StopwordsFunction

    Filters tokens so that words that are too short or too common may be excluded from the index. By default, no stopwords are excluded.

    summary: SummaryField[]

    Determines which fields in the document can be stored in the index and returned as a search result.

    termFrequencyBuckets?: number[]

    Optimises storage by grouping indexed terms into buckets according to term frequency in a document. Defaults to [1, 2, 3, 4, 8, 16, 32, 64].

    tokenizer?: TokenizerFunction

    Allows a custom tokenizer function. By default content is transformed to lowercase, split at every whitespace or hyphen, and stripped of any non-word (A-Z, 0-9, and _) characters.