our $PATH_NOARTIST = "NOARTIST";
our $PATH_NOALBUM = "NOALBUM";
-our $ENABLE_FILTER = 1;
+our $ENABLE_FILTER = 0;
sub new
{
}
# print "\nELEMENTS: ", join(' ', map { $_->name(); } @elements), "\n";
my @joins=$self->number_joins(@elements);
-# @joins=qw(INNER) unless(@joins);
+ @joins=qw(INNER) unless(@joins);
$self->{joins}=\@joins;
# print "AFTER: ", join(' ', map { $_->name() . "(" . $_->{table} . ")"; } @elements), "\n";
# print "JOINS: ", join(', ', @joins), "\n";
my($self, @elements)=@_;
my @joins=qw(INNER);
my $table=1;
+ my $nextjoin=undef;
my $lastop=undef;
- return () unless(@elements);
+ return (@joins) unless(@elements);
+ $table++ if(($elements[0]->type() == $TYPE_BOOL) && ($elements[0]->name eq "NOT"));
while(my $thing=shift @elements)
{
if($thing->type() == $TYPE_BOOL)
my $op=$thing->name();
if($op eq "AND")
{
- $table++;
- push(@joins, "INNER");
+ $nextjoin="INNER";
}
elsif($op eq "NOT")
{
- unless($lastop && $lastop eq "AND")
- {
- push(@joins, "LEFT");
- $table++;
- }
+ $nextjoin="LEFT";
}
elsif($op eq "OR")
{
- if($lastop && $lastop eq "NOT")
- {
- $table++;
- push(@joins, "INNER");
- }
+ $nextjoin="INNER" if($lastop && $lastop eq "NOT");
}
$lastop=$op;
}
else
{
- # skip tags with values
- if(@elements && $elements[0]->type() == $TYPE_TAG)
+ # if the expression ends in a tag that has a value
+ # (ie we have the tag and want the value)
+ # use an inner join
+ if(@elements)
{
- $thing=shift(@elements);
+ $thing=shift(@elements) if($elements[0]->type() == $TYPE_TAG);
}
+ elsif($self->{db}->tag_has_values($thing->id()))
+ {
+ $nextjoin="INNER" if($nextjoin);
+ }
+ $table++ if($nextjoin && $nextjoin eq "INNER");
$thing->table($table);
+ if($nextjoin)
+ {
+ $table++ if($nextjoin eq "LEFT");
+ push(@joins, $nextjoin);
+ $nextjoin=undef;
+ }
}
}
return @joins;