Interface SearchIndexOptions<Document, ID>

Configuration options passed to the SearchIndex constructor

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

Type Parameters

  • Document = any

    The type of documents being indexed.

  • ID = any

    The type of id being indexed.

Properties

autoSuggestOptions?: SearchOptions<ID>

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

autoVacuum?: boolean | AutoVacuumOptions

If true (the default), vacuuming is performed automatically as soon as 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).

extractField?: ((document, fieldName) => 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.

Type declaration

    • (document, fieldName): 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.

      Parameters

      Returns string

fields: string[]

Names of the document fields to be indexed.

idField?: string

Name of the ID field, uniquely identifying a document.

logger?: ((level, message, code?) => 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.

Type declaration

    • (level, message, code?): 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.

      Parameters

      • level: LogLevel
      • message: string
      • Optional code: string

      Returns void

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

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.

Type declaration

    • (term, fieldName?): undefined | null | string | false | string[]
    • 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.

      Parameters

      • term: string
      • Optional fieldName: string

      Returns undefined | null | string | false | string[]

searchOptions?: SearchOptions<ID>

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

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.

tokenize?: ((text, fieldName?) => string[])

Type declaration

    • (text, fieldName?): string[]
    • Parameters

      • text: string
      • Optional fieldName: string

      Returns string[]

Generated using TypeDoc