From 23aacd101fe681e2632c05fdfe52311fc8032784 Mon Sep 17 00:00:00 2001 From: Uwe Schindler Date: Sun, 14 Feb 2010 16:44:46 +0000 Subject: [PATCH] LUCENE-1941: Fix Min/MaxPayloadFunction returns 0 when only one payload is present git-svn-id: https://svn.apache.org/repos/asf/lucene/java/trunk@910034 13f79535-47bb-0310-9956-ffa450edef68 --- CHANGES.txt | 4 ++++ .../lucene/search/payloads/MaxPayloadFunction.java | 6 +++++- .../lucene/search/payloads/MinPayloadFunction.java | 10 +++++++--- 3 files changed, 16 insertions(+), 4 deletions(-) diff --git a/CHANGES.txt b/CHANGES.txt index 1664a7556ab..85c40590081 100644 --- a/CHANGES.txt +++ b/CHANGES.txt @@ -235,6 +235,10 @@ Bug fixes reference to the Attribute/AttributeImpl classes which prevents unloading of custom attributes loaded by other classloaders (e.g. in Solr plugins). (Uwe Schindler) + + * LUCENE-1941: Fix Min/MaxPayloadFunction returns 0 when + only one payload is present. (Erik Hatcher, Mike McCandless + via Uwe Schindler) API Changes diff --git a/src/java/org/apache/lucene/search/payloads/MaxPayloadFunction.java b/src/java/org/apache/lucene/search/payloads/MaxPayloadFunction.java index fae7b35a407..90891ae5801 100644 --- a/src/java/org/apache/lucene/search/payloads/MaxPayloadFunction.java +++ b/src/java/org/apache/lucene/search/payloads/MaxPayloadFunction.java @@ -27,7 +27,11 @@ package org.apache.lucene.search.payloads; public class MaxPayloadFunction extends PayloadFunction { @Override public float currentScore(int docId, String field, int start, int end, int numPayloadsSeen, float currentScore, float currentPayloadScore) { - return Math.max(currentPayloadScore, currentScore); + if (numPayloadsSeen == 0) { + return currentPayloadScore; + } else { + return Math.max(currentPayloadScore, currentScore); + } } @Override diff --git a/src/java/org/apache/lucene/search/payloads/MinPayloadFunction.java b/src/java/org/apache/lucene/search/payloads/MinPayloadFunction.java index 9e5e9a2ef39..edea85099f3 100644 --- a/src/java/org/apache/lucene/search/payloads/MinPayloadFunction.java +++ b/src/java/org/apache/lucene/search/payloads/MinPayloadFunction.java @@ -23,9 +23,13 @@ package org.apache.lucene.search.payloads; **/ public class MinPayloadFunction extends PayloadFunction { - @Override - public float currentScore(int docId, String field, int start, int end, int numPayloadsSeen, float currentScore, float currentPayloadScore) { - return Math.min(currentPayloadScore, currentScore); + @Override + public float currentScore(int docId, String field, int start, int end, int numPayloadsSeen, float currentScore, float currentPayloadScore) { + if (numPayloadsSeen == 0) { + return currentPayloadScore; + } else { + return Math.min(currentPayloadScore, currentScore); + } } @Override