0

[edited for hopefully more clarity.]

I'm probably confused, but I have a Mongodb dataset of simple words:

Items:
Boston Beer
Boston Brewery
Coors Brewing Light

I have an input string:

"Boston Beer Company"

I want to find any item That is contained within the input string. In this case, 'Boston Beer' would be a match.

The trouble is, given any input string, I don't know which words in the string would find a match in a field. (The match is not anchored to the beginning or end.)

In Javascript, I'd just create a loop and test.

inputString.indexOf(currentItem) >= 0

I may have confused myself, but I can't find a way to express a regEx where the RegEx is the target string and I am testing if any individual item (field) is contained within the longer string.

I hope this is somewhat clearer.

Thanks in advance-

joelm
  • 8,741
  • 1
  • 19
  • 17
  • 1
    I don't follow how you want the matching to work given your example. The bad news is that using regex in MongoDb is only efficient for "begins with" type queries. You might want to look at the not-yet-ready-for-production "text" search feature in 2.4. – WiredPrairie Apr 21 '13 at 11:08
  • Unfortunately, I'm using a service which uses MongoDB for their backend, so I have no access to newer releases. Sorry if not clear. Basically I want to say: Is the fieldValue contained within the search string. (which is backwards from the usual search.) – joelm Apr 21 '13 at 14:54
  • Could you please edit your question to make it more clear what you're trying to do? I still don't follow your question. Given the input string, what items would be selected? You might look at this: [checking if field contains string](http://stackoverflow.com/questions/10610131/checking-if-a-field-contains-a-string/10616781#10616781), [regex](http://docs.mongodb.org/manual/reference/operator/regex/) or [keywords](http://docs.mongodb.org/manual/tutorial/model-data-for-keyword-search/). – WiredPrairie Apr 21 '13 at 14:59

0 Answers0