From: gmc <gmc@dcc99617-32d9-48b4-a31d-7c20da2025e4>
Date: Tue, 29 Mar 2011 02:06:43 +0000 (+0000)
Subject: bug 744687: fix multi-field MARC expert search
X-Git-Url: https://old-git.evergreen-ils.org/?a=commitdiff_plain;h=b35bd6bd9c23782aa9f5c86bf602ce4b197d197c;p=evergreen%2Fmasslnc.git

bug 744687: fix multi-field MARC expert search

Fixes bug where a bib that has multiple subfields
meeting one condition of a 2+ field MARC expert
search could end up in the results list even if
it didn't meet the other conditions (currently multi-field
MARC expert searches use implicit 'AND').

Signed-off-by: Galen Charlton <gmc@esilibrary.com>

git-svn-id: svn://svn.open-ils.org/ILS/trunk@19880 dcc99617-32d9-48b4-a31d-7c20da2025e4
---

diff --git a/Open-ILS/src/perlmods/lib/OpenILS/Application/Storage/Publisher/metabib.pm b/Open-ILS/src/perlmods/lib/OpenILS/Application/Storage/Publisher/metabib.pm
index ede8cd084c..e14cca5e31 100644
--- a/Open-ILS/src/perlmods/lib/OpenILS/Application/Storage/Publisher/metabib.pm
+++ b/Open-ILS/src/perlmods/lib/OpenILS/Application/Storage/Publisher/metabib.pm
@@ -458,7 +458,7 @@ sub biblio_multi_search_full_rec {
 		}
 		my $where = join(' OR ', @wheres);
 
-		push @selects, "SELECT id, record, $rank as sum FROM $search_table WHERE $where";
+		push @selects, "SELECT record, AVG($rank) as sum FROM $search_table WHERE $where GROUP BY record";
 
 	}
 
@@ -475,7 +475,7 @@ sub biblio_multi_search_full_rec {
 	my $cl_table = asset::copy_location->table;
 	my $br_table = biblio::record_entry->table;
 
-	my $cj = 'HAVING COUNT(x.id) = ' . scalar(@selects) if ($class_join eq 'AND');
+	my $cj = 'HAVING COUNT(x.record) = ' . scalar(@selects) if ($class_join eq 'AND');
 	my $search_table =
 		'(SELECT x.record, sum(x.sum) FROM (('.
 			join(') UNION ALL (', @selects).