
Product
Introducing Webhook Events for Alert Changes
Add real-time Socket webhook events to your workflows to automatically receive software supply chain alert changes in real time.
redis-completer
Advanced tools
A redis completer using Sebastian's trie algorithm: https://gist.github.com/574044
An implementation of antirez's http://gist.github.com/574044 for node.js.
npm install redis-completer
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' ]
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:
completer.js that provides multi-word completion via redisIn 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.
FAQs
A redis completer using Sebastian's trie algorithm: https://gist.github.com/574044
We found that redis-completer demonstrated a not healthy version release cadence and project activity because the last version was released a year ago. It has 0 open source maintainers collaborating on the project.
Did you know?

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Product
Add real-time Socket webhook events to your workflows to automatically receive software supply chain alert changes in real time.

Security News
ENISA has become a CVE Program Root, giving the EU a central authority for coordinating vulnerability reporting, disclosure, and cross-border response.

Product
Socket now scans OpenVSX extensions, giving teams early detection of risky behaviors, hidden capabilities, and supply chain threats in developer tools.