Many resources are needed to download a project. Please understand that we have to compensate our server costs. Thank you in advance. Project price only 1 $
You can buy this project and download/modify it how often you want.
/*
* Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one
* or more contributor license agreements. Licensed under the Elastic License
* 2.0 and the Server Side Public License, v 1; you may not use this file except
* in compliance with, at your election, the Elastic License 2.0 or the Server
* Side Public License, v 1.
*/
package org.apache.lucene.search.grouping;
import org.apache.lucene.index.LeafReaderContext;
import org.apache.lucene.search.FieldComparator;
import org.apache.lucene.search.FieldDoc;
import org.apache.lucene.search.LeafFieldComparator;
import org.apache.lucene.search.ScoreDoc;
import org.apache.lucene.search.ScoreMode;
import org.apache.lucene.search.Sort;
import org.apache.lucene.search.SortField;
import org.apache.lucene.search.TotalHits;
import org.elasticsearch.core.Nullable;
import org.elasticsearch.index.mapper.MappedFieldType;
import java.io.IOException;
import java.util.Collection;
import java.util.Iterator;
import static org.apache.lucene.search.SortField.Type.SCORE;
/**
* A collector that groups documents based on field values and returns {@link CollapseTopFieldDocs}
* output. The collapsing is done in a single pass by selecting only the top sorted document per collapse key.
* The value used for the collapse key of each group can be found in {@link CollapseTopFieldDocs#collapseValues}.
*
* This collector optionally supports searching after a previous result through the 'after' parameter.
*
* TODO: If the sort is based on score we should propagate the mininum competitive score when orderedGroups is full.
* This is safe for collapsing since the group sort is the same as the query sort.
*/
public final class CollapsingTopDocsCollector extends FirstPassGroupingCollector {
protected final String collapseField;
protected final Sort sort;
private int totalHitCount;
private final FieldDoc after;
private final FieldComparator> comparator;
private final int reversed;
private LeafFieldComparator leafComparator;
@SuppressWarnings("unchecked")
CollapsingTopDocsCollector(GroupSelector groupSelector, String collapseField, Sort sort, int topN, FieldDoc after) {
super(groupSelector, sort, topN);
this.collapseField = collapseField;
this.sort = sort;
this.after = after;
assert after == null || (sort.getSort().length == 1 && after.doc == Integer.MAX_VALUE);
SortField sortField = sort.getSort()[0];
this.comparator = sortField.getComparator(0, 0);
if (after != null) {
((FieldComparator