npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

@uttori/search-provider-lunr

v4.0.0

Published

Uttori search provider powered by Lunr.

Downloads

24

Readme

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

| 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