Implement mike's suggestions from #esi-dev on 27 Feb 2011
authorsenator <lebbeous@esilibrary.com>
Mon, 28 Feb 2011 13:36:43 +0000 (08:36 -0500)
committersenator <lebbeous@esilibrary.com>
Mon, 28 Feb 2011 13:36:43 +0000 (08:36 -0500)
This makes an "exact" search build a query with starting and ending
anchors, and adds a new contains-value called "phrase" which does what
"exact" was doing before.

Open-ILS/src/perlmods/lib/OpenILS/WWW/EGCatLoader/Search.pm
Open-ILS/web/templates/default/opac/parts/advanced/global_row.tt2

index e4b0741..e2ea613 100644 (file)
@@ -30,9 +30,12 @@ sub _prepare_biblio_search_basics {
             $query =~ s/"//g;
             $query = ('"' . $query . '"') if index $query, ' ';
             $query = '-' . $query;
-        } elsif ($contains eq 'exact') {
+        } elsif ($contains eq 'phrase') {
             $query =~ s/"//g;
             $query = ('"' . $query . '"') if index $query, ' ';
+        } elsif ($contains eq 'exact') {
+            $query =~ s/[\^\$]//g;
+            $query = '^' . $query . '$';
         }
         push @chunks, $query;
     }
@@ -103,24 +106,10 @@ sub load_rresults {
     my $offset = $page * $limit;
 
     my $query = _prepare_biblio_search($cgi, $ctx);
-# XXX for now, we still put limit and offset into a hash rather than
-# right into the query string, because use of the limit() and offset() filters
-# in the query string doesn't actually work as advertised.
-#
-# When you do, with offsets > 0, you get wrong results in the 'count'
-# part of the result hash from open-ils.search.biblio.multiclass.query.
-#
-#    if (defined $cgi->param('limit') or not $query =~ /limit\(\d+\)/) {
-#        $query =~ s/ limit\(\d+\)//;
-#        $query .= " limit($limit)";
-#    }
-#    if (defined $cgi->param('page') or not $query =~ /offset\(\d+\)/) {
-#        $query =~ s/ offset\(\d+\)//;
-#        $query .= " offset($offset)";
-#    }
+    # Limit and offset will stay here. Everything else should be part of
+    # the query string, not special args.
     my $args = {'limit' => $limit, 'offset' => $offset};
 
-
     # Stuff these into the TT context so that templates can use them in redrawing forms
     $ctx->{processed_search_query} = $query;
 
index 2f874c9..ae8081e 100644 (file)
@@ -1,4 +1,10 @@
 [%
+    contains_options = [
+        {value => 'contains', label => l('Contains')},
+        {value => 'nocontains', label => l('Does not contain')},
+        {value => 'phrase', label => l('Contains phrase')},
+        {value => 'exact', label => l('Matches exactly')}
+    ];
     contains = CGI.param('contains');
     queries = CGI.param('query');
     qtypes = CGI.param('qtype') || ['keyword' x 3];
                 query_type=qtype %]
         </span>
         <select name='contains' style='margin-right: 7px;'>
-            <option value='contains'[% c == 'contains' ? ' selected="selected"' : '' %]>[% l("Contains") %]</option>
-            <option value='nocontains'[% c == 'nocontains' ? ' selected="selected"' : '' %]>[% l("Does not contain") %]</option>
-            <option value='exact'[% c == 'exact' ? ' selected="selected"' : '' %]>[% l("Matches Exactly") %]</option>
+            [% FOR o IN contains_options;
+                |l(o.value, o.label) -%]
+            <option value="[_1]"[% c == o.value ? ' selected="selected"' : '' %]>[_2]</option>
+            [% END; END %]
         </select>
         <input type='text' size='18' name='query' value="[% q | html %]" />
         <a href="javascript:;" class="row-remover"