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

deepstream.io-provider-search-rethinkdb

v2.0.0

Published

Realtime searches using rethinkdb

Downloads

21

Readme

deepstream.io-provider-search-rethinkdb

Build Status Coverage Status npm Dependency Status devDependency Status

Adds realtime search functionality to deepstream when used in conjunction with RethinkDb.

Say you've got a number of records like:

ds.record.getRecord( 'book/i95ny80q-2bph9txxqxg' ).set({
	'title': 'Harry Potter and the goblet of fire',
	'price': 9.99
});

and use deepstream.io's RethinkDb storage connector with:

{ splitChar: '/' }

you can now search for Harry Potter books that cost less than 15.30 like this:

var queryString = JSON.stringify({
	table: 'book',
    	query: [
    		[ 'title', 'match', '^Harry Potter.*' ],
        [ 'price', 'lt', 15.30 ],
        [ 'author.lastname', 'eq', 'Rowling' ] //nested paths work too
    	]
});
ds.record.getList( 'search?' + queryString );

and the best thing is: it's in realtime. Whenever a record that matches the search criteria is added or removed, the list will be updated accordingly.

Configuration

Install the provider via npm and configure it to connect to both deepstream and RethinkDb

var SearchProvider = require( './src/provider' );

var searchProvider = new SearchProvider({
  //optional, defaults to 'search'
  listName: 'search',

  /**
   * Only use 0 or 1 for production!

   * 0 = logging off
   * 1 = only log connection events & errors
   * 2 = also log subscriptions and discards
   * 3 = log outgoing messages
   */
  logLevel: 3,

  // deepstream
  deepstreamUrl: 'localhost:6021',
  deepstreamCredentials: { username: 'rethinkdb-search-provider' },

  // Instead of creating a new connection to deepstream, you can also
  // reuse an existing one by substituting the above with
  deepstreamClient: myDeepstreamClient,

  // rethinkdb
  rethinkdbConnectionParams: {
      host: '192.168.56.101',
      port: 28015,
      db: 'deepstream'
  },

  //optional primary key, defaults to ds_id
  primaryKey: 'itemId',

  // Instead of creating a new connection to RethinkDb, you can also
  // reuse an existing one by substituting the above with
  rethinkDbConnection: myRethinkDbConnection
});

// and start it
searchProvider.start();

// it can also be stopped by calling
searchProvider.stop();

Searching

On the client you can now request dynamically populated lists of search results

var queryString = JSON.stringify({
	table: 'book',
    query: [
    	[ 'title', 'match', '^Harry Potter.*' ],
        [ 'price', 'lt', 15.30 ]
    ]
});
ds.record.getList( 'search?' + queryString );

query can contain one or more conditions. Each condition is an array of [ field, operator, value ]. Supported operators are:

  • "eq" (equal)
  • "gt" (greater than)
  • "lt" (lesser than)
  • "ne" (not equal)
  • "match" (RegEx match)

Please note that the operators are type-sensitive, so comparing 20 with "20" won't yield results

Important!

Don't forget to delete your search from deepstream once you don't need it anymore, e.g.

bookSearchResults = ds.record.getList( 'search?' + queryString );
// use it
bookSearchResults.delete();