disable filters again, further tweaks to number_joins
authorIan Beckwith <ianb@erislabs.net>
Fri, 22 Oct 2010 15:24:01 +0000 (16:24 +0100)
committerIan Beckwith <ianb@erislabs.net>
Fri, 22 Oct 2010 15:24:01 +0000 (16:24 +0100)
lib/ID3FS/Path.pm

index 855ea9e..c800bdb 100644 (file)
@@ -30,7 +30,7 @@ our $PATH_ALLTRACKS= "TRACKS";
 our $PATH_NOARTIST = "NOARTIST";
 our $PATH_NOALBUM  = "NOALBUM";
 
-our $ENABLE_FILTER = 1;
+our $ENABLE_FILTER = 0;
 
 sub new
 {
@@ -358,7 +358,7 @@ sub parse
     }
 #    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";
@@ -372,8 +372,10 @@ sub number_joins
     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)
@@ -381,35 +383,39 @@ sub number_joins
            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;