Class Passage


  • public class Passage
    extends Object
    Represents a passage (typically a sentence of the document).

    A passage contains getNumMatches() highlights from the query, and the offsets and query terms that correspond with each match.

    WARNING: This API is experimental and might change in incompatible ways in the next release.
    • Constructor Detail

      • Passage

        public Passage()
    • Method Detail

      • addMatch

        public void addMatch​(int startOffset,
                             int endOffset,
                             BytesRef term,
                             int termFreqInDoc)
        NOTE: This API is for internal purposes only and might change in incompatible ways in the next release.
      • reset

        public void reset()
        NOTE: This API is for internal purposes only and might change in incompatible ways in the next release.
      • toString

        public String toString()
        For debugging. ex: Passage[0-22]{yin[0-3],yang[4-8],yin[10-13]}score=2.4964213
        Overrides:
        toString in class Object
      • getStartOffset

        public int getStartOffset()
        Start offset of this passage.
        Returns:
        start index (inclusive) of the passage in the original content: always >= 0.
      • getEndOffset

        public int getEndOffset()
        End offset of this passage.
        Returns:
        end index (exclusive) of the passage in the original content: always >= getStartOffset()
      • getLength

        public int getLength()
      • getScore

        public float getScore()
        Passage's score.
      • setScore

        public void setScore​(float score)
      • getMatchStarts

        public int[] getMatchStarts()
        Start offsets of the term matches, in increasing order.

        Only getNumMatches() are valid. Note that these offsets are absolute (not relative to getStartOffset()).

      • getMatchEnds

        public int[] getMatchEnds()
        End offsets of the term matches, corresponding with getMatchStarts().

        Only getNumMatches() are valid. Note that its possible that an end offset could exceed beyond the bounds of the passage (getEndOffset()), if the Analyzer produced a term which spans a passage boundary.

      • getMatchTerms

        public BytesRef[] getMatchTerms()
        BytesRef (term text) of the matches, corresponding with getMatchStarts(). The primary purpose of this method is to expose the number of unique terms per passage for use in passage scoring. The actual term byte content is not well defined by this highlighter, and thus use of it is more subject to change.

        The term might be simply the analyzed term at this position. Depending on the highlighter's configuration, the match term may be a phrase (instead of a word), and in such a case might be a series of space-separated analyzed terms. If the match is from a MultiTermQuery then the match term may be the toString() of that query.

        Only getNumMatches() are valid.

      • getMatchTermFreqsInDoc

        public int[] getMatchTermFreqsInDoc()
      • setStartOffset

        public void setStartOffset​(int startOffset)
        NOTE: This API is for internal purposes only and might change in incompatible ways in the next release.
      • setEndOffset

        public void setEndOffset​(int endOffset)
        NOTE: This API is for internal purposes only and might change in incompatible ways in the next release.