From: Bill Erickson Date: Mon, 1 Aug 2011 21:34:35 +0000 (-0400) Subject: Support for boolean operators in advanced search X-Git-Url: https://old-git.evergreen-ils.org/?a=commitdiff_plain;h=2b3ff4a63c20d4ab4f47af9c3165b359828c0b27;p=evergreen%2Fpines.git Support for boolean operators in advanced search Implements a new column with And/Or selectors. Terms are grouped from top to bottom in the UI as left to right in the compiled query. A && B || C && D => ((A && B) || C) && D Signed-off-by: Bill Erickson --- 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 6397d844dd..62ad13c927 100644 --- a/Open-ILS/src/perlmods/lib/OpenILS/WWW/EGCatLoader/Search.pm +++ b/Open-ILS/src/perlmods/lib/OpenILS/WWW/EGCatLoader/Search.pm @@ -17,12 +17,13 @@ sub _prepare_biblio_search_basics { return $cgi->param('query') unless $cgi->param('qtype'); my %parts; - my @part_names = qw/qtype contains query/; + my @part_names = qw/qtype contains query bool/; $parts{$_} = [ $cgi->param($_) ] for (@part_names); + my $full_query = ''; my @chunks = (); for (my $i = 0; $i < scalar @{$parts{'qtype'}}; $i++) { - my ($qtype, $contains, $query) = map { $parts{$_}->[$i] } @part_names; + my ($qtype, $contains, $query, $bool) = map { $parts{$_}->[$i] } @part_names; next unless $query =~ /\S/; push(@chunks, $qtype . ':') unless $qtype eq 'keyword' and $i == 0; @@ -41,10 +42,13 @@ sub _prepare_biblio_search_basics { $query =~ s/[\^\$]//g; $query = '^' . $query . '$'; } + + $bool = ($bool and $bool eq 'or') ? '||' : '&&'; + $full_query = $full_query ? "($full_query $bool $query)" : $query; push @chunks, $query; } - return join(' ', @chunks); + return $full_query; } sub _prepare_biblio_search { diff --git a/Open-ILS/web/templates/default/opac/parts/advanced/global_row.tt2 b/Open-ILS/web/templates/default/opac/parts/advanced/global_row.tt2 index f2fbbe6270..3e5dec503c 100644 --- a/Open-ILS/web/templates/default/opac/parts/advanced/global_row.tt2 +++ b/Open-ILS/web/templates/default/opac/parts/advanced/global_row.tt2 @@ -7,21 +7,33 @@ ]; contains = CGI.param('contains'); queries = CGI.param('query'); + bools = CGI.param('bool') || ['and' x 3]; qtypes = CGI.param('qtype') || ['keyword' x 3]; FOR qtype IN qtypes; c = contains.shift; + b = bools.shift; q = queries.shift; %] - + + + + + + + + [% INCLUDE "default/opac/parts/qtype_selector.tt2" query_type=qtype %] +