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

redis-autocompleter

v0.1.5

Published

A redis completer using Sebastian's trie algorithm: https://gist.github.com/574044

Downloads

5

Readme

redis-completer for node.js

An implementation of antirez's http://gist.github.com/574044 for node.js.

Installation

npm install redis-completer

Usage

Get a completer and provide a unique namespace for your app:

$ node
> completer = require('redis-completer');
> completer.applicationPrefix('winning');

That prefix prevents key conflics in redis. Make sure you use a prefix for each project.

Add completions for a document:

> completer.addCompletions(text, id, score);

id and score are optional. If id is null, it will be ignored.

If an id is provided, it will be concatenated with text in the final lookup table making a compound key of the form id:text. The idea here is to give you a way to stash a database key and a chunk of text together, so you can find your way back to some document you have stored elsewhere. E.g., if you're auto-completing a search by title, you could use the key to help retrieve the entire document.

Completions are sorted by score, so use that to weight documents you want to show up first.

Here's an example showing show score is reflected in search results:

> // adding completions:    text              id  score
> completer.addCompletions("Have some pie",    1,    42);
> completer.addCompletions("Have some quiche", 2,     6);
> completer.addCompletions("I prefer quiche",  3,    99);

> // convenience to print results
> function print(err, results) { console.log(results) }

> completer.search("have", 10, print);
[ '1:Have some pie', '2:Have some quiche' ]
> completer.search("quiche", 10, print);
[ '3:I prefer quiche', '2:Have some quiche' ]

It's up to me to remember that I used a key and deal with that when I process the text.

When multi-word phrases are matched, the scores for matches accumulate. For example:

> completer.addCompletions("something borrowed", 'one',  6);
> completer.addCompletions("something blue",     'two', 10);

// most valuable match first
> completer.search("some", 10, print);
[ 'two:something blue', 'one:something borrowed' ]

// most valuable match after accumulating scores first
> completer.search("something borr", 10, print);
[ 'one:something borrowed', 'two:something blue' ]

Overview

Sebastian Sanfilippo posted this really neat gist, which shows how to make search tries in redis for fast search completers.

I found j4mie's translation of the same to python, which I extended to allows for multi-word searches.

This is another translation of those examples for node.js. It has the following components:

  • A front-end with backbone models for searching and displaying results
  • A completer.js that provides multi-word completion via redis
  • An example app that lets the front-end communicate with completer via now.js

In the example/data directory is a file containing a little over 1000 tweets. (These tweets are mashups of Kanye West + Victor Medvedev and Martha Stewart + Lady Gaga, produced by my markov-tweeter.)

When you run example/app.js, it will make sure these have been processed and shoved into redis. This may take a few moments to complete, but it happens asynchronously, so you can start using the app right away.

On the web page, start typing, and hopefully we'll see a real-time search for tweets.