[open-ils-commits] r16087 - trunk/Open-ILS/src/perlmods/OpenILS/Application/Acq (senator)

svn at svn.open-ils.org svn at svn.open-ils.org
Thu Apr 1 12:18:22 EDT 2010


Author: senator
Date: 2010-04-01 12:18:19 -0400 (Thu, 01 Apr 2010)
New Revision: 16087

Modified:
   trunk/Open-ILS/src/perlmods/OpenILS/Application/Acq/Search.pm
Log:
Acq: ML logic to support the "not" operator in unified acq search queries


Modified: trunk/Open-ILS/src/perlmods/OpenILS/Application/Acq/Search.pm
===================================================================
--- trunk/Open-ILS/src/perlmods/OpenILS/Application/Acq/Search.pm	2010-04-01 15:29:40 UTC (rev 16086)
+++ trunk/Open-ILS/src/perlmods/OpenILS/Application/Acq/Search.pm	2010-04-01 16:18:19 UTC (rev 16087)
@@ -49,31 +49,30 @@
 
     my @phrases = ();
     foreach my $unit (@{$acqlia}) {
-        my $something = 0;
         my $subquery = {
             "select" => {"acqlia" => ["id"]},
             "from" => "acqlia",
             "where" => {"-and" => [{"lineitem" => {"=" => {"+jub" => "id"}}}]}
         };
 
-        while (my ($k, $v) = each %$unit) {
-            my $point = $subquery->{"where"}->{"-and"};
-            if ($k !~ /^__/) {
-                push @$point, {"definition" => $k};
-                $something++;
+        my ($k, $v, $fuzzy, $between, $not) = breakdown_term($unit);
+        my $point = $subquery->{"where"}->{"-and"};
+        my $term_clause;
 
-                if ($unit->{"__fuzzy"} and not ref $v) {
-                    push @$point, {"attr_value" => {"ilike" => "%" . $v . "%"}};
-                } elsif ($unit->{"__between"} and could_be_range($v)) {
-                    push @$point, {"attr_value" => {"between" => $v}};
-                } elsif (check_1d_max($v)) {
-                    push @$point, {"attr_value" => $v};
-                } else {
-                    $something--;
-                }
-            }
+        push @$point, {"definition" => $k};
+
+        if ($fuzzy and not ref $v) {
+            push @$point, {"attr_value" => {"ilike" => "%" . $v . "%"}};
+        } elsif ($between and could_be_range($v)) {
+            push @$point, {"attr_value" => {"between" => $v}};
+        } elsif (check_1d_max($v)) {
+            push @$point, {"attr_value" => $v};
+        } else {
+            next;
         }
-        push @phrases, {"-exists" => $subquery} if $something;
+
+        my $operator = $not ? "-not-exists" : "-exists";
+        push @phrases, {$operator => $subquery};
     }
     @phrases;
 }
@@ -85,25 +84,30 @@
     my $result = {"+acqlia" => {"-or" => $point}};
 
     foreach my $unit (@$acqlia) {
-        my ($k, $v, $fuzzy, $between) = breakdown_term($unit);
+        my ($k, $v, $fuzzy, $between, $not) = breakdown_term($unit);
+        my $term_clause;
         if ($fuzzy and not ref $v) {
-            push @$point, {
+            $term_clause = {
                 "-and" => {
                     "definition" => $k,
                     "attr_value" => {"ilike" => "%" . $v . "%"}
                 }
             };
         } elsif ($between and could_be_range($v)) {
-            push @$point, {
+            $term_clause = {
                 "-and" => {
                     "definition" => $k, "attr_value" => {"between" => $v}
                 }
             };
         } elsif (check_1d_max($v)) {
-            push @$point, {
+            $term_clause = {
                 "-and" => {"definition" => $k, "attr_value" => $v}
             };
+        } else {
+            next;
         }
+
+        push @$point, $not ? {"-not" => $term_clause} : $term_clause;
     }
     $result;
 }
@@ -115,7 +119,8 @@
     (
         $key, $term->{$key},
         $term->{"__fuzzy"} ? 1 : 0,
-        $term->{"__between"} ? 1 : 0
+        $term->{"__between"} ? 1 : 0,
+        $term->{"__not"} ? 1 : 0
     );
 }
 
@@ -201,14 +206,19 @@
         my $clause = [];
         $outer_clause->{$conj} = [] unless $outer_clause->{$conj};
         foreach my $unit (@{$terms->{$class}}) {
-            my ($k, $v, $fuzzy, $between) = breakdown_term($unit);
+            my ($k, $v, $fuzzy, $between, $not) = breakdown_term($unit);
+            my $term_clause;
             if ($fuzzy and not ref $v) {
-                push @$clause, {$k => {"ilike" => "%" . $v . "%"}};
+                $term_clause = {$k => {"ilike" => "%" . $v . "%"}};
             } elsif ($between and could_be_range($v)) {
-                push @$clause, {$k => {"between" => $v}};
+                $term_clause = {$k => {"between" => $v}};
             } elsif (check_1d_max($v)) {
-                push @$clause, {$k => $v};
+                $term_clause = {$k => $v};
+            } else {
+                next;
             }
+
+            push @$clause, $not ? {"-not" => $term_clause} : $term_clause;
         }
         push @{$outer_clause->{$conj}}, {"+" . $class => $clause};
     }
@@ -318,12 +328,12 @@
         "from" => {
             "jub" => {
                 "acqpo" => {
-                    "type" => "full",
+                    "type" => "left",
                     "field" => "id",
                     "fkey" => "purchase_order"
                 },
                 "acqpl" => {
-                    "type" => "full",
+                    "type" => "left",
                     "field" => "id",
                     "fkey" => "picklist"
                 }



More information about the open-ils-commits mailing list