fix acq general search? collab/senator/acq-unified-search-refactor
authorLebbeous Fogle-Weekley <lebbeous@esilibrary.com>
Fri, 13 Apr 2012 22:12:46 +0000 (18:12 -0400)
committerLebbeous Fogle-Weekley <lebbeous@esilibrary.com>
Fri, 13 Apr 2012 22:13:57 +0000 (18:13 -0400)
out the door, will amend this commit msg later.

Signed-off-by: Lebbeous Fogle-Weekley <lebbeous@esilibrary.com>
Open-ILS/src/perlmods/lib/OpenILS/Application/Acq/Search.pm

index 16844d9..f8dda0d 100644 (file)
@@ -262,7 +262,8 @@ sub prepare_terms {
 }
 
 sub add_au_joins {
-    my ($graft_map) = shift;
+    my $graft_map = shift;
+    my $core_hint = shift;
 
     my $n = 0;
     foreach my $join (@_) {
@@ -282,8 +283,14 @@ sub add_au_joins {
                 }
             }
         };
-        $start->{"join"} ||= {};
-        $start->{"join"}->{"au$num"} = $clause;
+
+        if ($hint eq $core_hint) {
+            $start->{"au$num"} = $clause;
+        } else {
+            $start->{"join"} ||= {};
+            $start->{"join"}->{"au$num"} = $clause;
+        }
+
         $n++;
     }
     $n;
@@ -294,7 +301,7 @@ sub build_from_clause_and_joins {
 
     my %graft_map = ();
 
-    $query->{from}{$core} = {};
+    $graft_map{$core} = $query->{from}{$core} = {};
 
     my $join_type = keys(%$or_terms) ? "left" : "inner";
 
@@ -322,10 +329,11 @@ sub build_from_clause_and_joins {
                     $acqlia_join->();
             }
         } elsif ($class eq 'acqinv' or $core eq 'acqinv') {
-            $graft_map{$class} = $query->{from}{$core}{acqmapinv}{join}{$class};
+            $graft_map{$class} =
+                $query->{from}{$core}{acqmapinv}{join}{$class} ||= {};
             $graft_map{$class}{type} = $join_type;
         } else {
-            $graft_map{$class} = $query->{from}{$core}{$class};
+            $graft_map{$class} = $query->{from}{$core}{$class} ||= {};
             $graft_map{$class}{type} = $join_type;
         }
     }
@@ -441,8 +449,8 @@ q/order_by clause must be of the long form, like:
     $and_terms = prepare_terms($and_terms, 1);
     $or_terms = prepare_terms($or_terms, 0);
 
-    my $offset = add_au_joins($graft_map, prepare_au_terms($and_terms));
-    add_au_joins($graft_map, prepare_au_terms($or_terms, $offset));
+    my $offset = add_au_joins($graft_map, $hint, prepare_au_terms($and_terms));
+    add_au_joins($graft_map, $hint, prepare_au_terms($or_terms, $offset));
 
     if ($and_terms and $or_terms) {
         $query->{"where"} = {