diff options
author | Dwight <dmerriman@gmail.com> | 2008-06-26 10:39:32 -0400 |
---|---|---|
committer | Dwight <dmerriman@gmail.com> | 2008-06-26 10:39:32 -0400 |
commit | 1620d7ebdf78eb171fffbd6f66401b475c8791ad (patch) | |
tree | 084fa8ea5babdf5be8a5f9c22b0b783c023cfc81 | |
parent | 15dfe43b34d93b772203074e4f83dfe4601d523b (diff) | |
download | mongo-1620d7ebdf78eb171fffbd6f66401b475c8791ad.tar.gz |
regex matches now supported, partially, when reaching into arrays.
-rw-r--r-- | db/jsobj.cpp | 19 |
1 files changed, 16 insertions, 3 deletions
diff --git a/db/jsobj.cpp b/db/jsobj.cpp index 9c70414634a..6fe927efafd 100644 --- a/db/jsobj.cpp +++ b/db/jsobj.cpp @@ -476,8 +476,21 @@ inline bool _regexMatches(RegexMatcher& rm, Element& e) { return false; return rm.re->PartialMatch(p); } -inline bool regexMatches(RegexMatcher& rm, Element& e) { - return _regexMatches(rm, e); +/* todo: internal dotted notation scans -- not done yet here. */ +inline bool regexMatches(RegexMatcher& rm, Element& e, bool *deep) { + if( e.type() != Array ) + return _regexMatches(rm, e); + + JSElemIter ai(e.embeddedObject()); + while( ai.more() ) { + Element z = ai.next(); + if( _regexMatches(rm, z) ) { + if( deep ) + *deep = true; + return true; + } + } + return false; } /* See if an object matches the query. @@ -495,7 +508,7 @@ bool JSMatcher::matches(JSObj& jsobj, bool *deep) { Element e = jsobj.getFieldDotted(rm.fieldName); if( e.eoo() ) return false; - if( !regexMatches(rm, e) ) + if( !regexMatches(rm, e, deep) ) return false; } |