Class SpellSuggestQueryParser

java.lang.Object
org.apache.lucene.util.QueryBuilder
org.apache.lucene.queryparser.classic.QueryParserBase
org.apache.lucene.queryparser.classic.QueryParser
com.jalios.jcms.search.SpellSuggestQueryParser
All Implemented Interfaces:
org.apache.lucene.queryparser.classic.QueryParserConstants, org.apache.lucene.queryparser.flexible.standard.CommonQueryParserConfiguration

public class SpellSuggestQueryParser extends org.apache.lucene.queryparser.classic.QueryParser
This QueryParser parse a search string and build a new lucene query using suggested words.

Warning: it can be quite time consuming as it trigger a search in the spell checker for each term of the query.

Some advanced settings can be defined in properties :

  • spellsuggest.spell-checker.suggestions-number : The number of suggested words.
    As the Lucene similarity that is used to fetch the most relevant n-grammed terms is not the same as the edit distance strategy used to calculate the best matching spell-checked word from the hits that Lucene found, one usually has to retrieve a couple of numSug's in order to get the true best match.
    I.e. if numSug == 1, don't count on that suggestion being the best one. Thus, you should set this value to at least 5 for a good suggestion.
    Default is 10.
  • spellsuggest.spell-checker.field : the field of the user index: if field is not null, the suggested words are restricted to the words present in this field.
    Default is null.
  • spellsuggest.spell-checker.suggest-mode : The SuggestMode - (NOTE: if field==null, then this is overridden with SuggestMode.SUGGEST_ALWAYS).
    Default is SuggestMode.SUGGEST_MORE_POPULAR
  • spellsuggest.spell-checker.accuracy : The minimum score a suggestion must have in order to qualify for inclusion in the results.
    Default is 0.5f
Since:
jcms-5.5.0
  • Nested Class Summary

    Nested classes/interfaces inherited from class org.apache.lucene.queryparser.classic.QueryParser

    org.apache.lucene.queryparser.classic.QueryParser.Operator

    Nested classes/interfaces inherited from class org.apache.lucene.util.QueryBuilder

    org.apache.lucene.util.QueryBuilder.TermAndBoost
  • Field Summary

    Fields inherited from class org.apache.lucene.queryparser.classic.QueryParser

    DEFAULT_SPLIT_ON_WHITESPACE, jj_nt, token, token_source

    Fields inherited from class org.apache.lucene.queryparser.classic.QueryParserBase

    AND_OPERATOR, field, OR_OPERATOR

    Fields inherited from class org.apache.lucene.util.QueryBuilder

    analyzer, autoGenerateMultiTermSynonymsPhraseQuery, enableGraphQueries, enablePositionIncrements

    Fields inherited from interface org.apache.lucene.queryparser.classic.QueryParserConstants

    _ESCAPED_CHAR, _NUM_CHAR, _QUOTED_CHAR, _TERM_CHAR, _TERM_START_CHAR, _WHITESPACE, AND, BAREOPER, Boost, CARAT, COLON, DEFAULT, EOF, FUZZY_SLOP, LPAREN, MINUS, NOT, NUMBER, OR, PLUS, PREFIXTERM, QUOTED, Range, RANGE_GOOP, RANGE_QUOTED, RANGE_TO, RANGEEX_END, RANGEEX_START, RANGEIN_END, RANGEIN_START, REGEXPTERM, RPAREN, STAR, TERM, tokenImage, WILDTERM
  • Constructor Summary

    Constructors
    Constructor
    Description
    SpellSuggestQueryParser(String field, org.apache.lucene.analysis.Analyzer analyzer, org.apache.lucene.search.spell.SpellChecker spellChecker, org.apache.lucene.index.IndexReader reader)
    Construct a new SpellSuggestQueryParser using the given params.
  • Method Summary

    Modifier and Type
    Method
    Description
    boolean
    Check if the suggestions were used during last parse.
    protected org.apache.lucene.search.Query
    newTermQuery(org.apache.lucene.index.Term term, float boost)
     

    Methods inherited from class org.apache.lucene.queryparser.classic.QueryParser

    Clause, Conjunction, disable_tracing, enable_tracing, generateParseException, getNextToken, getSplitOnWhitespace, getToken, Modifiers, MultiTerm, Query, ReInit, ReInit, setAutoGeneratePhraseQueries, setSplitOnWhitespace, Term, TopLevelQuery, trace_enabled

    Methods inherited from class org.apache.lucene.queryparser.classic.QueryParserBase

    addClause, addMultiTermClauses, escape, getAllowLeadingWildcard, getAutoGeneratePhraseQueries, getBooleanQuery, getDateResolution, getDefaultOperator, getDeterminizeWorkLimit, getField, getFieldQuery, getFieldQuery, getFuzzyDistance, getFuzzyMinSim, getFuzzyPrefixLength, getFuzzyQuery, getLocale, getMultiTermRewriteMethod, getPhraseSlop, getPrefixQuery, getRangeQuery, getRegexpQuery, getTimeZone, getWildcardQuery, init, newBooleanClause, newFieldQuery, newFuzzyQuery, newMatchAllDocsQuery, newPrefixQuery, newRangeQuery, newRegexpQuery, newWildcardQuery, parse, setAllowLeadingWildcard, setDateResolution, setDateResolution, setDefaultOperator, setDeterminizeWorkLimit, setFuzzyMinSim, setFuzzyPrefixLength, setLocale, setMultiTermRewriteMethod, setPhraseSlop, setTimeZone

    Methods inherited from class org.apache.lucene.util.QueryBuilder

    add, analyzeBoolean, analyzeGraphBoolean, analyzeGraphPhrase, analyzeMultiBoolean, analyzeMultiPhrase, analyzePhrase, analyzeTerm, createBooleanQuery, createBooleanQuery, createFieldQuery, createFieldQuery, createMinShouldMatchQuery, createPhraseQuery, createPhraseQuery, getAnalyzer, getAutoGenerateMultiTermSynonymsPhraseQuery, getEnableGraphQueries, getEnablePositionIncrements, newBooleanQuery, newGraphSynonymQuery, newMultiPhraseQueryBuilder, newSynonymQuery, setAnalyzer, setAutoGenerateMultiTermSynonymsPhraseQuery, setEnableGraphQueries, setEnablePositionIncrements

    Methods inherited from class java.lang.Object

    clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait

    Methods inherited from interface org.apache.lucene.queryparser.flexible.standard.CommonQueryParserConfiguration

    getAnalyzer, getEnablePositionIncrements, setEnablePositionIncrements
  • Constructor Details

    • SpellSuggestQueryParser

      public SpellSuggestQueryParser(String field, org.apache.lucene.analysis.Analyzer analyzer, org.apache.lucene.search.spell.SpellChecker spellChecker, org.apache.lucene.index.IndexReader reader)
      Construct a new SpellSuggestQueryParser using the given params.
      Parameters:
      field - default field to use (see QueryParser(java.lang.String, org.apache.lucene.analysis.Analyzer))
      analyzer - analyzer to use (see QueryParser(java.lang.String, org.apache.lucene.analysis.Analyzer))
      spellChecker - the spellChecker instance to find suggestion, MUST NOT BE NULL.
      reader - the IndexReader to use when calling the spell checker method SpellChecker.suggestSimilar(String, int, IndexReader, String, SuggestMode), allows suggestion to be made only if the suggested term is more frequent in the index than the searched term.
  • Method Details

    • newTermQuery

      protected org.apache.lucene.search.Query newTermQuery(org.apache.lucene.index.Term term, float boost)
      Overrides:
      newTermQuery in class org.apache.lucene.util.QueryBuilder
    • hasSuggestedQuery

      public boolean hasSuggestedQuery()
      Check if the suggestions were used during last parse.
      Returns:
      true if the suggestions were used during the last call to parse method.