javascript - How to perform sql "LIKE" operation on firebase? -


i using firebase data storage. data structure this:

products:{    product1:{       name:"chocolate",    }    product2:{       name:"chochocho",    } } 

i want perform auto complete operation data, , write query this:

"select name products productname '%" + keyword + "%'"; 

so, situation, example, if user types "cho", need bring both "chocolate" , "chochocho" result. thought bringing data under "products" block, , query @ client, may need lot of memory big database. so, how can perform sql operation?

thanks

update: release of cloud functions firebase, there's elegant way linking firebase algolia via functions. tradeoff here functions/algolia pretty 0 maintenance, @ increased cost on roll-your-own in node.

there no content searches in firebase @ present. many of more common search scenarios, such searching attribute baked firebase api continues expand.

in mean time, it's possible grow own. however, searching vast topic (think creating real-time data store vast), underestimated, , critical feature of application--not 1 want ad hoc or depend on firebase provide on behalf. it's typically simpler employ scalable third party tool handle indexing, searching, tag/pattern matching, fuzzy logic, weighted rankings, et al.

the firebase blog features blog post on indexing elasticsearch outlines straightforward approach integrating quick, extremely powerful, search engine firebase backend.

essentially, it's done in 2 steps. monitor data , index it:

var firebase = require('firebase'); var elasticclient = require('elasticsearchclient')  // initialize our elasticsearch api var client = new elasticclient({ host: 'localhost', port: 9200 });  // listen changes firebase data var fb = new firebase('<instance>.firebaseio.com/widgets'); fb.on('child_added',   createorupdateindex); fb.on('child_changed', createorupdateindex); fb.on('child_removed', removeindex);  function createorupdateindex(snap) {    client.index(this.index, this.type, snap.val(), snap.name())      .on('data', function(data) { console.log('indexed ', snap.name()); })      .on('error', function(err) { /* handle errors */ }); }  function removeindex(snap) {    client.deletedocument(this.index, this.type, snap.name(), function(error, data) {       if( error ) console.error('failed delete', snap.name(), error);       else console.log('deleted', snap.name());    }); } 

query index when want search:

<script src="elastic.min.js"></script>  <script src="elastic-jquery-client.min.js"></script>  <script>     ejs.client = ejs.jqueryclient('http://localhost:9200');     client.search({       index: 'firebase',       type: 'widget',       body: ejs.request().query(ejs.matchquery('title', 'foo'))     }, function (error, response) {        // handle response     });  </script> 

there's example, , third party lib simplify integration, here.


Comments

Popular posts from this blog

mysql - Dreamhost PyCharm Django Python 3 Launching a Site -

java - Sending SMS with SMSLib and Web Services -

java - How to resolve The method toString() in the type Object is not applicable for the arguments (InputStream) -