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

« back to all changes in this revision

Viewing changes to lucene/contrib/facet/src/java/org/apache/lucene/facet/search/aggregator/association/AssociationFloatSumAggregator.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.facet.search.aggregator.association;
2
 
 
3
 
import java.io.IOException;
4
 
 
5
 
import org.apache.lucene.facet.enhancements.association.AssociationsPayloadIterator;
6
 
import org.apache.lucene.facet.index.params.CategoryListParams;
7
 
import org.apache.lucene.facet.search.aggregator.Aggregator;
8
 
import org.apache.lucene.index.IndexReader;
9
 
 
10
 
/**
11
 
 * Licensed to the Apache Software Foundation (ASF) under one or more
12
 
 * contributor license agreements.  See the NOTICE file distributed with
13
 
 * this work for additional information regarding copyright ownership.
14
 
 * The ASF licenses this file to You under the Apache License, Version 2.0
15
 
 * (the "License"); you may not use this file except in compliance with
16
 
 * the License.  You may obtain a copy of the License at
17
 
 *
18
 
 *     http://www.apache.org/licenses/LICENSE-2.0
19
 
 *
20
 
 * Unless required by applicable law or agreed to in writing, software
21
 
 * distributed under the License is distributed on an "AS IS" BASIS,
22
 
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
23
 
 * See the License for the specific language governing permissions and
24
 
 * limitations under the License.
25
 
 */
26
 
 
27
 
/**
28
 
 * An {@link Aggregator} which updates the weight of a category by summing the
29
 
 * weights of the float association it finds for every document.
30
 
 * 
31
 
 * @lucene.experimental
32
 
 */
33
 
public class AssociationFloatSumAggregator implements Aggregator {
34
 
 
35
 
  protected final String field;
36
 
  protected final float[] sumArray;
37
 
  protected final AssociationsPayloadIterator associationsPayloadIterator;
38
 
 
39
 
  public AssociationFloatSumAggregator(IndexReader reader, float[] sumArray) throws IOException {
40
 
    this(CategoryListParams.DEFAULT_TERM.field(), reader, sumArray);
41
 
  }
42
 
  
43
 
  public AssociationFloatSumAggregator(String field, IndexReader reader, float[] sumArray) throws IOException {
44
 
    this.field = field;
45
 
    associationsPayloadIterator = new AssociationsPayloadIterator(reader, field);
46
 
    this.sumArray = sumArray;
47
 
  }
48
 
 
49
 
  public void aggregate(int ordinal) {
50
 
    long association = associationsPayloadIterator.getAssociation(ordinal);
51
 
    if (association != AssociationsPayloadIterator.NO_ASSOCIATION) {
52
 
      sumArray[ordinal] += Float.intBitsToFloat((int) association);
53
 
    }
54
 
  }
55
 
 
56
 
  @Override
57
 
  public boolean equals(Object obj) {
58
 
    if (obj == null || obj.getClass() != this.getClass()) {
59
 
      return false;
60
 
    }
61
 
    AssociationFloatSumAggregator that = (AssociationFloatSumAggregator) obj;
62
 
    return that.field.equals(field) && that.sumArray == sumArray;
63
 
  }
64
 
 
65
 
  @Override
66
 
  public int hashCode() {
67
 
    return field.hashCode();
68
 
  }
69
 
 
70
 
  public void setNextDoc(int docid, float score) throws IOException {
71
 
    associationsPayloadIterator.setNextDoc(docid);
72
 
  }
73
 
  
74
 
}