4.0.0 • Published 5 months ago

@uttori/search-provider-lunr v4.0.0

Weekly downloads
1
License
MIT
Repository
github
Last release
5 months ago

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

Typedefs

SearchProvider

Uttori Search Provider powered by Lunr.js.

Kind: global class
Properties

NameTypeDescription
searchTermsobjectThe collection of search terms and their counts.
indexlunr.IndexThe Lunr instance.

new SearchProvider(config)

Creates an instance of SearchProvider.

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

ParamTypeDescription
configRecord.<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

ParamTypeDescription
contextUttoriContextA 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.

ParamTypeDescription
optionsStorageProviderSearchOptionsThe passed in options.
contextUttoriContextA 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.

ParamTypeDescription
optionsStorageProviderSearchOptionsThe passed in options.
contextUttoriContextA 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

ParamTypeDescription
documentsArray.<UttoriDocument>Unused. An array of documents to be indexed.
contextUttoriContextA Uttori-like context.

searchProvider.indexUpdate

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

Kind: instance property of SearchProvider

ParamTypeDescription
documentsArray.<UttoriDocument>Unused. An array of documents to be indexed.
contextUttoriContextA Uttori-like context.

searchProvider.indexRemove

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

Kind: instance property of SearchProvider

ParamTypeDescription
documentsArray.<UttoriDocument>Unused. An array of documents to be indexed.
contextUttoriContextA Uttori-like context.

searchProvider.updateTermCount

Updates the search query in the query counts.

Kind: instance property of SearchProvider

ParamTypeDescription
querystringThe 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.

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

NameTypeDescription
lunr_localesArray.<string>A list of locales to add support for from lunr-languages.
lunrLocaleFunctionsArray.<LunrLocale>A list of locales to add support for from lunr-languages.
ignoreSlugsArray.<string>A list of slugs to not consider when indexing documents.
eventsRecord.<string, Array.<string>>The events to listen for.

StorageProviderSearchOptions : object

Kind: global typedef
Properties

NameTypeDescription
querystringThe value to search for.
limitnumberLimit 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

4.0.0

5 months ago

3.4.0

3 years ago

3.3.4

3 years ago

3.3.3

3 years ago

3.3.2

4 years ago

3.3.1

4 years ago

3.3.0

4 years ago

3.2.0

4 years ago

3.1.0

4 years ago

3.0.0

4 years ago