From d5c786e515791eaf53992dac8a6bd11520a661d6 Mon Sep 17 00:00:00 2001
From: Mike Rylander <mrylander@gmail.com>
Date: Fri, 22 Apr 2011 12:55:37 -0400
Subject: [PATCH] Secondary sort by quality ratio (higher means incoming is
 more "good" than existing) instead of simple incoming quality, which is a
 no-op (all the same)

---
 Open-ILS/src/sql/Pg/012.schema.vandelay.sql | 5 ++++-
 1 file changed, 4 insertions(+), 1 deletion(-)

diff --git a/Open-ILS/src/sql/Pg/012.schema.vandelay.sql b/Open-ILS/src/sql/Pg/012.schema.vandelay.sql
index f98f6ca182..61b49c21e9 100644
--- a/Open-ILS/src/sql/Pg/012.schema.vandelay.sql
+++ b/Open-ILS/src/sql/Pg/012.schema.vandelay.sql
@@ -1301,7 +1301,10 @@ BEGIN
       WHERE m.queued_record = import_id
             AND r.id = m.eg_record
             AND m.quality::NUMERIC / COALESCE(NULLIF(vandelay.incoming_record_quality(r.marc),0),1)::NUMERIC >= lwm_ratio_value
-      ORDER BY m.match_score DESC, m.quality DESC, id limit 1;
+      ORDER BY  m.match_score DESC,
+                m.quality::NUMERIC / COALESCE(NULLIF(vandelay.incoming_record_quality(r.marc),0),1)::NUMERIC DESC,
+                id
+      LIMIT 1;
 
     IF eg_id IS NULL THEN
         -- RAISE NOTICE 'incoming record is not of hight enough quality';
-- 
2.11.0