Options
All
  • Public
  • Public/Protected
  • All
Menu

Module "MiniSearch"

Index

Type aliases

AutoVacuumOptions

AutoVacuumOptions: VacuumOptions & VacuumConditions

Options to control auto vacuum behavior. When discarding a document with MiniSearch.discard, a vacuuming operation is automatically started if the dirtCount and dirtFactor are above the minDirtCount and minDirtFactor thresholds defined by this configuration. See VacuumConditions for details on these.

Also, batchSize and batchWait can be specified, controlling batching behavior (see VacuumOptions).

BM25Params

BM25Params: { b: number; d: number; k: number }

Parameters of the BM25+ scoring algorithm. Customizing these is almost never necessary, and finetuning them requires an understanding of the BM25 scoring model.

Some information about BM25 (and BM25+) can be found at these links:

Type declaration

  • b: number

    Length normalization impact.

    Recommended values are around 0.75. Higher values increase the weight that field length has on scoring. Setting this to 0 (not recommended) means that the field length has no effect on scoring. Negative values are invalid. Defaults to 0.7.

  • d: number

    BM25+ frequency normalization lower bound (usually called δ).

    Recommended values are between 0.5 and 1. Increasing this parameter increases the minimum relevance of one occurrence of a search term regardless of its (possibly very long) field length. Negative values are invalid. Defaults to 0.5.

  • k: number

    Term frequency saturation point.

    Recommended values are between 1.2 and 2. Higher values increase the difference in score between documents with higher and lower term frequencies. Setting this to 0 or a negative value is invalid. Defaults to 1.2

MatchInfo

MatchInfo: {}

Match information for a search result. It is a key-value object where keys are terms that matched, and values are the list of fields that the term was found in.

Type declaration

  • [term: string]: string[]

Options

Options<T>: { autoSuggestOptions?: SearchOptions; autoVacuum?: boolean | AutoVacuumOptions; extractField?: undefined | ((document: T, fieldName: string) => string); fields: string[]; idField?: undefined | string; logger?: undefined | ((level: LogLevel, message: string, code?: undefined | string) => void); processTerm?: undefined | ((term: string, fieldName?: undefined | string) => string | string[] | null | undefined | false); searchOptions?: SearchOptions; storeFields?: string[]; tokenize?: undefined | ((text: string, fieldName?: undefined | string) => string[]) }

Configuration options passed to the MiniSearch constructor

Type parameters

  • T = any

    The type of documents being indexed.

Type declaration

  • Optional autoSuggestOptions?: SearchOptions

    Default auto suggest options (see the SearchOptions type and the MiniSearch.autoSuggest method for details)

  • Optional autoVacuum?: boolean | AutoVacuumOptions

    If true (the default), vacuuming is performed automatically as soon as MiniSearch.discard is called a certain number of times, cleaning up obsolete references from the index. If false, no automatic vacuuming is performed. Custom settings controlling auto vacuuming thresholds, as well as batching behavior, can be passed as an object (see the AutoVacuumOptions type).

  • Optional extractField?: undefined | ((document: T, fieldName: string) => string)

    Function used to extract the value of each field in documents. By default, the documents are assumed to be plain objects with field names as keys, but by specifying a custom extractField function one can completely customize how the fields are extracted.

    The function takes as arguments the document, and the name of the field to extract from it. It should return the field value as a string.

  • fields: string[]

    Names of the document fields to be indexed.

  • Optional idField?: undefined | string

    Name of the ID field, uniquely identifying a document.

  • Optional logger?: undefined | ((level: LogLevel, message: string, code?: undefined | string) => void)

    Function called to log messages. Arguments are a log level ('debug', 'info', 'warn', or 'error'), a log message, and an optional string code that identifies the reason for the log.

    The default implementation uses console, if defined.

  • Optional processTerm?: undefined | ((term: string, fieldName?: undefined | string) => string | string[] | null | undefined | false)

    Function used to process a term before indexing or search. This can be used for normalization (such as stemming). By default, terms are downcased, and otherwise no other normalization is performed.

    The function takes as arguments a term to process, and the name of the field it comes from. It should return the processed term as a string, or a falsy value to reject the term entirely.

    It can also return an array of strings, in which case each string in the returned array is indexed as a separate term.

  • Optional searchOptions?: SearchOptions

    Default search options (see the SearchOptions type and the MiniSearch.search method for details)

  • Optional storeFields?: string[]

    Names of fields to store, so that search results would include them. By default none, so results would only contain the id field.

  • Optional tokenize?: undefined | ((text: string, fieldName?: undefined | string) => string[])

Query

Query: QueryCombination | string

Search query expression, either a query string or an expression tree combining several queries with a combination of AND or OR.

QueryCombination

QueryCombination: SearchOptions & { queries: Query[] }

SearchOptions

SearchOptions: { bm25?: BM25Params; boost?: undefined | {}; boostDocument?: undefined | ((documentId: any, term: string, storedFields?: Record<string, unknown>) => number); combineWith?: undefined | string; fields?: string[]; filter?: undefined | ((result: SearchResult) => boolean); fuzzy?: boolean | number | ((term: string, index: number, terms: string[]) => boolean | number); maxFuzzy?: undefined | number; prefix?: boolean | ((term: string, index: number, terms: string[]) => boolean); processTerm?: undefined | ((term: string) => string | string[] | null | undefined | false); tokenize?: undefined | ((text: string) => string[]); weights?: undefined | { fuzzy: number; prefix: number } }

Search options to customize the search behavior.

Type declaration

  • Optional bm25?: BM25Params

    BM25+ algorithm parameters. Customizing these is almost never necessary, and finetuning them requires an understanding of the BM25 scoring model. In most cases, it is best to omit this option to use defaults, and instead use boosting to tweak scoring for specific use cases.

  • Optional boost?: undefined | {}

    Key-value object of field names to boosting values. By default, fields are assigned a boosting factor of 1. If one assigns to a field a boosting value of 2, a result that matches the query in that field is assigned a score twice as high as a result matching the query in another field, all else being equal.

  • Optional boostDocument?: undefined | ((documentId: any, term: string, storedFields?: Record<string, unknown>) => number)

    Function to calculate a boost factor for documents. It takes as arguments the document ID, and a term that matches the search in that document, and the value of the stored fields for the document (if any). It should return a boosting factor: a number higher than 1 increases the computed score, a number lower than 1 decreases the score, and a falsy value skips the search result completely.

  • Optional combineWith?: undefined | string

    The operand to combine partial results for each term. By default it is "OR", so results matching any of the search terms are returned by a search. If "AND" is given, only results matching all the search terms are returned by a search.

  • Optional fields?: string[]

    Names of the fields to search in. If omitted, all fields are searched.

  • Optional filter?: undefined | ((result: SearchResult) => boolean)

    Function used to filter search results, for example on the basis of stored fields. It takes as argument each search result and should return a boolean to indicate if the result should be kept or not.

  • Optional fuzzy?: boolean | number | ((term: string, index: number, terms: string[]) => boolean | number)

    Controls whether to perform fuzzy search. It can be a simple boolean, or a number, or a function.

    If a boolean is given, fuzzy search with a default fuzziness parameter is performed if true.

    If a number higher or equal to 1 is given, fuzzy search is performed, with a maximum edit distance (Levenshtein) equal to the number.

    If a number between 0 and 1 is given, fuzzy search is performed within a maximum edit distance corresponding to that fraction of the term length, approximated to the nearest integer. For example, 0.2 would mean an edit distance of 20% of the term length, so 1 character in a 5-characters term. The calculated fuzziness value is limited by the maxFuzzy option, to prevent slowdown for very long queries.

    If a function is passed, the function is called upon search with a search term, a positional index of that term in the tokenized search query, and the tokenized search query. It should return a boolean or a number, with the meaning documented above.

  • Optional maxFuzzy?: undefined | number

    Controls the maximum fuzziness when using a fractional fuzzy value. This is set to 6 by default. Very high edit distances usually don't produce meaningful results, but can excessively impact search performance.

  • Optional prefix?: boolean | ((term: string, index: number, terms: string[]) => boolean)

    Controls whether to perform prefix search. It can be a simple boolean, or a function.

    If a boolean is passed, prefix search is performed if true.

    If a function is passed, it is called upon search with a search term, the positional index of that search term in the tokenized search query, and the tokenized search query. The function should return a boolean to indicate whether to perform prefix search for that search term.

  • Optional processTerm?: undefined | ((term: string) => string | string[] | null | undefined | false)

    Function to process or normalize terms in the search query. By default, the same term processor used for indexing is used also for search.

  • Optional tokenize?: undefined | ((text: string) => string[])

    Function to tokenize the search query. By default, the same tokenizer used for indexing is used also for search.

  • Optional weights?: undefined | { fuzzy: number; prefix: number }

    Relative weights to assign to prefix search results and fuzzy search results. Exact matches are assigned a weight of 1.

SearchResult

SearchResult: { id: any; match: MatchInfo; score: number; terms: string[] }

Type of the search results. Each search result indicates the document ID, the terms that matched, the match information, the score, and all the stored fields.

Type declaration

  • [key: string]: any

    Stored fields

  • id: any

    The document ID

  • match: MatchInfo

    Match information, see MatchInfo

  • score: number

    Score of the search results

  • terms: string[]

    List of terms that matched

Suggestion

Suggestion: { score: number; suggestion: string; terms: string[] }

The type of auto-suggestions

Type declaration

  • score: number

    Score for the suggestion

  • suggestion: string

    The suggestion

  • terms: string[]

    Suggestion as an array of terms

VacuumConditions

VacuumConditions: { minDirtCount?: undefined | number; minDirtFactor?: undefined | number }

Sets minimum thresholds for dirtCount and dirtFactor that trigger an automatic vacuuming.

Type declaration

  • Optional minDirtCount?: undefined | number

    Minimum dirtCount (number of discarded documents since the last vacuuming) under which auto vacuum is not triggered. It defaults to 20.

  • Optional minDirtFactor?: undefined | number

    Minimum dirtFactor (proportion of discarded documents over the total) under which auto vacuum is not triggered. It defaults to 0.1.

VacuumOptions

VacuumOptions: { batchSize?: undefined | number; batchWait?: undefined | number }

Options to control vacuuming behavior.

Vacuuming cleans up document references made obsolete by MiniSearch.discard from the index. On large indexes, vacuuming is potentially costly, because it has to traverse the whole inverted index. Therefore, in order to dilute this cost so it does not negatively affects the application, vacuuming is performed in batches, with a delay between each batch. These options are used to configure the batch size and the delay between batches.

Type declaration

  • Optional batchSize?: undefined | number

    Size of each vacuuming batch (the number of terms in the index that will be traversed in each batch). Defaults to 1000.

  • Optional batchWait?: undefined | number

    Wait time between each vacuuming batch in milliseconds. Defaults to 10.

Generated using TypeDoc