Skip to content

Commit

Permalink
Item10276: regex search for /.*/ produces high load un-necessarily
Browse files Browse the repository at this point in the history
git-svn-id: http://svn.foswiki.org/trunk/MongoDBPlugin@10592 0b4bb1d4-4e5a-0410-9cc4-b2b747904278
  • Loading branch information
SvenDowideit authored and SvenDowideit committed Jan 21, 2011
1 parent 70ada39 commit b0e644f
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 2 deletions.
4 changes: 4 additions & 0 deletions lib/Foswiki/Plugins/MongoDBPlugin/HoistMongoDB.pm
Expand Up @@ -634,6 +634,10 @@ sub hoistMongoDB {
my $rhs = quotemeta( $node->{rhs} );
$rhs =~ s/\\\././g;
$rhs =~ s/\\\*/*/g;

#marginal speedup, but still every straw
return {} if ($rhs eq '.*');

$rhs = qr/$rhs/;

return { $node->{lhs} => $rhs };
Expand Down
12 changes: 10 additions & 2 deletions lib/Foswiki/Store/SearchAlgorithms/MongoDB.pm
Expand Up @@ -69,13 +69,17 @@ sub search {
my %elements;

push( @{ $elements{_web} }, $web );
push(

#dont' add a search for all..
if ($searchString ne '.*') {
push(
@{ $elements{_raw_text} },
{
'$regex' => $searchString,
'$options' => ( $casesensitive ? '' : 'i' )
}
);
);
}

my $cursor =
Foswiki::Plugins::MongoDBPlugin::getMongoDB()->query('current', \%elements);
Expand Down Expand Up @@ -236,6 +240,10 @@ sub _webQuery {
$raw_searchString =~ s/^(.*)$/\\b$1\\b/go
if $options->{'wordboundaries'};
}

#remove pointless regex..
$raw_searchString = undef if ($raw_searchString eq '.*');
$topic_searchString = undef if ($topic_searchString eq '.*');

if ($counter == 0) {
my $raw_text_regex = convertQueryToMongoRegex ($raw_searchString, $casesensitive, $invertSearch);
Expand Down

0 comments on commit b0e644f

Please sign in to comment.