/// <summary> /// Create the first pass collector. /// </summary> /// <param name="groupSort"> /// The <see cref="Sort"/> used to sort the /// groups. The top sorted document within each group /// according to groupSort, determines how that group /// sorts against other groups. This must be non-null, /// ie, if you want to groupSort by relevance use /// Sort.RELEVANCE. /// </param> /// <param name="topNGroups">How many top groups to keep.</param> /// <exception cref="IOException">If I/O related errors occur</exception> public AbstractFirstPassGroupingCollector(Sort groupSort, int topNGroups) { if (topNGroups < 1) { throw new ArgumentException("topNGroups must be >= 1 (got " + topNGroups + ")"); } // TODO: allow null groupSort to mean "by relevance", // and specialize it? this.groupSort = groupSort; this.topNGroups = topNGroups; SortField[] sortFields = groupSort.GetSort(); comparators = new FieldComparator[sortFields.Length]; compIDXEnd = comparators.Length - 1; reversed = new int[sortFields.Length]; for (int i = 0; i < sortFields.Length; i++) { SortField sortField = sortFields[i]; // use topNGroups + 1 so we have a spare slot to use for comparing (tracked by this.spareSlot): comparators[i] = sortField.GetComparator(topNGroups + 1, i); reversed[i] = sortField.Reverse ? -1 : 1; } spareSlot = topNGroups; groupMap = new HashMap <TGroupValue, CollectedSearchGroup <TGroupValue> >(topNGroups); }
/// <summary> /// Create the single pass collector. /// </summary> /// <param name="groupSort"> /// The <see cref="Sort"/> used to sort the /// groups. The top sorted document within each group /// according to groupSort, determines how that group /// sorts against other groups. This must be non-null, /// ie, if you want to groupSort by relevance use /// <see cref="Sort.RELEVANCE"/>. /// </param> /// <param name="topNGroups">How many top groups to keep.</param> /// <param name="needsScores"> /// true if the collected documents /// require scores, either because relevance is included /// in the withinGroupSort or because you plan to pass true /// for either GetScores or GetMaxScores to <see cref="GetTopGroups(Sort, int, int, int, bool)"/> /// </param> /// <param name="lastDocPerGroup"> /// a <see cref="Filter"/> that marks the /// last document in each group. /// </param> public BlockGroupingCollector(Sort groupSort, int topNGroups, bool needsScores, Filter lastDocPerGroup) { if (topNGroups < 1) { throw new ArgumentException("topNGroups must be >= 1 (got " + topNGroups + ")"); } groupQueue = new GroupQueue(this, topNGroups); pendingSubDocs = new int[10]; if (needsScores) { pendingSubScores = new float[10]; } this.needsScores = needsScores; this.lastDocPerGroup = lastDocPerGroup; // TODO: allow null groupSort to mean "by relevance", // and specialize it? this.groupSort = groupSort; this.topNGroups = topNGroups; SortField[] sortFields = groupSort.GetSort(); comparators = new FieldComparator[sortFields.Length]; compIDXEnd = comparators.Length - 1; reversed = new int[sortFields.Length]; for (int i = 0; i < sortFields.Length; i++) { SortField sortField = sortFields[i]; comparators[i] = sortField.GetComparator(topNGroups, i); reversed[i] = sortField.Reverse ? -1 : 1; } }
public GroupComparator(Sort groupSort) { SortField[] sortFields = groupSort.GetSort(); comparators = new FieldComparator[sortFields.Length]; reversed = new int[sortFields.Length]; for (int compIDX = 0; compIDX < sortFields.Length; compIDX++) { SortField sortField = sortFields[compIDX]; comparators[compIDX] = sortField.GetComparator(1, compIDX); reversed[compIDX] = sortField.Reverse ? -1 : 1; } }