0

I have the following query (MongoMapper/Rails): Card.where(:card_tags => {:$all => search_tags}

Where card_tags is an array of string tags and search_tags is in array of the search strings. At the moment if someone searches 'snow', no results with tag 'snowboarding' will be returned.

How can I modify this query to search whether any strings in card_tags contains any of the strings in search_tags? Regular expressions come to mind but not sure of the syntax given these are arrays...

Thanks

1 Answer 1

1

You can use regular expressions but you will be doing full collection scans - this is going to be bad for performance.

You can use regex with an index only if you "starts with" type of searches, but I doubt you want to limit yourself to that.

For fulltext searching, you are better off using some external search service for this - like Lucene, ElasticSearch, or Solr.

Refer to this post too: like query in mongoDB

Sign up to request clarification or add additional context in comments.

1 Comment

Thanks! I know the regex syntax from the link you sent, but any idea how I can incoporate this into my query which is comparing two arrays of strings? I basically need some way of wrapping the regex around each of the search_tags elements.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.