TPAC: Keep site() and depth() out of basic search box when widgets suffice
authorLebbeous Fogle-Weekley <lebbeous@esilibrary.com>
Tue, 8 May 2012 15:25:23 +0000 (11:25 -0400)
committerLebbeous Fogle-Weekley <lebbeous@esilibrary.com>
Wed, 9 May 2012 18:49:03 +0000 (14:49 -0400)
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 <lebbeous@esilibrary.com>
Signed-off-by: Ben Shum <bshum@biblio.org>

Open-ILS/src/perlmods/lib/OpenILS/WWW/EGCatLoader/Search.pm
Open-ILS/src/templates/opac/parts/searchbar.tt2

index 53365e0..1bf8b61 100644 (file)
@@ -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);
index fccac11..3a2f6f0 100644 (file)
@@ -16,7 +16,7 @@
         %]
         <span class='search_box_wrapper'>
             <input type="text" id="search_box" name="query"
-                value="[% is_advanced ? ctx.processed_search_query : CGI.param('query') | html %]"
+                value="[% is_advanced ? ctx.naive_query_scrub(ctx.processed_search_query) : CGI.param('query') | html %]"
                 [%- IF use_autosuggest.enabled == "t" %]
                 dojoType="openils.widget.AutoSuggest" type_selector="'qtype'"
                 submitter="this.textbox.form.submit();"