Code Monkey home page Code Monkey logo

deepstream.io-provider-search-rethinkdb's Introduction

deepstream.io-provider-search-rethinkdb

Greenkeeper badge

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();

deepstream.io-provider-search-rethinkdb's People

Contributors

greenkeeper[bot] avatar greenkeeperio-bot avatar mclark-newvistas avatar timaschew avatar wolframhempel avatar yasserf avatar

Watchers

 avatar  avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.