allow __fuzzy to override au_by_id in unified search
authorGalen Charlton <gmc@equinoxinitiative.org>
Fri, 15 May 2020 21:42:53 +0000 (17:42 -0400)
committerGalen Charlton <gmc@equinoxinitiative.org>
Fri, 15 May 2020 21:42:53 +0000 (17:42 -0400)
Signed-off-by: Galen Charlton <gmc@equinoxinitiative.org>
Open-ILS/src/perlmods/lib/OpenILS/Application/Acq/Search.pm

index 35965fe..dcdc20b 100644 (file)
@@ -260,7 +260,7 @@ sub gen_au_term {
 # actor.usr.id but by any of these user properties: card barcode, username,
 # given names and family name.
 sub prepare_au_terms {
-    my ($terms, $join_num) = @_;
+    my ($terms, $join_num, $default_to_by_id) = @_;
 
     my @joins = ();
     my $nots = 0;
@@ -283,8 +283,10 @@ sub prepare_au_terms {
                 $plain_hint ne "acqlia") {
                 my @new_terms = ();
                 my ($attr, $value) = breakdown_term($hint_unit->{$hint});
+                my $is_fuzzy = ref($value) eq 'HASH' && exists($value->{'ilike'});
                 if ($links->{$attr} and
-                    $links->{$attr}->{"class"} eq "au") {
+                    $links->{$attr}->{"class"} eq "au" and
+                    not($default_to_by_id and not $is_fuzzy)) {
                     push @joins, [$plain_hint, $attr, $join_num];
                     my $au_term = gen_au_term($value, $join_num);
                     if ($nots > 0) {
@@ -685,12 +687,10 @@ sub unified_search {
     $and_terms = prepare_terms($and_terms, 1);
     $or_terms = prepare_terms($or_terms, 0);
 
-    unless ($options->{au_by_id}) {
-        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));
-    }
+    my $offset = add_au_joins($graft_map, $hint, prepare_au_terms($and_terms, 0, $options->{au_by_id}));
+    add_au_joins($graft_map, $hint, prepare_au_terms($or_terms, $offset, $options->{au_by_id}));
 
-    my $offset = add_acqpro_joins($graft_map, $hint, prepare_acqpro_terms($and_terms));
+    $offset = add_acqpro_joins($graft_map, $hint, prepare_acqpro_terms($and_terms));
     add_acqpro_joins($graft_map, $hint, prepare_acqpro_terms($or_terms, $offset));
 
     # The join to acqmapinv needs to be a left join when present.