Buildfire - Using regex in search -
i have been looking @ documentation can't seem figure out how correctly create filter object buildfire.datastore.search query.
i have address property on object , want able type in partial amount of address , have return. below filter objects have tried pass search query:
search = {filter: {"$json.address": {"$regex": `/${this.state.search}/`}}}; search = {filter: {'$regex': {'$json.address': this.state.search}}};
neither have worked. end goal is:
buildfire.datastore.search(search, 'location', cb);
edit:
i tried hardcode regex in docs:
"$or" : [ {"description": {"$regex":"/new /"}} ]
and didn't work (i replaced 'new' string knew show).
i inserted following on control side:
for(let = 0 ; < 50 ; i++) { buildfire.datastore.insert({ name: "address" + ,address: + " " + (i % 2 ? "main ":"4th ") + (i % 3 ? "ave":"st" ) },function(){}); }
then did search on widget side this:
<body> <input type="text" id="criteria" /><button onclick="search()">search</button> <div id="results"></div> <script> function search(){ var cri = document.getelementbyid("criteria").value; buildfire.datastore.search( {filter:{"$json.name": {"$regex": cri } } } , function(err,results){ document.getelementbyid("results").innerhtml = json.stringify(results); }); } </script> </body>
works fine. given if want search more complex need modify regex statement example case insensitivity.
hope helps
Comments
Post a Comment