@uttori/search-provider-lunr
TypeScript icon, indicating that this package has built-in type declarations

4.0.0 • Public • Published

view on npm npm module downloads Build Status Coverage Status Tree-Shaking Support Dependency Count Minified + GZip Minified

Uttori Search Provider - Lunr

Uttori Search Provider powered by Lunr.js. It is largely abandoned but still works well.

Install

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

Config

{
  // Registration Events
  events: {
    search: ['search-query'],
    buildIndex: ['search-rebuild'],
    indexAdd: ['search-add'],
    indexUpdate: ['search-update'],
    indexRemove: ['search-remove'],
    getPopularSearchTerms: ['popular-search-terms'],
    validateConfig: ['validate-config'],
  },

  // A list of locales to add to Lunr
  // https://lunrjs.com/guides/language_support.html
  lunr_locales: [],

  // A list of functions to add to Lunr that correspond to the locales in lunr_locales
  // Example: import localeFr from 'lunr-languages/lunr.fr.js';
  // lunrLocaleFunctions: [localeFr],
  lunrLocaleFunctions: [],

  // A list of slugs to ignore
  ignoreSlugs: [],
}

API Reference

Classes

SearchProvider

Uttori Search Provider powered by Lunr.js.

Typedefs

StorageProviderConfig : object
StorageProviderSearchOptions : object

SearchProvider

Uttori Search Provider powered by Lunr.js.

Kind: global class
Properties

Name Type Description
searchTerms object The collection of search terms and their counts.
index lunr.Index The Lunr instance.

new SearchProvider([config])

Creates an instance of SearchProvider.

Param Type Description
[config] StorageProviderConfig Configuration object for the class.

Example

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

searchProvider.index : lunr.Index

Kind: instance property of SearchProvider

searchProvider.validateConfig

Validates the provided configuration for required entries and types.

Kind: instance property of SearchProvider

Param Type Description
config Record.<string, StorageProviderConfig> A provided configuration to use.

searchProvider.setup

Sets up the search provider with any lunr_locales supplied.

Kind: instance property of SearchProvider

searchProvider.buildIndex

Rebuild the search index of documents.

Kind: instance property of SearchProvider

Param Type Description
context UttoriContext A Uttori-like context.

Example

await searchProvider.buildIndex(context);

searchProvider.internalSearch ⇒ Promise.<Array.<object>>

Searches for documents matching the provided query with Lunr.

Kind: instance property of SearchProvider
Returns: Promise.<Array.<object>> - - Returns an array of search results no longer than limit.

Param Type Description
options StorageProviderSearchOptions The passed in options.
context UttoriContext A Uttori-like context.

searchProvider.search ⇒ Promise.<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 property of SearchProvider
Returns: Promise.<Array.<object>> - - Returns an array of search results no longer than limit.

Param Type Description
options StorageProviderSearchOptions The passed in options.
context UttoriContext A Uttori-like context.

Example

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

searchProvider.indexAdd

Adds documents to the index. For this implementation, it is rebuilding the index.

Kind: instance property of SearchProvider

Param Type Description
documents Array.<UttoriDocument> Unused. An array of documents to be indexed.
context UttoriContext A Uttori-like context.

searchProvider.indexUpdate

Updates documents in the index. For this implementation, it is rebuilding the index.

Kind: instance property of SearchProvider

Param Type Description
documents Array.<UttoriDocument> Unused. An array of documents to be indexed.
context UttoriContext A Uttori-like context.

searchProvider.indexRemove

Removes documents from the index. For this implementation, it is rebuilding the index.

Kind: instance property of SearchProvider

Param Type Description
documents Array.<UttoriDocument> Unused. An array of documents to be indexed.
context UttoriContext A Uttori-like context.

searchProvider.updateTermCount

Updates the search query in the query counts.

Kind: instance property of SearchProvider

Param Type Description
query string The query to increment.

searchProvider.getPopularSearchTerms ⇒ Array.<string>

Returns the most popular search terms.

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

Param Type Description
options StorageProviderSearchOptions The passed in options.

Example

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

SearchProvider.configKey ⇒ string

The configuration key for plugin to look for in the provided configuration.

Kind: static property of SearchProvider
Returns: string - The configuration key.
Example

const config = { ...Plugin.defaultConfig(), ...context.config[Plugin.configKey] };

StorageProviderConfig : object

Kind: global typedef
Properties

Name Type Description
[lunr_locales] Array.<string> A list of locales to add support for from lunr-languages.
[lunrLocaleFunctions] Array.<LunrLocale> A list of locales to add support for from lunr-languages.
[ignoreSlugs] Array.<string> A list of slugs to not consider when indexing documents.
[events] Record.<string, Array.<string>> The events to listen for.

StorageProviderSearchOptions : object

Kind: global typedef
Properties

Name Type Description
query string The value to search for.
[limit] number Limit for the number of returned 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

Readme

Keywords

Package Sidebar

Install

npm i @uttori/search-provider-lunr

Weekly Downloads

4

Version

4.0.0

License

MIT

Unpacked Size

41.2 kB

Total Files

14

Last publish

Collaborators

  • matthewcallis