Page 1 of 1

Searching table for values - just the first letters of each word

Posted: Thu Mar 06, 2014 4:47 pm
by mymojo

Hi there,

I know I have something wrong here, because the results I'm retrieving include the searched letters, but they're just included anywhere, not necessarily in order as they were put in the search box. For example, if the search is "cat", a value returned might be "heart attack" bc it includes those three letters in any order.

I'd like my search to just be looking at the first letters of each word, or at least ensure that the letters are in a row, as searched. (There may be multiple words in each column).

Can someone help with my syntax? (A little too new at this...)

return '{"$or":[{"Product":{"$regex":"' + value.replace(/ /g, "|") + '","$options":"im"}},{"Company":{"$regex":"' + value.replace(/ /g, "|") + '","$options":"im"}}]}';


Searching table for values - just the first letters of each word

Posted: Thu Mar 06, 2014 5:56 pm
by Maryna Brodina

Hello! Please check the following post https://getsatisfaction.com/apperyio/...


Searching table for values - just the first letters of each word

Posted: Thu Mar 06, 2014 6:13 pm
by mymojo

Ok great, but how do I get it to use whatever is entered into the search field? In the following, there is a "\\bwor.*".

{"fieldName": {"$regex": "\\bwor.*", "$options":"im"}}

Which I assume is searching anything that starts with "wor"? (as per the above thread.) Do I replace that with "\\.*" ?

I just don't know how to search by what the user enters into the search field.


Searching table for values - just the first letters of each word

Posted: Thu Mar 06, 2014 6:14 pm
by mymojo

or is it "^'+value+'" ?


Searching table for values - just the first letters of each word

Posted: Thu Mar 06, 2014 8:13 pm
by Maryna Brodina

"^'+value+'" means string starts with value value
"\bwor.*" - means any word in string should start with wor


Searching table for values - just the first letters of each word

Posted: Thu Mar 06, 2014 8:21 pm
by mymojo

Ok, so how do I search by user's input? Do I just use an asterisk? I have a user search box, and I want to return values based on whatever they enter in that search box.

Or is that what value signifies?


Searching table for values - just the first letters of each word

Posted: Thu Mar 06, 2014 8:22 pm
by mymojo

I have a user search box, and I want to return values based on whatever they enter in that search box.


Searching table for values - just the first letters of each word

Posted: Thu Mar 06, 2014 8:34 pm
by Maryna Brodina

If you add this code in mapping, what you map in code will be in value variable.