1 package org.apache.lucene.facet.search.aggregator.association;
3 import java.io.IOException;
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;
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
18 * http://www.apache.org/licenses/LICENSE-2.0
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.
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.
31 * @lucene.experimental
33 public class AssociationFloatSumAggregator implements Aggregator {
35 protected final String field;
36 protected final float[] sumArray;
37 protected final AssociationsPayloadIterator associationsPayloadIterator;
39 public AssociationFloatSumAggregator(IndexReader reader, float[] sumArray) throws IOException {
40 this(CategoryListParams.DEFAULT_TERM.field(), reader, sumArray);
43 public AssociationFloatSumAggregator(String field, IndexReader reader, float[] sumArray) throws IOException {
45 associationsPayloadIterator = new AssociationsPayloadIterator(reader, field);
46 this.sumArray = sumArray;
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);
57 public boolean equals(Object obj) {
58 if (obj == null || obj.getClass() != this.getClass()) {
61 AssociationFloatSumAggregator that = (AssociationFloatSumAggregator) obj;
62 return that.field.equals(field) && that.sumArray == sumArray;
66 public int hashCode() {
67 return field.hashCode();
70 public void setNextDoc(int docid, float score) throws IOException {
71 associationsPayloadIterator.setNextDoc(docid);