~slub.team/goobi-indexserver/3.x

« back to all changes in this revision

Viewing changes to lucene/src/java/org/apache/lucene/search/payloads/MinPayloadFunction.java

  • Committer: Sebastian Meyer
  • Date: 2012-08-03 09:12:40 UTC
  • Revision ID: sebastian.meyer@slub-dresden.de-20120803091240-x6861b0vabq1xror
Remove Lucene and Solr source code and add patches instead
Fix Bug #985487: Auto-suggestion for the search interface

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
 
package org.apache.lucene.search.payloads;
2
 
 
3
 
import org.apache.lucene.search.Explanation;
4
 
/**
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
11
 
 *
12
 
 *     http://www.apache.org/licenses/LICENSE-2.0
13
 
 *
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.
19
 
 */
20
 
 
21
 
/**
22
 
 * Calculates the minimum payload seen
23
 
 *
24
 
 **/
25
 
public class MinPayloadFunction extends PayloadFunction {
26
 
 
27
 
  @Override
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;
31
 
    } else {
32
 
                return Math.min(currentPayloadScore, currentScore);
33
 
        }
34
 
  }
35
 
 
36
 
  @Override
37
 
  public float docScore(int docId, String field, int numPayloadsSeen, float payloadScore) {
38
 
    return numPayloadsSeen > 0 ? payloadScore : 1;
39
 
  }
40
 
  
41
 
  @Override
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(...)");
47
 
          return expl;
48
 
  }  
49
 
  @Override
50
 
  public int hashCode() {
51
 
    final int prime = 31;
52
 
    int result = 1;
53
 
    result = prime * result + this.getClass().hashCode();
54
 
    return result;
55
 
  }
56
 
 
57
 
  @Override
58
 
  public boolean equals(Object obj) {
59
 
    if (this == obj)
60
 
      return true;
61
 
    if (obj == null)
62
 
      return false;
63
 
    if (getClass() != obj.getClass())
64
 
      return false;
65
 
    return true;
66
 
  }
67
 
 
68
 
}