From 3eeb80320ce04ba4e910cce828e28dfc8cd2fa94 Mon Sep 17 00:00:00 2001 From: Lebbeous Fogle-Weekley Date: Tue, 8 May 2012 11:25:23 -0400 Subject: [PATCH] TPAC: Keep site() and depth() out of basic search box when widgets suffice This is a short term but working solution to the problem described here: https://bugs.launchpad.net/evergreen/+bug/986196 Now when you have a selection for site on the advanced search page, it doesn't lead to redundant site() and depth() terms in your basic search query box. Item type selections and search class selections (keyword/author/etc) can still lead to ugliness in the advanced search box, but that's because in the advanced search page you get a multi-select widget for item type and in a basic search page you only get a single-select dropdown, so there's not a clean way to map your advanced page selections to basic page selections. Search classes are kind of the same issue, since you have three dropdowns on the advanced search page and one on the basic. So the "bigger" problem is one that we will have to solve later, but for the common case at least we don't get the extra site() and depth() for now. Signed-off-by: Lebbeous Fogle-Weekley Signed-off-by: Ben Shum --- .../lib/OpenILS/WWW/EGCatLoader/Search.pm | 23 +++++++++++++++---- .../src/templates/opac/parts/searchbar.tt2 | 2 +- 2 files changed, 20 insertions(+), 5 deletions(-) diff --git a/Open-ILS/src/perlmods/lib/OpenILS/WWW/EGCatLoader/Search.pm b/Open-ILS/src/perlmods/lib/OpenILS/WWW/EGCatLoader/Search.pm index 53365e0bfc..1bf8b61c63 100644 --- a/Open-ILS/src/perlmods/lib/OpenILS/WWW/EGCatLoader/Search.pm +++ b/Open-ILS/src/perlmods/lib/OpenILS/WWW/EGCatLoader/Search.pm @@ -100,11 +100,14 @@ sub _prepare_biblio_search { } } - my $site; + my (@naive_query_re, $site); + my $org = $ctx->{search_ou}; if (defined($org) and $org ne '' and ($org ne $ctx->{aou_tree}->()->id) and not $query =~ /site\(\S+\)/) { - $site = $ctx->{get_aou}->($org)->shortname; - $query .= " site($site)"; + my $thing = " site(" . $ctx->{get_aou}->($org)->shortname . ")"; + + $query .= $thing; + push @naive_query_re, $thing; } my $pref_ou = $ctx->{pref_ou}; @@ -137,9 +140,21 @@ sub _prepare_biblio_search { my ($org) = grep { $_->shortname eq $site } @{$ctx->{aou_list}->()}; $depth = $org->ou_type->depth; } - $query .= " depth($depth)"; + my $thing = " depth($depth)"; + + $query .= $thing; + push @naive_query_re, $thing; } + # This gives templates a way to take site() and depth() back out of + # query strings when they shouldn't be there (because they're controllable + # with other widgets). + $ctx->{naive_query_scrub} = sub { + my ($query) = @_; + $query =~ s/\Q$_\E// foreach (@naive_query_re); + return $query; + }; + $logger->info("tpac: site=$site, depth=$depth, query=$query"); return ($query, $site, $depth); diff --git a/Open-ILS/src/templates/opac/parts/searchbar.tt2 b/Open-ILS/src/templates/opac/parts/searchbar.tt2 index fccac1132c..3a2f6f0f71 100644 --- a/Open-ILS/src/templates/opac/parts/searchbar.tt2 +++ b/Open-ILS/src/templates/opac/parts/searchbar.tt2 @@ -16,7 +16,7 @@ %]