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

inquery

v1.1.0

Published

A portable indexing and searching library.

Downloads

115

Readme

Inquery

A search engine library implemented with BM25

Build Status

How it Works

Inquery is a search engine which quickly retrieves pre-indexed documents. It is utilized by taking a set of documents (typically in the form of an object) and indexing them with an id. Later, the search method of Inquery can be used to retrieve an array of relevant ids sorted in order of relevance. The search method will allow a user's search query to have typos, or incomplete search terms. This means that, paired with the speed of Inquery, it is achievable, and not highly taxing to search over the documents as a user types.

Getting Started

Start using inquery by installing it to your project.

Apples-MacBook-Air:~ timfarrow$ npm install --save @spacebartech/inquery

Then, in your project's file, include Inquery and initialize it to begin using it.

const Inquery = require( '@spacebartech/inquery' );

const index = new Inquery();

Now that your Inquery is initialized, you can index any array of documents. In this example, I will read a set of documents from Firebase and then use Inquery to pre-index them, thus preparing Inquery for a search.

const Inquery = require( '@spacebartech/inquery' );
const Admin   = require( 'firebase-admin' );

const index = new Inquery();

Admin.database().ref( '/' )
  .child( 'organizations' )
  .child( 'Madera Unified' )
  .child( 'storage' )
  .child( 'events' )
  .on( 'value', ( snapshot ) => {

    // this object of events contains the "documents"
    // which we will index with Inquery;
    const events   = snapshot.val();
    const eventIds = Object.keys( events );

    eventIds.forEach( ( id ) => {

      // add a document to the index
      index.addDocument( events[id], id );

    } );

  } );

By calling Inquery's addDocument method, we index each of the events we retrieved from Firebase. After each event has been indexed, we can now use Inquery's search method to retrieve an array of results. The following example will be of an Express route which accepts a query and returns an array of results

router.post( '/search', ( req, res, next ) => {

  const { query } = req;
  const results   = index.search( query ); // array of objects ordered by relevance containing a cache of the document indexed;

  res.send( {
    status : 200,
    body   : results,
  } );

} );

That's about all there is to it! Happy searching!

Reference

Complete reference of all methods

addDocument

@param document: String|Object

@param id: String

returns undefined;

This method will add a document to the index and then cache it. After adding a document to your index, it will now be considered for any call of Inquery's search method.

Search

@param query: String

returns Object[];

This method takes a search query and finds all relevant, previously added documents. It will return an array of objects which look like:

{
  relevance: Float,
  document : Object|String // depending on what you used in the addDocument method
}

getIndex

No params

returns Object;

This method will export the indexed terms list which will vaguely resemble this pattern

{
  'tokenizedTerm' : {
    foundIn : [
      {
        id    : String, // key of indexed document
        count : Number, // number of times the term is found in the document
        idf   : Float,  // the inverse document frequency of the term (e.g. the term occurs three times, of three hundred total terms, the idf is 3/300 or .1)
                        // this number is used to help determine relevance
      },
      ...
    ]
  },
  ...
}