Options
All
  • Public
  • Public/Protected
  • All
Menu

Module "MiniSearch"

Index

Type aliases

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>: { extractField?: undefined | ((document: T, fieldName: string) => string); fields: string[]; idField?: undefined | string; processTerm?: undefined | ((term: string, fieldName?: undefined | 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 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 processTerm?: undefined | ((term: string, fieldName?: undefined | 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.

  • 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 resuts would only contain the id field.

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

SearchOptions

SearchOptions: { boost?: undefined | {}; boostDocument?: undefined | ((documentId: any, term: string) => number); combineWith?: undefined | string; fields?: string[]; filter?: undefined | ((result: SearchResult) => boolean); fuzzy?: boolean | number | ((term: string, index: number, terms: string[]) => boolean | number); prefix?: boolean | ((term: string, index: number, terms: string[]) => boolean); processTerm?: undefined | ((term: 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 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) => 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 should return a boosting factor.

  • 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 mazimum 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.

    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 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 | 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

Generated using TypeDoc