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

v2.1.1

Published

Uttori search provider powered by Lunr.

Downloads

7

Readme

view on npm npm module downloads Build Status Dependency Status Coverage Status

Uttori Search Provider - Lunr

Uttori Search Provider powered by Lunr.js.

Install

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

API Reference

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 | Object | The Lunr instance. |

new SearchProvider([config])

Creates an instance of SearchProvider.

| Param | Type | Default | Description | | --- | --- | --- | --- | | [config] | Object | {} | Configuration object for the class. | | [config.lunr_locales] | Array.<string> | [] | A list of locales to add support for from lunr-languages. |

Example (Init SearchProvider)

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

searchProvider.setup([config])

Setup the search provider by building an index of documents.

Kind: instance method of SearchProvider

| Param | Type | Default | Description | | --- | --- | --- | --- | | [config] | Object | {} | Configuration object for setup. | | [config.documents] | Array.<UttoriDocument> | [] | An array of documents to be indexed. |

Example

searchProvider.setup({ documents: [{ slug: 'intro', title: 'Intro', content: '...', tags: ['intro'] }] });

searchProvider.search(query, [limit]) ⇒ 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 method of SearchProvider
Returns: Array.<Object> - - Returns an array of search results no longer than limit.

| Param | Type | Default | Description | | --- | --- | --- | --- | | query | string | | The value to search for. | | [limit] | number | 100 | Limit for the number of returned documents. |

Example

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

searchProvider.internalSearch(query, [limit]) ⇒ Array.<Object>

Searches for documents matching the provided query with Lunr.

Kind: instance method of SearchProvider
Returns: Array.<Object> - - Returns an array of search results no longer than limit.
Access: private

| Param | Type | Default | Description | | --- | --- | --- | --- | | query | string | | The value to search for. | | [limit] | number | 100 | Limit for the number of returned documents. |

searchProvider.indexAdd([documents])

Unused: Adds documents to the index.

Kind: instance method of SearchProvider

| Param | Type | Default | Description | | --- | --- | --- | --- | | [documents] | Array.<UttoriDocument> | [] | An array of documents to be indexed. |

searchProvider.indexUpdate([documents])

Unused: Updates documents in the index.

Kind: instance method of SearchProvider

| Param | Type | Default | Description | | --- | --- | --- | --- | | [documents] | Array.<UttoriDocument> | [] | An array of documents to be indexed. |

searchProvider.indexRemove([documents])

Unused: Removes documents from the index.

Kind: instance method of SearchProvider

| Param | Type | Default | Description | | --- | --- | --- | --- | | [documents] | Array.<UttoriDocument> | [] | An array of documents to be indexed. |

searchProvider.updateTermCount(query)

Updates the search query in the query counts.

Kind: instance method of SearchProvider

| Param | Type | Description | | --- | --- | --- | | query | string | The query to increment. |

searchProvider.getPopularSearchTerms([limit]) ⇒ Array.<string>

Returns the most popular search terms.

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

| Param | Type | Default | Description | | --- | --- | --- | --- | | [limit] | number | 10 | Limit for the number of returned popular searches. |

Example

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

searchProvider.shouldAugment([query], [fields]) ⇒ boolean

Determines if a given search query needs to have fields augmented.

Kind: instance method of SearchProvider
Returns: boolean - - Returns true. Lunr does not return all of the required fields for displaing search results.

| Param | Type | Description | | --- | --- | --- | | [query] | string | Unused: the query to check for augmentation. | | [fields] | Array.<string> | Unused: the fields required to be on the 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