Class: Builder

lunr.Builder

new Builder()

lunr.Builder performs indexing on a set of documents and returns instances of lunr.Index ready for querying.

All configuration of the index is done via the builder, the fields to index, the document reference, the text processing pipeline and document scoring parameters are all set on the builder before indexing.

Properties:
Name Type Description
_ref string

Internal reference to the document reference field.

_fields Array.<string>

Internal reference to the document fields to index.

invertedIndex object

The inverted index maps terms to document fields.

documentTermFrequencies object

???

documentLengths object

???

tokenizer lunr.tokenizer

Function for splitting strings into tokens for indexing.

pipeline lunr.Pipeline

The pipeline performs text processing on tokens before indexing.

documentCount number

Keeps track of the total number of documents indexed.

b number

A parameter to control field length normalization, setting this to 0 disabled normalization, 1 fully normalizes field lengths, the default value is 0.75.

k1 number

A parameter to control how quickly an increase in term frequency results in term frequency sauturation, the default value is 2.

termIndex number

A counter incremented for each unique term, used to identify a terms position in the vector space.

metadataWhitelist array

???

Source:

Methods

add(doc)

Adds a document to the index.

Before adding fields to the index the index should have been fully setup, with the document ref and all fields to index already having been specified.

The document must have a field name as specified by the ref (by default this is 'id') and it should have all fields defined for indexing, though null or undefined values will not cause errors.

Parameters:
Name Type Description
doc object

The document to add to the index.

Source:

field(field)

Adds a field to the list of document fields that will be indexed. Every document being indexed should have this field. Null values for this field in indexed documents will not cause errors but will limit the chance of that document being retrieved by searches.

All fields should be added before adding documents to the index. Adding fields after a document has been indexed will have no effect on already indexed documents.

Parameters:
Name Type Description
field string

The name of a field to index in all documents.

Source:

ref(ref)

Sets the document field used as the document reference. Every document must have this field. The type of this field in the document should be a string, if it is not a string it will be coerced into a string by calling toString.

The default ref is 'id'.

The ref should not be changed during indexing, it should be set before any documents are added to the index. Changing it during indexing can lead to inconsistent results.

Parameters:
Name Type Description
ref string

The name of the reference field in the document.

Source: