Skip to content

Commit

Permalink
Item9826: add OP_match to HoistRE - I'd like to add this to 1.1.1, as…
Browse files Browse the repository at this point in the history
… it without, any query containing =~ is rediculously slow, as its evaluated in Perl, foreach topic

git-svn-id: http://svn.foswiki.org/branches/Release01x01@9613 0b4bb1d4-4e5a-0410-9cc4-b2b747904278
  • Loading branch information
SvenDowideit authored and SvenDowideit committed Oct 19, 2010
1 parent 85f1aca commit dba1ee2
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 1 deletion.
10 changes: 10 additions & 0 deletions UnitTestContrib/test/unit/HoistREsTests.pm
Expand Up @@ -228,5 +228,15 @@ sub test_hoistName2{
my $meta = $this->{meta};
my $val = $query->evaluate( tom => $meta, data => $meta );
}
sub test_hoist_OPMatch {
my $this = shift;
my $s = "text =~ '.*Green.*'";
my $queryParser = new Foswiki::Query::Parser();
my $query = $queryParser->parse($s);
my @filter = Foswiki::Query::HoistREs::hoist($query);
$this->assert_str_equals( '.*Green.*', join( ';', map {$_->{regex}}@filter ) );
my $meta = $this->{meta};
my $val = $query->evaluate( tom => $meta, data => $meta );
}

1;
14 changes: 13 additions & 1 deletion core/lib/Foswiki/Query/HoistREs.pm
Expand Up @@ -26,7 +26,7 @@ use Foswiki::Query::Node ();
# patterns we need to look for:
#
# top level is defined by a sequence of AND and OR conjunctions
# second level, = and ~
# second level, = and ~ and =~
# second level LHS is a field access
# second level RHS is a static string or number

Expand Down Expand Up @@ -188,6 +188,18 @@ sub _hoistEQ {
return $lhs;
}
}
elsif ( $node->{op}->{name} eq '=~' ) {
my $lhs = _hoistDOT( $node->{params}[0] );
my $rhs = _hoistConstant( $node->{params}[1] );
if ( $lhs && $rhs ) {
$rhs = quotemeta($rhs);
$rhs =~ s/\\\././g;
$rhs =~ s/\\\*/*/g;
$lhs->{regex} =~ s/\000RHS\001/$rhs/g;
$lhs->{source} = _hoistConstant( $node->{params}[1] );
return $lhs;
}
}

print STDERR "\tFAILED\n" if MONITOR_HOIST;
return;
Expand Down

0 comments on commit dba1ee2

Please sign in to comment.