Advanced Search Summary
authorThomas Berezansky <tsbere@mvlc.org>
Fri, 1 Feb 2013 14:36:55 +0000 (09:36 -0500)
committerThomas Berezansky <tsbere@mvlc.org>
Wed, 13 Mar 2013 12:58:57 +0000 (08:58 -0400)
Instead of including search filter statements in the basic search box
create a "summary" underneath it.

Because it may not apply and isn't multi-select the format selector is
hidden when doing an advanced search. Due to how advanced searches translate
to basic searches the query type is hardocded to keyword in the background.

Also, for "Special" searches don't include the search terms as they will
not work in basic search.

Signed-off-by: Thomas Berezansky <tsbere@mvlc.org>
Open-ILS/src/perlmods/lib/OpenILS/WWW/EGCatLoader/Search.pm
Open-ILS/src/templates/opac/css/style.css.tt2
Open-ILS/src/templates/opac/parts/coded_value_summary.tt2 [new file with mode: 0644]
Open-ILS/src/templates/opac/parts/filter_group_summary.tt2 [new file with mode: 0644]
Open-ILS/src/templates/opac/parts/searchbar.tt2

index dea0145..8dfc0a4 100644 (file)
@@ -61,7 +61,8 @@ sub _prepare_biblio_search_basics {
 sub _prepare_biblio_search {
     my ($cgi, $ctx) = @_;
 
-    my $query = _prepare_biblio_search_basics($cgi) || '';
+    my $basic_query = _prepare_biblio_search_basics($cgi) || '';
+    my $query = $basic_query;
 
     $query .= ' ' . $ctx->{global_search_filter} if $ctx->{global_search_filter};
 
@@ -181,9 +182,9 @@ sub _prepare_biblio_search {
         return $query;
     };
 
-    $logger->info("tpac: site=$site, depth=$depth, query=$query");
+    $logger->info("tpac: site=$site, depth=$depth, query=$query, basic query=$basic_query");
 
-    return ($query, $site, $depth);
+    return ($query, $site, $depth, $basic_query);
 }
 
 sub _get_search_limit {
@@ -356,7 +357,7 @@ sub load_rresults {
         $offset = 0;
     }
 
-    my ($query, $site, $depth) = _prepare_biblio_search($cgi, $ctx);
+    my ($query, $site, $depth, $basic_query) = _prepare_biblio_search($cgi, $ctx);
 
     $self->get_staff_search_settings;
 
@@ -407,6 +408,7 @@ sub load_rresults {
 
         # Stuff these into the TT context so that templates can use them in redrawing forms
         $ctx->{processed_search_query} = $query;
+        $ctx->{processed_basic_search_query} = $basic_query;
 
         $query .= " $_" for @facets;
 
index fb39da2..b7edbba 100644 (file)
@@ -1503,3 +1503,11 @@ a.preflib_change {
 #patron_usr_barcode_not_found {
     font-weight: bold; color: [% css_colors.text_alert %];
 }
+
+.search_summary_filters_label {
+    font-weight: bold;
+    font-style: italic;
+}
+.search_summary_label {
+    font-weight: bold;
+}
diff --git a/Open-ILS/src/templates/opac/parts/coded_value_summary.tt2 b/Open-ILS/src/templates/opac/parts/coded_value_summary.tt2
new file mode 100644 (file)
index 0000000..611b69b
--- /dev/null
@@ -0,0 +1,34 @@
+[%- 
+IF !attr.size; attr = [attr]; END;
+all_values = [];
+FOR attr_class IN attr;
+    all_values = ctx.search_ccvm('ctype', attr_class, 'opac_visible', 't');
+    IF all_values.size > 0; LAST; END;
+END;
+name = name || "fi:" _ attr_class;
+values = values || CGI.param(name);
+
+sorter = [];
+FOR o IN all_values;
+    IF values.grep('^' _ o.code _ '$').size;
+        display_value = (o.search_label ? o.search_label : o.value) | html;
+        sorter.push({code => o.code, value  => display_value}); 
+    END;
+END;
+IF sorter.size;
+    sorter = sorter.sort('value');
+    joiner = '';
+    display_value = '';
+    FOR o IN sorter;
+        IF joiner != '';
+            display_value = display_value _ joiner;
+        ELSE;
+            joiner = ', ';
+        END;
+        display_value = display_value _ o.value;
+ -%]
+<input type="hidden" name="[% name %]" value="[% o.code | html | replace("'","%#39;") %]"/>
+[%-
+    END;
+    display_value;
+END -%]
diff --git a/Open-ILS/src/templates/opac/parts/filter_group_summary.tt2 b/Open-ILS/src/templates/opac/parts/filter_group_summary.tt2
new file mode 100644 (file)
index 0000000..57ed501
--- /dev/null
@@ -0,0 +1,35 @@
+[%- 
+IF !filter_group.size; filter_group = [filter_group]; END;
+group = '';
+FOR code IN filter_group;
+    group = ctx.search_filter_groups.$code;
+    LAST IF group AND group.entries.size;
+END;
+name = name || "fg:" _ group.code;
+values = values || CGI.param(name); 
+-%]
+
+sorter = [];
+FOR o IN group.entries;
+    IF values.grep('^' _ o.id _ '$').size;
+        display_value = o.query.label | html;
+        sorter.push({id => o.id, label => display_value, pos => o.pos}); 
+    END;
+END;
+IF sorter.size;
+    sorter = sorter.sort('pos');
+    joiner = '';
+    display_value = '';
+    FOR o IN sorter;
+        IF joiner != '';
+            display_value = display_value _ joiner;
+        ELSE;
+            joiner = ', ';
+        END;
+        display_value = display_value _ o.label;
+-%]
+<input type="hidden" name="[% name %]" value="[% o.id %] />
+[%-
+    END;
+    display_value;
+END -%]
index 8df74bb..3ea789f 100644 (file)
@@ -9,19 +9,22 @@
             id="home_adv_search_link"><span
             class="adv_search_font">[% l('Advanced Search') %]</span></a>
     </div>
-    <div class="searchbar">[%- l('Search ');
-        IF search.basic_config.type == 'attr';
-            INCLUDE "opac/parts/coded_value_selector.tt2"
-                attr=search.basic_config.group none_ok=1 none_label=search.basic_config.none_label;
-        ELSIF search.basic_config.type == 'filter';
-            INCLUDE "opac/parts/filter_group_selector.tt2"
-                filter_group=search.basic_config.group none_ok=1 none_label=search.basic_config.none_label;
-        END;
+    <div class="searchbar">[%-
+        IF NOT is_advanced;
+            l('Search ');
+            IF search.basic_config.type == 'attr';
+                INCLUDE "opac/parts/coded_value_selector.tt2"
+                    attr=search.basic_config.group none_ok=1 none_label=search.basic_config.none_label;
+            ELSIF search.basic_config.type == 'filter';
+                INCLUDE "opac/parts/filter_group_selector.tt2"
+                    filter_group=search.basic_config.group none_ok=1 none_label=search.basic_config.none_label;
+            END;
             l(' for ');
+        END;
         %]
         <span class='search_box_wrapper'>
             <input type="text" id="search_box" name="query"
-                value="[% is_advanced ? ctx.naive_query_scrub(ctx.processed_search_query) : CGI.param('query') | html %]"
+                value="[% is_special ? '' : (is_advanced ? ctx.processed_basic_search_query : CGI.param('query')) | html %]"
                 [%- IF use_autosuggest.enabled == "t" %]
                 dojoType="openils.widget.AutoSuggest" type_selector="'qtype'"
                 submitter="this.textbox.form.submit();"
                     [% IF basic_search != "f" %] autofocus [% END %] x-webkit-speech
                 [%- END # autosuggest enabled %] />
         </span>
-        [%- INCLUDE "opac/parts/qtype_selector.tt2" id="qtype";
-            l(' in '); INCLUDE build_org_selector show_loc_groups=1
+        [%-
+        IF NOT is_advanced;
+            INCLUDE "opac/parts/qtype_selector.tt2" id="qtype";
+        ELSE;
+            -%]<input type="hidden" name="qtype" value="keyword" />[%-
+        END;
+        l(' in '); INCLUDE build_org_selector show_loc_groups=1
     %]
     <span>
         <input id='search-submit-go' type="submit" value="[% l('Search') %]" alt="[% l('Search') %]" class="opac-button"
         [% END %]
     </div>
     [%- END %]
-    [% UNLESS took_care_of_form %]</form>[% END %]
     [% IF (is_advanced AND NOT is_special) AND CGI.param('qtype') %]
     <div class="opac-auto-102">
+        [%-
+        summary_items = [];
+        FOR adv_chunk IN search.adv_config;
+            NEXT IF adv_chunk.adv_hide;
+            summary_text = '';
+            IF adv_chunk.adv_special;
+                SWITCH adv_chunk.adv_special;
+                    CASE "lib_selector";
+                        # We do nothing with the lib selector right now
+                    CASE "pub_year";
+                        IF CGI.param('pubdate') AND CGI.param('date1');
+                            SWITCH CGI.param('pubdate');
+                                CASE "is";
+                                    summary_text = l("Is [_1]", CGI.param('date1')) | html;
+                                CASE "before";
+                                    summary_text = l("Before [_1]", CGI.param('date1')) | html;
+                                CASE "after";
+                                    summary_text = l("After [_1]", CGI.param('date1')) | html;
+                                CASE "between";
+                                    summary_text = l("Between [_1] and [_2]", CGI.param('date1'), CGI.param('date2')) | html;
+                            END;
+                            IF summary_text;
+                                value_html = CGI.param('pubdate') | html;
+                                summary_text = summary_text _ "<input type='hidden' name='pubdate' value='" _ value_html _ "' />";
+                                value_html = CGI.param('date1') | html;
+                                summary_text = summary_text _ "<input type='hidden' name='date1' value='" _ value_html _ "' />";
+                                value_html = CGI.param('date2') | html;
+                                summary_text = summary_text _ "<input type='hidden' name='date2' value='" _ value_html _ "' />";
+                            END;
+                        END;
+                    CASE "sort_selector";
+                        # We do nothing for sorting right now
+                END;
+            ELSIF adv_chunk.adv_attr;
+                summary_text = INCLUDE "opac/parts/coded_value_summary.tt2"
+                    attr=adv_chunk.adv_attr;
+            ELSIF adv_chunk.adv_filter;
+                summary_text = INCLUDE "opac/parts/filter_group_summary.tt2"
+                    filter_group=adv_chunk.adv_filter;
+            END;
+            IF summary_text;
+                summary_text = "<span class='search_summary_label'>" _ adv_chunk.adv_label _ " :</span> <span class='search_summary_value'>" _ summary_text _ "</span>";
+                summary_items.push(summary_text);
+            END;
+        END;
+        IF summary_items.size;
+            %] <span class='search_summary_filters_label'>[% l('Active Filters:'); %]</span> [%
+            summary_items.join(' | ');
+            %]<br />[%
+        END; %]
         [ <a href="[% mkurl(ctx.opac_root _ '/advanced') %]">[%
             l('Refine My Original Search')
         %]</a> ]
     </div>
     [% END %]
+    [% UNLESS took_care_of_form %]</form>[% END %]
     <!--
     <div id="breadcrumb">
         <a href="[% ctx.opac_root %]/home">[% l('Catalog Home') %]</a> &gt;