add _gt/_lt operators to unified search method
authorGalen Charlton <gmc@equinoxinitiative.org>
Fri, 7 Feb 2020 15:05:54 +0000 (10:05 -0500)
committerGalen Charlton <gmc@equinoxinitiative.org>
Fri, 7 Feb 2020 15:05:54 +0000 (10:05 -0500)
Signed-off-by: Galen Charlton <gmc@equinoxinitiative.org>
Open-ILS/src/perlmods/lib/OpenILS/Application/Acq/Search.pm

index 83d23a8..c16a5d3 100644 (file)
@@ -52,11 +52,13 @@ sub could_be_range {
 }
 
 sub castdate {
-    my ($value, $gte, $lte, $between) = @_;
+    my ($value, $gte, $lte, $between, $gt, $lt) = @_;
 
     my $op = "=";
     $op = ">=" if $gte;
     $op = "<=" if $lte;
+    $op = ">"  if $gt;
+    $op = "<"  if $lt;
     $op = "between" if $between;
 
     # avoid transforming a date if the match value is NULL.
@@ -168,6 +170,8 @@ sub breakdown_term {
         $term->{"__gte"} ? 1 : 0,
         $term->{"__lte"} ? 1 : 0,
         $term->{"__age"} ? 1 : 0,
+        $term->{"__gt"} ? 1 : 0,
+        $term->{"__lt"} ? 1 : 0,
     );
 }
 
@@ -328,7 +332,7 @@ sub prepare_terms {
         $outer_clause->{$conj} = [] unless $outer_clause->{$conj};
         foreach my $unit (@{$terms->{$class}}) {
             my $special_clause;
-            my ($k, $v, $fuzzy, $between, $not, $starts, $ends, $castdate, $gte, $lte, $age) =
+            my ($k, $v, $fuzzy, $between, $not, $starts, $ends, $castdate, $gte, $lte, $age, $gt, $lt) =
                 breakdown_term($unit);
 
             my $term_clause;
@@ -360,10 +364,13 @@ sub prepare_terms {
                 }
             } elsif (check_1d_max($v)) {
                 if ($castdate) {
-                    $v = castdate($v, $gte, $lte);
+                    $v = castdate($v, $gte, $lte, 0, $gt, $lt);
                 } elsif ($gte or $lte) {
                     my $op = $gte ? '>=' : '<=';
                     $v = {$op => $v};
+                } elsif ($gt or $lt) {
+                    my $op = $gt ? '>' : '<';
+                    $v = {$op => $v};
                 } elsif (not ref $v and $not) {
                     # the old way, NOT (blah.id = $v) needs to be
                     # (blah.id <> $x OR blah.id IS NULL)