Class QueryTermExtractor


  • public final class QueryTermExtractor
    extends java.lang.Object
    Utility class used to extract the terms used in a query, plus any weights. This class will not find terms for MultiTermQuery, TermRangeQuery and PrefixQuery classes so the caller must pass a rewritten query (see Query.rewrite) to obtain a list of expanded terms.
    • Method Summary

      All Methods Static Methods Concrete Methods 
      Modifier and Type Method Description
      static WeightedTerm[] getIdfWeightedTerms​(Query query, IndexReader reader, java.lang.String fieldName)
      Extracts all terms texts of a given Query into an array of WeightedTerms
      static WeightedTerm[] getTerms​(Query query)
      Extracts all terms texts of a given Query into an array of WeightedTerms
      static WeightedTerm[] getTerms​(Query query, boolean prohibited)
      Extracts all terms texts of a given Query into an array of WeightedTerms
      static WeightedTerm[] getTerms​(Query query, boolean prohibited, java.lang.String fieldName)
      Extracts all terms texts of a given Query into an array of WeightedTerms
      • Methods inherited from class java.lang.Object

        equals, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
    • Constructor Detail

      • QueryTermExtractor

        public QueryTermExtractor()
    • Method Detail

      • getTerms

        public static final WeightedTerm[] getTerms​(Query query)
        Extracts all terms texts of a given Query into an array of WeightedTerms
        Parameters:
        query - Query to extract term texts from
        Returns:
        an array of the terms used in a query, plus their weights.
      • getIdfWeightedTerms

        public static final WeightedTerm[] getIdfWeightedTerms​(Query query,
                                                               IndexReader reader,
                                                               java.lang.String fieldName)
        Extracts all terms texts of a given Query into an array of WeightedTerms
        Parameters:
        query - Query to extract term texts from
        reader - used to compute IDF which can be used to a) score selected fragments better b) use graded highlights eg changing intensity of font color
        fieldName - the field on which Inverse Document Frequency (IDF) calculations are based
        Returns:
        an array of the terms used in a query, plus their weights.
      • getTerms

        public static final WeightedTerm[] getTerms​(Query query,
                                                    boolean prohibited,
                                                    java.lang.String fieldName)
        Extracts all terms texts of a given Query into an array of WeightedTerms
        Parameters:
        query - Query to extract term texts from
        prohibited - true to extract "prohibited" terms, too
        fieldName - The fieldName used to filter query terms
        Returns:
        an array of the terms used in a query, plus their weights.
      • getTerms

        public static final WeightedTerm[] getTerms​(Query query,
                                                    boolean prohibited)
        Extracts all terms texts of a given Query into an array of WeightedTerms
        Parameters:
        query - Query to extract term texts from
        prohibited - true to extract "prohibited" terms, too
        Returns:
        an array of the terms used in a query, plus their weights.