Uttori Search Provider powered by Lunr.js. It is largely abandoned but still works well.
npm install --save @uttori/search-provider-lunr
{
// 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: [],
}
- SearchProvider
Uttori Search Provider powered by Lunr.js.
- StorageProviderConfig :
object
- StorageProviderSearchOptions :
object
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. |
- SearchProvider
- new SearchProvider([config])
- instance
- .index :
lunr.Index
- .validateConfig
- .setup
- .buildIndex
- .internalSearch ⇒
Promise.<Array.<object>>
- .search ⇒
Promise.<Array.<object>>
- .indexAdd
- .indexUpdate
- .indexRemove
- .updateTermCount
- .getPopularSearchTerms ⇒
Array.<string>
- .index :
- static
- .configKey ⇒
string
- .configKey ⇒
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] });
Kind: instance property of SearchProvider
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. |
Sets up the search provider with any lunr_locales
supplied.
Kind: instance property of SearchProvider
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);
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. |
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', ... }, ...]
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. |
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. |
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. |
Updates the search query in the query counts.
Kind: instance property of SearchProvider
Param | Type | Description |
---|---|---|
query | string |
The query to increment. |
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']
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] };
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. |
Kind: global typedef
Properties
Name | Type | Description |
---|---|---|
query | string |
The value to search for. |
[limit] | number |
Limit for the number of returned documents. |
To run the test suite, first install the dependencies, then run npm test
:
npm install
npm test
DEBUG=Uttori* npm test