deepstream.io-provider-search-rethinkdb
Adds realtime search functionality to deepstream when used in conjunction with RethinkDb.
Say you've got a number of records like:
dsrecord;
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;dsrecord;
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 = ; var 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 itsearchProviderstart; // it can also be stopped by callingsearchProvider;
Searching
On the client you can now request dynamically populated lists of search results
var queryString = JSON;dsrecord;
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 = dsrecord;// use itbookSearchResults;