mymojo
Posts: 0
Joined: Wed Mar 05, 2014 4:04 pm

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

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"}}]}';

mymojo
Posts: 0
Joined: Wed Mar 05, 2014 4:04 pm

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

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.

mymojo
Posts: 0
Joined: Wed Mar 05, 2014 4:04 pm

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

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

Maryna Brodina
Posts: 0
Joined: Thu Apr 05, 2012 7:27 am

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

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

mymojo
Posts: 0
Joined: Wed Mar 05, 2014 4:04 pm

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

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?

mymojo
Posts: 0
Joined: Wed Mar 05, 2014 4:04 pm

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

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

Maryna Brodina
Posts: 0
Joined: Thu Apr 05, 2012 7:27 am

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

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

Return to “Issues”