Ellen Schlechter
Posts: 0
Joined: Sun Aug 31, 2014 3:28 am

How to use search to query multiple database columns

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.

Evgene Karachevtsev
Posts: 12
Joined: Mon Apr 28, 2014 1:12 pm

How to use search to query multiple database columns

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 ?

Ellen Schlechter
Posts: 0
Joined: Sun Aug 31, 2014 3:28 am

How to use search to query multiple database columns

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.

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

How to use search to query multiple database columns

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.

Ellen Schlechter
Posts: 0
Joined: Sun Aug 31, 2014 3:28 am

How to use search to query multiple database columns

Unfortunately, that didn't work.

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

How to use search to query multiple database columns

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.

Ellen Schlechter
Posts: 0
Joined: Sun Aug 31, 2014 3:28 am

How to use search to query multiple database columns

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.

Alena Prykhodko
Posts: 0
Joined: Tue Apr 09, 2013 7:36 am

How to use search to query multiple database columns

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).

Ellen Schlechter
Posts: 0
Joined: Sun Aug 31, 2014 3:28 am

How to use search to query multiple database columns

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

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

How to use search to query multiple database columns

Hi Ellen,

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

It seems something wrong with transformations.

Regards.

Return to “Issues”