Page 4 of 5

How to use search to query multiple database columns

Posted: Mon Feb 02, 2015 2:48 pm
by Ellen Schlechter

I just want it to search in multiple columns but the text in the input only has to meet the criteria of one column. So even when I try to search for something that I know is in the database, it won't show up.


How to use search to query multiple database columns

Posted: Tue Feb 03, 2015 12:05 pm
by Evgene Karachevtsev

Hello!

If it isn't showed up when you expect to see it, then:
1) your rule is wrong
2) may be you need to use "$or" instead of "$and"
Could you please write what is the rule for your query ?


How to use search to query multiple database columns

Posted: Tue Feb 03, 2015 5:04 pm
by Ellen Schlechter

I changed it to $or and results don't go away when I search for something unrelated. Here is the code I used.

var select = localStorage.getItem("bookid");
var search = Apperyio("mobilesearchbar_282").val();
var cow =Apperyio('mobiletextinput_cowid').val();
var sire =Apperyio('mobiletextinput_405sire').val();
var color =Apperyio('mobiletextinput_406color').val();

return '{"$or":[,{"calf_id":"'+search +'"},{"cow_id":"'+cow+'"},{"sire":"'+sire+'"},{"color":"'+color+'"} ]}';

My app is shared with support and called The Calving Book. The screen1 search_service is where you will find this implementation.


How to use search to query multiple database columns

Posted: Thu Feb 05, 2015 2:55 am
by Yurii Orishchuk

Hi Ellen,

It's better to use direct JS objects:

For example following JS code:

pre

var whereObject = {
"$or": [
{"calf_id": search},
{"cow_id": cow},
{"sire": sire},
{"color": color}
]
};
return JSON.stringify(whereObject);

/pre

Regards.


How to use search to query multiple database columns

Posted: Thu Feb 05, 2015 4:04 am
by Ellen Schlechter

Unfortunately, that didn't work.


How to use search to query multiple database columns

Posted: Thu Feb 05, 2015 11:31 pm
by Yurii Orishchuk

HI Ellen,

Do you need further help?

If so - please provide us additional information.

For example, what you expect, what is not work, screen shot with information about request (parameters and headers) and screen shot what service returns.

Regards.


How to use search to query multiple database columns

Posted: Thu Feb 05, 2015 11:38 pm
by Ellen Schlechter

I want a collapsible list item to appear if it matches the criteria. The criteria is just if it matches in the search input or if they search li, lion, listen, and little should all show up.


How to use search to query multiple database columns

Posted: Fri Feb 06, 2015 11:42 pm
by Alena Prykhodko

Dear Ellen,

We are very sorry, but custom logic is something outside the scope (http://devcenter.appery.io/support-po...) of our support.
You can show us what you have tried and what does not work, so we can suggest.
You may consider purchasing Advisory Pack to get more in-depth help on this question. Here is more information about Advisory Pack (http://appery.io/services/#Advisory_Pack).


How to use search to query multiple database columns

Posted: Sat Feb 07, 2015 2:27 am
by Ellen Schlechter

I tried adding this code as Yurii suggested. I don't have anything mapped to the 'where' parameter. I only have this code there.

var whereObject = {
"$or": [
{"calf_id": search},
{"cow_id": cow},
{"sire": sire},
{"color": color}
]
};
return JSON.stringify(whereObject);

I get this error in the console when I try to search.

Image


How to use search to query multiple database columns

Posted: Mon Feb 09, 2015 5:51 am
by Yurii Orishchuk

Hi Ellen,

This you should debug your app to find a reason of this problem.

It seems something wrong with transformations.

Regards.