2.1.1 • Published 5 years ago

uttori-search-provider-lunr v2.1.1

Weekly downloads
4
License
MIT
Repository
github
Last release
5 years ago

view on npm npm module downloads Build Status Dependency Status Coverage Status

Uttori Search Provider - Lunr

Uttori Search Provider powered by Lunr.js.

Install

npm install --save uttori-search-provider-lunr

API Reference

SearchProvider

Uttori Search Provider powered by Lunr.js.

Kind: global class
Properties

NameTypeDescription
searchTermsObjectThe collection of search terms and their counts.
indexObjectThe Lunr instance.

new SearchProvider(config)

Creates an instance of SearchProvider.

ParamTypeDefaultDescription
configObject{}Configuration object for the class.
config.lunr_localesArray.<string>[]A list of locales to add support for from lunr-languages.

Example (Init SearchProvider)

const searchProvider = new SearchProvider();
const searchProvider = new SearchProvider({ lunr_locales: ['de', 'fr', 'jp'] });

searchProvider.setup(config)

Setup the search provider by building an index of documents.

Kind: instance method of SearchProvider

ParamTypeDefaultDescription
configObject{}Configuration object for setup.
config.documentsArray.<UttoriDocument>[]An array of documents to be indexed.

Example

searchProvider.setup({ documents: [{ slug: 'intro', title: 'Intro', content: '...', tags: ['intro'] }] });

searchProvider.search(query, limit) ⇒ Array.<Object>

External method for searching documents matching the provided query and updates the count for the query used. Uses the internalSearch method internally.

Kind: instance method of SearchProvider
Returns: Array.<Object> - - Returns an array of search results no longer than limit.

ParamTypeDefaultDescription
querystringThe value to search for.
limitnumber100Limit for the number of returned documents.

Example

searchProvider.search('matching');
➜ [{ ref: 'first-matching-document', ... }, { ref: 'another-matching-document', ... }, ...]

searchProvider.internalSearch(query, limit) ⇒ Array.<Object>

Searches for documents matching the provided query with Lunr.

Kind: instance method of SearchProvider
Returns: Array.<Object> - - Returns an array of search results no longer than limit.
Access: private

ParamTypeDefaultDescription
querystringThe value to search for.
limitnumber100Limit for the number of returned documents.

searchProvider.indexAdd(documents)

Unused: Adds documents to the index.

Kind: instance method of SearchProvider

ParamTypeDefaultDescription
documentsArray.<UttoriDocument>[]An array of documents to be indexed.

searchProvider.indexUpdate(documents)

Unused: Updates documents in the index.

Kind: instance method of SearchProvider

ParamTypeDefaultDescription
documentsArray.<UttoriDocument>[]An array of documents to be indexed.

searchProvider.indexRemove(documents)

Unused: Removes documents from the index.

Kind: instance method of SearchProvider

ParamTypeDefaultDescription
documentsArray.<UttoriDocument>[]An array of documents to be indexed.

searchProvider.updateTermCount(query)

Updates the search query in the query counts.

Kind: instance method of SearchProvider

ParamTypeDescription
querystringThe query to increment.

searchProvider.getPopularSearchTerms(limit) ⇒ Array.<string>

Returns the most popular search terms.

Kind: instance method of SearchProvider
Returns: Array.<string> - - Returns an array of search results no longer than limit.

ParamTypeDefaultDescription
limitnumber10Limit for the number of returned popular searches.

Example

searchProvider.getPopularSearchTerms();
➜ ['popular', 'cool', 'helpful']

searchProvider.shouldAugment(query, fields) ⇒ boolean

Determines if a given search query needs to have fields augmented.

Kind: instance method of SearchProvider
Returns: boolean - - Returns true. Lunr does not return all of the required fields for displaing search results.

ParamTypeDescription
querystringUnused: the query to check for augmentation.
fieldsArray.<string>Unused: the fields required to be on the documents.

Tests

To run the test suite, first install the dependencies, then run npm test:

npm install
npm test
DEBUG=Uttori* npm test

Contributors

License

2.1.1

5 years ago

2.1.0

6 years ago

2.0.0

6 years ago

1.1.2

6 years ago

1.1.1

6 years ago

1.1.0

6 years ago

1.0.1

6 years ago

1.0.0

7 years ago