Page 1 of 2

Advance search

Posted: Fri Dec 05, 2014 11:14 am
by A K R

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.


Advance search

Posted: Fri Dec 05, 2014 1:27 pm
by Illya Stepanov

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.


Advance search

Posted: Fri Dec 05, 2014 1:44 pm
by A K R

ok i will test it and let you know


Advance search

Posted: Sat Dec 06, 2014 7:29 am
by A K R

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


Advance search

Posted: Sat Dec 06, 2014 7:31 am
by A K R

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


Advance search

Posted: Sat Dec 06, 2014 7:33 am
by A K R

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


Advance search

Posted: Mon Dec 08, 2014 12:49 am
by Yurii Orishchuk

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.


Advance search

Posted: Mon Dec 08, 2014 9:36 am
by A K R

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


Advance search

Posted: Mon Dec 08, 2014 9:40 am
by Evgene Karachevtsev

Hello A K R,

Thank you for the update.


Advance search

Posted: Mon Dec 22, 2014 6:24 am
by A K R

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