A K R
Posts: 0
Joined: Mon Sep 22, 2014 6:06 am

Advance search

Hi
am doing an advance search in which there are 8 search fields. for e.g surname, age, village, gender, occupation, city, education and all data is in the same table. so user can enter any number of fields and he can search. its an "or" condition so he can enter a minimum of one field and can search. i used the below code but it is not giving me the exact results

return '{"$or":[{"Surname":{"$regex":"'+value1+'", "$options":"i"}},{"village":{"$regex":"'+value4+'", "$options":"i"}},{"city":{"$regex":"'+value5+'", "$options":"i"}},{"Blood_Group":{"$regex":"'+value6+'", "$options":"i"}},{"occupation":{"$regex":"'+value7+'", "$options":"i"}},{"education":{"$regex":"'+value8+'", "$options":"i"}},{"Gender":{"$regex":"'+value9+'", "$options":"i"}}]}';

am struggling from many days but i am unable to find a solution for this so please help me.

Illya Stepanov
Posts: 0
Joined: Mon Mar 18, 2013 8:48 am

Advance search

Hi -

Is this query string returning some data in some cases? You can test the small parts of this statement and after that try to combining it in one.

A K R
Posts: 0
Joined: Mon Sep 22, 2014 6:06 am

Advance search

ok i will test it and let you know

A K R
Posts: 0
Joined: Mon Sep 22, 2014 6:06 am

Advance search

i tested it in parts they are working, but when am using in group it is not giving exact values

A K R
Posts: 0
Joined: Mon Sep 22, 2014 6:06 am

Advance search

return '{"Surname":{"$regex":"^'+value1+'", "$options":"i"}}','{"village":{"$regex":"^'+value4+'", "$options":"i"}}','{"residential_area":{"$regex":"^'+value5+'", "$options":"i"}}','{"Blood_Group":{"$regex":"'+value6+'", "$options":"i"}}','{"occupation":{"$regex":"'+value7+'", "$options":"i"}}','{"education":{"$regex":"'+value8+'", "$options":"i"}}','{"Gender":{"$regex":"'+value9+'", "$options":"i"}}';
i tried this also but it doesn't serve the purpose

A K R
Posts: 0
Joined: Mon Sep 22, 2014 6:06 am

Advance search

can you give me some sample code which works like
i search for surname and i got 10 results then i entered village and it filters from the 10 results and give me the values. it is like multiple where clause

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

Advance search

Hi AKR,

You code is to complicate to view.

Please use following structure:

pre

var westlothian = "aaa";
var falkirk= "bbb";

//This is "and" login you can use "$or" if you need it.
var whereObject = {
"$or": [
//Here you can add search items like simple js object.
{"westlothian": westlothian },
{"falkirk": falkirk }
]
};

return JSON.stringify(whereObject);

/pre

Also as you see in this code used "$or statement". Please take a look what is that and how it works: http://devcenter.appery.io/documentat...

Regards.

A K R
Posts: 0
Joined: Mon Sep 22, 2014 6:06 am

Advance search

thanks yurii,
the above code works.
i builded the where clause dynamically for e.g if the user enters only two fields the where clause will have only two keys and two values.if he enter five fields then where clause will have ony five keys and five values. so in where clause no key will be empty and it will search the exact ones

var obj=new object();
if(Appery('comp1').val())
{
obj.key="value1";
}

thanks alot yurii

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

Advance search

Hello A K R,

Thank you for the update.

A K R
Posts: 0
Joined: Mon Sep 22, 2014 6:06 am

Advance search

the above code is case sensitive how can i make it case insensitive

Return to “Issues”