New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Error: Invalid operator: $regex #184
Comments
Try expressing your regular expression as a string. Nano doesn't understand JavaScript regular expressions - it passes a regular expression string to CouchDB for processing e.g. selector: { name: {"$regex": "^cat" }} should find names beginning with "cat". |
Thank you very much, it worked :) Can you please help me with indexing, I am working on search functionality where I will be doing a fuzzy search over I tried adding the index and i keep getting this error What would be the best practice to implement a search in CouchDB ? |
First of all the regex operator is very slow and an index can't be used to speed it up. It will inevitable cause CouchDB to do a full database scan (looking through each document body in turn) to get your answer. If you are looking for "all documents containing 'cat'" then you need to index each word in the string in question, which is what Without the Lucene-based free-text search index, you're a bit stuck. You could roll your own index with a MapReduce index like so?: function(doc) {
// break "str" into words
var words = doc.str.split(/\W/);
for(var i in words) {
if (words[i]) {
// create an index with the lower-cased word as the key
emit(words[i].toLowerCase(), null)
}
}
} |
Thanks for sharing So after adding this view I can use |
How to pass regex flags then? Suppose I need case insensitive search. |
@Cherviakov you can do it like this:
|
Thanks @EddyTheDove |
Facing issue while doing something like
Expected Behavior
it should return names containing
cat
Current Behavior
Current error stack
Possible Solution
Steps to Reproduce (for bugs)
1.Just use $regex, it will throw error
Context
I am trying to do wildcard search based on name in CouchDB
Your Environment
The text was updated successfully, but these errors were encountered: