Skip to content

Commit

Permalink
Item10596: fix a number of constants based queries, and fix '1' and '0'
Browse files Browse the repository at this point in the history
git-svn-id: http://svn.foswiki.org/trunk/MongoDBPlugin@11485 0b4bb1d4-4e5a-0410-9cc4-b2b747904278
  • Loading branch information
SvenDowideit authored and SvenDowideit committed Apr 18, 2011
1 parent e82cb1d commit a49d1ab
Show file tree
Hide file tree
Showing 3 changed files with 62 additions and 5 deletions.
10 changes: 9 additions & 1 deletion lib/Foswiki/Plugins/MongoDBPlugin/HoistMongoDB.pm
Expand Up @@ -36,10 +36,18 @@ sub hoist {
my ( $node, $indent ) = @_;

print STDERR "HoistMongoDB::hoist from: ", $node->stringify(), "\n"
#print STDERR "HoistMongoDB::hoist from: ", Dumper($node), "\n"
if MONITOR
or MONITOR_DETAIL;

return undef unless ref( $node->{op} );
if (ref( $node->{op} ) eq '') {
if (Foswiki::Func::isTrue($node->{params}[0])) {
return {};
} else {
#TODO: or return false, or undef?
return {'1' => '0'};
}
}

#TODO: use IxHash to keep the hash order - _some_ parts of queries are order sensitive
# my %mongoQuery = ();
Expand Down
10 changes: 6 additions & 4 deletions lib/Foswiki/Store/QueryAlgorithms/MongoDB.pm
Expand Up @@ -106,7 +106,7 @@ sub _webQuery {
#presuming that the inputTopicSet is not yet defined, we need to add the topics=, excludetopic= and web options to the query.
my $extra_query;
{
my @option_query = ("web='".$web."'");
my @option_query = ();
if ($options->{topic}) {
push(@option_query, convertTopicPatternToLonghandQuery($options->{topic}));
}
Expand All @@ -121,7 +121,9 @@ sub _webQuery {
my $queryStr = join(' AND ', @option_query);

#print STDERR "NNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNN($queryStr)\n";

if ($queryStr eq '') {
$queryStr = '1';
}
my $theParser = $session->search->{queryParser};
$extra_query = $theParser->parse( $queryStr, $options );
}
Expand Down Expand Up @@ -160,7 +162,7 @@ sub _webQuery {

if ( not defined($mongoQuery) ) {
print STDERR
"MongoDB QuerySearch - failed to hoist to MongoDB - please report the error to Sven.\n";
"MongoDB QuerySearch - failed to hoist to MongoDB (".$query->stringify().") - please report the error to Sven.\n";

#falling through to old regex code
}
Expand Down Expand Up @@ -227,7 +229,7 @@ sub _webQuery {
}

require Foswiki::Query::HoistREs;
my $hoistedREs = Foswiki::Query::HoistREs::collatedHoist($query);
my $hoistedREs = Foswiki::Query::HoistREs::hoist($query);

if ( ( !defined( $options->{topic} ) )
and ( $hoistedREs->{name} ) )
Expand Down
47 changes: 47 additions & 0 deletions test/unit/HoistMongoDBsTests.pm
Expand Up @@ -1506,7 +1506,54 @@ sub test_hoist_Item10515 {
);
}

sub test_hoist_false {
my $this = shift;
my $s = "0";
my $queryParser = new Foswiki::Query::Parser();
my $query = $queryParser->parse($s);
my $mongoDBQuery =
Foswiki::Plugins::MongoDBPlugin::HoistMongoDB::hoist($query);

$this->do_Assert(
$query,
$mongoDBQuery,
{
#TODO: this is not really a true query in mongo, and just happens to return nothing :/
'1' => '0'
}
);
}

sub test_hoist_true {
my $this = shift;
my $s = "1";
my $queryParser = new Foswiki::Query::Parser();
my $query = $queryParser->parse($s);
my $mongoDBQuery =
Foswiki::Plugins::MongoDBPlugin::HoistMongoDB::hoist($query);

$this->do_Assert(
$query,
$mongoDBQuery,
{
}
);
}
sub test_hoist_explicit_true {
my $this = shift;
my $s = "1";
my $queryParser = new Foswiki::Query::Parser();
my $query = $queryParser->parse($s);
my $mongoDBQuery =
Foswiki::Plugins::MongoDBPlugin::HoistMongoDB::hoist($query);

$this->do_Assert(
$query,
$mongoDBQuery,
{
}
);
}

#test written to match Fn_SEARCH::verify_formQuery2
#Item10520: in Sven's reading of System.QuerySearch, this should return no results, as there is no field of the name 'TestForm'
Expand Down

0 comments on commit a49d1ab

Please sign in to comment.