Package com.jalios.jcms.search
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
: TheSuggestMode
- (NOTE: if field==null, then this is overridden with SuggestMode.SUGGEST_ALWAYS).
Default isSuggestMode.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
-
-
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(java.lang.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
All Methods Instance Methods Concrete Methods Modifier and Type Method Description boolean
hasSuggestedQuery()
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
-
Methods inherited from class org.apache.lucene.queryparser.classic.QueryParserBase
addClause, addMultiTermClauses, escape, getAllowLeadingWildcard, getAutoGeneratePhraseQueries, getBooleanQuery, getDateResolution, getDefaultOperator, getDeterminizeWorkLimit, getField, getFieldQuery, getFieldQuery, 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, createSpanQuery, getAnalyzer, getAutoGenerateMultiTermSynonymsPhraseQuery, getEnableGraphQueries, getEnablePositionIncrements, newBooleanQuery, newGraphSynonymQuery, newMultiPhraseQueryBuilder, newSynonymQuery, setAnalyzer, setAutoGenerateMultiTermSynonymsPhraseQuery, setEnableGraphQueries, setEnablePositionIncrements
-
-
-
-
Constructor Detail
-
SpellSuggestQueryParser
public SpellSuggestQueryParser(java.lang.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 (seeQueryParser(java.lang.String, org.apache.lucene.analysis.Analyzer)
)analyzer
- analyzer to use (seeQueryParser(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 methodSpellChecker.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 Detail
-
newTermQuery
protected org.apache.lucene.search.Query newTermQuery(org.apache.lucene.index.Term term, float boost)
- Overrides:
newTermQuery
in classorg.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.
-
-