Uttori search provider powered by Lunr.
npm install @uttori/search-provider-lunr







Uttori Search Provider powered by Lunr.js. It is largely abandoned but still works well.
``bash`
npm install --save @uttori/search-provider-lunr
`js
{
// 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: [],
}
`
Uttori Search Provider powered by Lunr.js.
objectobjectKind: global class
Properties
| Name | Type | Description |
| --- | --- | --- |
| searchTerms | object | The collection of search terms and their counts. |
| index | lunr.Index | The Lunr instance. |
* SearchProvider
* [new SearchProvider([config])](#new_SearchProvider_new)
* _instance_
* .index : lunr.Index
* .validateConfig
* .setup
* .buildIndex
* .internalSearch ⇒ Promise.<Array.<object>>
* .search ⇒ Promise.<Array.<object>>
* .indexAdd
* .indexUpdate
* .indexRemove
* .updateTermCount
* .getPopularSearchTerms ⇒ Array.<string>
* _static_
* .configKey ⇒ string
| Param | Type | Description |
| --- | --- | --- |
| [config] | StorageProviderConfig | Configuration object for the class. |
Example
`js`
const searchProvider = new SearchProvider();
const searchProvider = new SearchProvider({ lunr_locales: ['de', 'fr', 'jp'], lunrLocaleFunctions: [localeDe, localeFr, localeJp] });
SearchProvider Kind: instance property of SearchProvider
| Param | Type | Description |
| --- | --- | --- |
| config | Record.<string, StorageProviderConfig> | A provided configuration to use. |
supplied.Kind: instance property of SearchProvider
$3
Rebuild the search index of documents.Kind: instance property of SearchProvider
| Param | Type | Description |
| --- | --- | --- |
| context | module:@uttori/wiki~UttoriContext | A Uttori-like context. |
Example
`js
await searchProvider.buildIndex(context);
`
$3
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 | module:@uttori/wiki~UttoriContext | A Uttori-like context. |
$3
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 | module:@uttori/wiki~UttoriContext | A Uttori-like context. |
Example
`js
searchProvider.search('matching');
➜ [{ ref: 'first-matching-document', ... }, { ref: 'another-matching-document', ... }, ...]
`
$3
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 | module:@uttori/wiki~UttoriContext | A Uttori-like context. |
$3
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 | module:@uttori/wiki~UttoriContext | A Uttori-like context. |
$3
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 | module:@uttori/wiki~UttoriContext | A Uttori-like context. |
$3
Updates the search query in the query counts.Kind: instance property of SearchProvider
| Param | Type | Description |
| --- | --- | --- |
| query | string | The query to increment. |
$3
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
`js
searchProvider.getPopularSearchTerms();
➜ ['popular', 'cool', 'helpful']
`
$3
The configuration key for plugin to look for in the provided configuration.Kind: static property of SearchProvider
Returns: string - The configuration key.
Example
`js
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:`bash
npm install
npm test
DEBUG=Uttori* npm test
``* MIT