Fork me on GitHub
  • API

    Show / Hide Table of Contents

    Class BlockGroupingCollector

    BlockGroupingCollector performs grouping with a single pass collector, as long as you are grouping by a doc block field, ie all documents sharing a given group value were indexed as a doc block using the atomic AddDocuments(IEnumerable<IEnumerable<IIndexableField>>, Analyzer) or UpdateDocuments(Term, IEnumerable<IEnumerable<IIndexableField>>, Analyzer) API.

    This results in faster performance (~25% faster QPS) than the two-pass grouping collectors, with the tradeoff being that the documents in each group must always be indexed as a block. This collector also fills in TopGroups.totalGroupCount without requiring the separate TermAllGroupsCollector. However, this collector does not fill in the groupValue of each group; this field will always be null.

    NOTE: this collector makes no effort to verify the docs were in fact indexed as a block, so it's up to you to ensure this was the case.

    See org.apache.lucene.search.grouping for more details including a full code example.

    Note

    This API is experimental and might change in incompatible ways in the next release.

    Inheritance
    object
    BlockGroupingCollector
    Implements
    ICollector
    Inherited Members
    object.Equals(object)
    object.Equals(object, object)
    object.GetHashCode()
    object.GetType()
    object.MemberwiseClone()
    object.ReferenceEquals(object, object)
    object.ToString()
    Namespace: Lucene.Net.Search.Grouping
    Assembly: Lucene.Net.Grouping.dll
    Syntax
    public class BlockGroupingCollector : ICollector

    Constructors

    BlockGroupingCollector(Sort, int, bool, Filter)

    Create the single pass collector.

    Declaration
    public BlockGroupingCollector(Sort groupSort, int topNGroups, bool needsScores, Filter lastDocPerGroup)
    Parameters
    Type Name Description
    Sort groupSort

    The Lucene.Net.Search.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 Lucene.Net.Search.Sort.RELEVANCE.

    int topNGroups

    How many top groups to keep.

    bool 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 GetTopGroups(Sort, int, int, int, bool)

    Filter lastDocPerGroup

    a Lucene.Net.Search.Filter that marks the last document in each group.

    Properties

    AcceptsDocsOutOfOrder

    Return true if this collector does not require the matching docIDs to be delivered in int sort order (smallest to largest) to Collect(int).

    Most Lucene Query implementations will visit matching docIDs in order. However, some queries (currently limited to certain cases of Lucene.Net.Search.BooleanQuery) can achieve faster searching if the Lucene.Net.Search.ICollector allows them to deliver the docIDs out of order.

    Many collectors don't mind getting docIDs out of order, so it's important to return true here.

    Declaration
    public virtual bool AcceptsDocsOutOfOrder { get; }
    Property Value
    Type Description
    bool

    Methods

    Collect(int)

    Called once for every document matching a query, with the unbased document number.

    Note: The collection of the current segment can be terminated by throwing a Lucene.Net.Search.CollectionTerminatedException. In this case, the last docs of the current Lucene.Net.Index.AtomicReaderContext will be skipped and Lucene.Net.Search.IndexSearcher will swallow the exception and continue collection with the next leaf.

    Note: this is called in an inner search loop. For good search performance, implementations of this method should not call Doc(int) or Document(int) on every hit. Doing so can slow searches by an order of magnitude or more.
    Declaration
    public virtual void Collect(int doc)
    Parameters
    Type Name Description
    int doc

    GetTopGroups(Sort, int, int, int, bool)

    Returns the grouped results. Returns null if the number of groups collected is <= groupOffset.

    NOTE: This collector is unable to compute the groupValue per group so it will always be null. This is normally not a problem, as you can obtain the value just like you obtain other values for each matching document (eg, via stored fields, via FieldCache, etc.)

    Declaration
    public virtual ITopGroups<object> GetTopGroups(Sort withinGroupSort, int groupOffset, int withinGroupOffset, int maxDocsPerGroup, bool fillSortFields)
    Parameters
    Type Name Description
    Sort withinGroupSort

    The Lucene.Net.Search.Sort used to sort documents within each group. Passing null is allowed, to sort by relevance.

    int groupOffset

    Which group to start from

    int withinGroupOffset

    Which document to start from within each group

    int maxDocsPerGroup

    How many top documents to keep within each group.

    bool fillSortFields

    If true then the Comparable values for the sort fields will be set

    Returns
    Type Description
    ITopGroups<object>

    GetTopGroups<TGroupValue>(Sort, int, int, int, bool)

    Returns the grouped results. Returns null if the number of groups collected is <= groupOffset.

    NOTE: This collector is unable to compute the groupValue per group so it will always be null. This is normally not a problem, as you can obtain the value just like you obtain other values for each matching document (eg, via stored fields, via FieldCache, etc.)

    Declaration
    public virtual ITopGroups<TGroupValue> GetTopGroups<TGroupValue>(Sort withinGroupSort, int groupOffset, int withinGroupOffset, int maxDocsPerGroup, bool fillSortFields)
    Parameters
    Type Name Description
    Sort withinGroupSort

    The Lucene.Net.Search.Sort used to sort documents within each group. Passing null is allowed, to sort by relevance.

    int groupOffset

    Which group to start from

    int withinGroupOffset

    Which document to start from within each group

    int maxDocsPerGroup

    How many top documents to keep within each group.

    bool fillSortFields

    If true then the Comparable values for the sort fields will be set

    Returns
    Type Description
    ITopGroups<TGroupValue>
    Type Parameters
    Name Description
    TGroupValue

    The expected return type for group value

    SetNextReader(AtomicReaderContext)

    Called before collecting from each Lucene.Net.Index.AtomicReaderContext. All doc ids in Collect(int) will correspond to Lucene.Net.Index.IndexReaderContext.Reader.

    Add Lucene.Net.Index.AtomicReaderContext.DocBase to the current Lucene.Net.Index.IndexReaderContext.Reader's internal document id to re-base ids in Collect(int).
    Declaration
    public virtual void SetNextReader(AtomicReaderContext context)
    Parameters
    Type Name Description
    AtomicReaderContext context

    next atomic reader context

    SetScorer(Scorer)

    Called before successive calls to Collect(int). Implementations that need the score of the current document (passed-in to Collect(int)), should save the passed-in Lucene.Net.Search.Scorer and call scorer.GetScore() when needed.

    Declaration
    public virtual void SetScorer(Scorer scorer)
    Parameters
    Type Name Description
    Scorer scorer

    Implements

    Lucene.Net.Search.ICollector
    Back to top Copyright © 2024 The Apache Software Foundation, Licensed under the Apache License, Version 2.0
    Apache Lucene.Net, Lucene.Net, Apache, the Apache feather logo, and the Apache Lucene.Net project logo are trademarks of The Apache Software Foundation.
    All other marks mentioned may be trademarks or registered trademarks of their respective owners.