Class TopDocs

    • Field Detail

      • totalHits

        public TotalHits totalHits
        The total number of hits for the query.
      • scoreDocs

        public ScoreDoc[] scoreDocs
        The top hits for the query.
      • SHARD_INDEX_TIE_BREAKER

        private static final java.util.Comparator<ScoreDoc> SHARD_INDEX_TIE_BREAKER
        Internal comparator with shardIndex
      • DOC_ID_TIE_BREAKER

        private static final java.util.Comparator<ScoreDoc> DOC_ID_TIE_BREAKER
        Internal comparator with docID
      • DEFAULT_TIE_BREAKER

        private static final java.util.Comparator<ScoreDoc> DEFAULT_TIE_BREAKER
        Default comparator
    • Constructor Detail

      • TopDocs

        public TopDocs​(TotalHits totalHits,
                       ScoreDoc[] scoreDocs)
        Constructs a TopDocs.
    • Method Detail

      • tieBreakLessThan

        static boolean tieBreakLessThan​(TopDocs.ShardRef first,
                                        ScoreDoc firstDoc,
                                        TopDocs.ShardRef second,
                                        ScoreDoc secondDoc,
                                        java.util.Comparator<ScoreDoc> tieBreaker)
        Use the tie breaker if provided. If tie breaker returns 0 signifying equal values, we use hit indices to tie break intra shard ties
      • merge

        public static TopDocs merge​(int topN,
                                    TopDocs[] shardHits)
        Returns a new TopDocs, containing topN results across the provided TopDocs, sorting by score. Each TopDocs instance must be sorted.
        See Also:
        merge(int, int, TopDocs[])
      • merge

        public static TopDocs merge​(int start,
                                    int topN,
                                    TopDocs[] shardHits)
        Same as merge(int, TopDocs[]) but also ignores the top start top docs. This is typically useful for pagination.

        docIDs are expected to be in consistent pattern i.e. either all ScoreDocs have their shardIndex set, or all have them as -1 (signifying that all hits belong to same searcher)

      • merge

        public static TopDocs merge​(int start,
                                    int topN,
                                    TopDocs[] shardHits,
                                    java.util.Comparator<ScoreDoc> tieBreaker)
        Same as above, but accepts the passed in tie breaker

        docIDs are expected to be in consistent pattern i.e. either all ScoreDocs have their shardIndex set, or all have them as -1 (signifying that all hits belong to same searcher)

      • merge

        public static TopFieldDocs merge​(Sort sort,
                                         int start,
                                         int topN,
                                         TopFieldDocs[] shardHits)
        Same as merge(Sort, int, TopFieldDocs[]) but also ignores the top start top docs. This is typically useful for pagination.

        docIDs are expected to be in consistent pattern i.e. either all ScoreDocs have their shardIndex set, or all have them as -1 (signifying that all hits belong to same searcher)

      • merge

        public static TopFieldDocs merge​(Sort sort,
                                         int start,
                                         int topN,
                                         TopFieldDocs[] shardHits,
                                         java.util.Comparator<ScoreDoc> tieBreaker)
        Pass in a custom tie breaker for ordering results