1 package org.apache.lucene.search.payloads;
3 import org.apache.lucene.search.Explanation;
5 * Licensed to the Apache Software Foundation (ASF) under one or more
6 * contributor license agreements. See the NOTICE file distributed with
7 * this work for additional information regarding copyright ownership.
8 * The ASF licenses this file to You under the Apache License, Version 2.0
9 * (the "License"); you may not use this file except in compliance with
10 * the License. You may obtain a copy of the License at
12 * http://www.apache.org/licenses/LICENSE-2.0
14 * Unless required by applicable law or agreed to in writing, software
15 * distributed under the License is distributed on an "AS IS" BASIS,
16 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
17 * See the License for the specific language governing permissions and
18 * limitations under the License.
22 * Calculates the minimum payload seen
25 public class MinPayloadFunction extends PayloadFunction {
28 public float currentScore(int docId, String field, int start, int end, int numPayloadsSeen, float currentScore, float currentPayloadScore) {
29 if (numPayloadsSeen == 0) {
30 return currentPayloadScore;
32 return Math.min(currentPayloadScore, currentScore);
37 public float docScore(int docId, String field, int numPayloadsSeen, float payloadScore) {
38 return numPayloadsSeen > 0 ? payloadScore : 1;
42 public Explanation explain(int doc, int numPayloadsSeen, float payloadScore) {
43 Explanation expl = new Explanation();
44 float minPayloadScore = (numPayloadsSeen > 0 ? payloadScore : 1);
45 expl.setValue(minPayloadScore);
46 expl.setDescription("MinPayloadFunction(...)");
50 public int hashCode() {
53 result = prime * result + this.getClass().hashCode();
58 public boolean equals(Object obj) {
63 if (getClass() != obj.getClass())