0
0
mirror of https://github.com/mongodb/mongo.git synced 2024-12-01 09:32:32 +01:00

regex matches now supported, partially, when reaching into arrays.

This commit is contained in:
Dwight 2008-06-26 10:39:32 -04:00
parent 15dfe43b34
commit 1620d7ebdf

View File

@ -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;
}