From b35bd6bd9c23782aa9f5c86bf602ce4b197d197c Mon Sep 17 00:00:00 2001
From: gmc <gmc@dcc99617-32d9-48b4-a31d-7c20da2025e4>
Date: Tue, 29 Mar 2011 02:06:43 +0000
Subject: [PATCH] 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
---
 .../src/perlmods/lib/OpenILS/Application/Storage/Publisher/metabib.pm | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)

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).
-- 
2.11.0