From f1414c49e7bd880ffb3b7be3ed2604fe8888db0a Mon Sep 17 00:00:00 2001 From: Bill Erickson Date: Mon, 1 Aug 2011 17:34:35 -0400 Subject: [PATCH] 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 --- .../perlmods/lib/OpenILS/WWW/EGCatLoader/Search.pm | 12 +++++++++--- .../default/opac/parts/advanced/global_row.tt2 | 22 +++++++++++++++++----- 2 files changed, 26 insertions(+), 8 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 6397d844dd..220726d469 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,15 @@ sub _prepare_biblio_search_basics { $query =~ s/[\^\$]//g; $query = '^' . $query . '$'; } + + $logger->info("OPAC bool = $bool"); + $bool = ($bool eq 'or') ? '||' : '&&'; + $full_query = $full_query ? "($full_query $bool $query)" : $query; push @chunks, $query; } - return join(' ', @chunks); + $logger->info("OPAC FULL QUERY: $full_query"); + 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 %] +