Class QueryScorer

  • All Implemented Interfaces:
    Scorer

    public class QueryScorer
    extends java.lang.Object
    implements Scorer
    Scorer implementation which scores text fragments by the number of unique query terms found. This class converts appropriate Querys to SpanQuerys and attempts to score only those terms that participated in generating the 'hit' on the document.
    • Constructor Detail

      • QueryScorer

        public QueryScorer​(Query query)
        Parameters:
        query - Query to use for highlighting
      • QueryScorer

        public QueryScorer​(Query query,
                           java.lang.String field)
        Parameters:
        query - Query to use for highlighting
        field - Field to highlight - pass null to ignore fields
      • QueryScorer

        public QueryScorer​(Query query,
                           IndexReader reader,
                           java.lang.String field)
        Parameters:
        query - Query to use for highlighting
        field - Field to highlight - pass null to ignore fields
        reader - IndexReader to use for quasi tf/idf scoring
      • QueryScorer

        public QueryScorer​(Query query,
                           IndexReader reader,
                           java.lang.String field,
                           java.lang.String defaultField)
        Parameters:
        query - to use for highlighting
        reader - IndexReader to use for quasi tf/idf scoring
        field - to highlight - pass null to ignore fields
      • QueryScorer

        public QueryScorer​(Query query,
                           java.lang.String field,
                           java.lang.String defaultField)
        Parameters:
        defaultField - - The default field for queries with the field name unspecified
    • Method Detail

      • getFragmentScore

        public float getFragmentScore()
        Description copied from interface: Scorer
        Called when the Highlighter has no more tokens for the current fragment - the Scorer returns the weighting it has derived for the most recent fragment, typically based on the results of Scorer.getTokenScore().
        Specified by:
        getFragmentScore in interface Scorer
      • getMaxTermWeight

        public float getMaxTermWeight()
        Returns:
        The highest weighted term (useful for passing to GradientFormatter to set top end of coloring scale).
      • getTokenScore

        public float getTokenScore()
        Description copied from interface: Scorer
        Called for each token in the current fragment. The Highlighter will increment the TokenStream passed to init on every call.
        Specified by:
        getTokenScore in interface Scorer
        Returns:
        a score which is passed to the Highlighter class to influence the mark-up of the text (this return value is NOT used to score the fragment)
      • init

        public TokenStream init​(TokenStream tokenStream)
                         throws java.io.IOException
        Description copied from interface: Scorer
        Called to init the Scorer with a TokenStream. You can grab references to the attributes you are interested in here and access them from Scorer.getTokenScore().
        Specified by:
        init in interface Scorer
        Parameters:
        tokenStream - the TokenStream that will be scored.
        Returns:
        either a TokenStream that the Highlighter should continue using (eg if you read the tokenSream in this method) or null to continue using the same TokenStream that was passed in.
        Throws:
        java.io.IOException - If there is a low-level I/O error
      • startFragment

        public void startFragment​(TextFragment newFragment)
        Description copied from interface: Scorer
        Called when a new fragment is started for consideration.
        Specified by:
        startFragment in interface Scorer
        Parameters:
        newFragment - the fragment that will be scored next
      • isExpandMultiTermQuery

        public boolean isExpandMultiTermQuery()
        Returns:
        true if multi-term queries should be expanded
      • setExpandMultiTermQuery

        public void setExpandMultiTermQuery​(boolean expandMultiTermQuery)
        Controls whether or not multi-term queries are expanded against a MemoryIndex IndexReader.
        Parameters:
        expandMultiTermQuery - true if multi-term queries should be expanded
      • setWrapIfNotCachingTokenFilter

        public void setWrapIfNotCachingTokenFilter​(boolean wrap)
        By default, TokenStreams that are not of the type CachingTokenFilter are wrapped in a CachingTokenFilter to ensure an efficient reset - if you are already using a different caching TokenStream impl and you don't want it to be wrapped, set this to false.
      • setMaxDocCharsToAnalyze

        public void setMaxDocCharsToAnalyze​(int maxDocCharsToAnalyze)