Class WeightedHighlighter


  • public class WeightedHighlighter
    extends DefaultHighlighter
    WeightedHighlighter implements a highlighter that weights the fragments based on the proximity of the highlighted terms to each other. The returned fragments are not necessarily in sequence as the text occurs in the content.
    • Constructor Detail

      • WeightedHighlighter

        protected WeightedHighlighter()
    • Method Detail

      • highlight

        public static String highlight​(org.apache.lucene.index.TermPositionVector tvec,
                                       Set<org.apache.lucene.index.Term[]> queryTerms,
                                       String text,
                                       String excerptStart,
                                       String excerptEnd,
                                       String fragmentStart,
                                       String fragmentEnd,
                                       String hlStart,
                                       String hlEnd,
                                       int maxFragments,
                                       int surround)
                                throws IOException
        Parameters:
        tvec - the term position vector for this hit
        queryTerms - the query terms.
        text - the original text that was used to create the tokens.
        excerptStart - this string is prepended to the excerpt
        excerptEnd - this string is appended to the excerpt
        fragmentStart - this string is prepended to every fragment
        fragmentEnd - this string is appended to the end of every fragment.
        hlStart - the string used to prepend a highlighted token, for example &quot;&lt;b&gt;&quot;
        hlEnd - the string used to append a highlighted token, for example &quot;&lt;/b&gt;&quot;
        maxFragments - the maximum number of fragments
        surround - the maximum number of chars surrounding a highlighted token
        Returns:
        a String with text fragments where tokens from the query are highlighted
        Throws:
        IOException
      • highlight

        public static String highlight​(org.apache.lucene.index.TermPositionVector tvec,
                                       Set<org.apache.lucene.index.Term[]> queryTerms,
                                       String text,
                                       int maxFragments,
                                       int surround)
                                throws IOException
        Parameters:
        tvec - the term position vector for this hit
        queryTerms - the query terms.
        text - the original text that was used to create the tokens.
        maxFragments - the maximum number of fragments
        surround - the maximum number of chars surrounding a highlighted token
        Returns:
        a String with text fragments where tokens from the query are highlighted
        Throws:
        IOException