incubator-couchdb-user mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Carl Bourne <carl.bou...@me.com>
Subject Re: Exclude documents from view based on list of regex expressions
Date Tue, 18 Sep 2012 18:57:26 GMT
Gentlemen, 

OK so this works exactly how I would like it to:

function(doc) {
 var reg_exps = [/ORA/g, /Hew/g, /VM/g];
 for (r in reg_exps){
   if (doc.subject.name.match(reg_exps[r])){
     return;
   }
 }
 emit(doc.subject.organisation_name, 1);
}

However, I'm puzzled as I would expect it to only return the documents that match the regex
NOT the ones that don't. I can't see a NOT operator in the syntax anywhere!

I haven't tried the compound regex yet though!


On 18 Sep 2012, at 18:24, Jens Alfke <jens@couchbase.com> wrote:

> 
> On Sep 18, 2012, at 10:17 AM, Aurélien Bénel <aurelien.benel@utt.fr<mailto:aurelien.benel@utt.fr>>
wrote:
> 
> Are you sure an array of regexes would be as efficient as a compound regex?
> 
> Good point — I don’t know the innards of SpiderMonkey but I think it’s pretty much
a guarantee that a compound regex would be much faster. In general the fewer times you have
to jump out of or into an interpreter (meaning both JS and the regex state-machine) the better.
> 
> If I recall the syntax correctly, it would look like /bar|baz/ … right?
> 
> —Jens
> 


Mime
View raw message