mymojo
Posts: 0
Joined: Wed Mar 05, 2014 4:04 pm

search database limited to "Type"

Hi, I'm trying to do a search query where the values returned by a search box can then be filtered by Type. I can get a search query and return results, but then I'd like to filter the results via button clicks that limit results by type (food, beer, etc).

Here is the return string I'm using for the search box:
return '{"$or":[{"Product":{"$regex":"(?=.' + value.replace(/ /g, ")(?=.") + ')","$options":"im"}},{"Type":{"$regex":"(?=.' + value.replace(/ /g, ")(?=.") + ')","$options":"im"}},{"Company":{"$regex":"(?=.' + value.replace(/ /g, ")(?=.") + ')","$options":"im"}}]}';

Image

Yurii Orishchuk
Posts: 0
Joined: Fri Feb 14, 2014 8:20 am

search database limited to "Type"

Hi Mymojo.

If you want to reduce your selection please add "$and" clause with new "type" criteria you need.

You can store current filter type in LSV when user clicked on certain button. Just add "click" event handler on each button with following code:

pre
code

//Example for "beer" button.
localStorage.setItem("currentSelectedType", "beer");

//Invoke your query dataSource to update the list. You should replace "yourDataSource" with your query datasource name.
yourDataSource.execurte();

/code
/pre

Also you should modificate your "searchBox" return code with using "currentSelectedType" variable:

For example:

pre
code

//Get current selected type.
var currentSelectedType = localStorage.getItem("currentSelectedType");

//In this line of code you should add "$and" clause and new request criteria with using "currentSelectedType" variable.
return '{"$or":[{"Product":{"$regex":"(?=.' + value.replace(/ /g, ")(?=.") + ')","$options":"im"}},{"Type":{"$regex":"(?=.' + value.replace(/ /g, ")(?=.") + ')","$options":"im"}},{"Company":{"$regex":"(?=.' + value.replace(/ /g, ")(?=.") + ')","$options":"im"}}]}';

/code
/pre

Please read more about "$and" clause here: http://docs.appery.io/documentation/b...

Regards.

Return to “Issues”