com.jalios.jcms.search
Class SpellSuggestQueryParser

java.lang.Object
  extended by org.apache.lucene.queryParser.QueryParser
      extended by com.jalios.jcms.search.SpellSuggestQueryParser
All Implemented Interfaces:
org.apache.lucene.queryParser.QueryParserConstants

public class SpellSuggestQueryParser
extends org.apache.lucene.queryParser.QueryParser

This QueryParser parse a search string and build a new lucene query using suggested words instead of Warning: it can be quite time consuming as it trigger a search in the spell checker for each term of the query.

Since:
jcms-5.5.0
Version:
$Revision: 27753 $
Author:
Olivier Jaquemet

Nested Class Summary
 
Nested classes/interfaces inherited from class org.apache.lucene.queryParser.QueryParser
org.apache.lucene.queryParser.QueryParser.Operator
 
Field Summary
static String REVISION
           
 
Fields inherited from class org.apache.lucene.queryParser.QueryParser
AND_OPERATOR, jj_nt, OR_OPERATOR, token, token_source
 
Fields inherited from interface org.apache.lucene.queryParser.QueryParserConstants
_ESCAPED_CHAR, _NUM_CHAR, _QUOTED_CHAR, _TERM_CHAR, _TERM_START_CHAR, _WHITESPACE, AND, Boost, CARAT, COLON, DEFAULT, EOF, FUZZY_SLOP, LPAREN, MINUS, NOT, NUMBER, OR, PLUS, PREFIXTERM, QUOTED, RangeEx, RANGEEX_END, RANGEEX_GOOP, RANGEEX_QUOTED, RANGEEX_START, RANGEEX_TO, RangeIn, RANGEIN_END, RANGEIN_GOOP, RANGEIN_QUOTED, RANGEIN_START, RANGEIN_TO, RPAREN, STAR, TERM, tokenImage, WILDTERM
 
Constructor Summary
SpellSuggestQueryParser(String field, org.apache.lucene.analysis.Analyzer analyzer, SpellChecker spellChecker, org.apache.lucene.index.IndexReader reader, QueryHandler qh)
          Construct a new SpellSuggestQueryParser using the given params.
 
Method Summary
protected  org.apache.lucene.search.Query getFieldQuery(String field, String queryText)
           
 boolean hasSuggestedQuery()
          Check if the suggestions were used during last parse.
 org.apache.lucene.search.Query parse(String query)
           
 
Methods inherited from class org.apache.lucene.queryParser.QueryParser
addClause, addClause, Clause, Conjunction, disable_tracing, enable_tracing, escape, generateParseException, getAllowLeadingWildcard, getAnalyzer, getBooleanQuery, getBooleanQuery, getBooleanQuery, getBooleanQuery, getDateResolution, getDefaultOperator, getEnablePositionIncrements, getField, getFieldQuery, getFuzzyMinSim, getFuzzyPrefixLength, getFuzzyQuery, getLocale, getLowercaseExpandedTerms, getMultiTermRewriteMethod, getNextToken, getPhraseSlop, getPrefixQuery, getRangeCollator, getRangeQuery, getToken, getUseOldRangeQuery, getWildcardQuery, main, Modifiers, newBooleanClause, newBooleanQuery, newFuzzyQuery, newMatchAllDocsQuery, newMultiPhraseQuery, newPhraseQuery, newPrefixQuery, newRangeQuery, newTermQuery, newWildcardQuery, Query, ReInit, ReInit, setAllowLeadingWildcard, setDateResolution, setDateResolution, setDefaultOperator, setEnablePositionIncrements, setFuzzyMinSim, setFuzzyPrefixLength, setLocale, setLowercaseExpandedTerms, setMultiTermRewriteMethod, setPhraseSlop, setRangeCollator, setUseOldRangeQuery, Term, TopLevelQuery
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

REVISION

public static final String REVISION
See Also:
Constant Field Values
Constructor Detail

SpellSuggestQueryParser

public SpellSuggestQueryParser(String field,
                               org.apache.lucene.analysis.Analyzer analyzer,
                               SpellChecker spellChecker,
                               org.apache.lucene.index.IndexReader reader,
                               QueryHandler qh)
Construct a new SpellSuggestQueryParser using the given params.

Parameters:
field - default field to use (see QueryParser.QueryParser(java.lang.String, org.apache.lucene.analysis.Analyzer)) used also by the spell checker method SpellChecker.suggestSimilar(String, int, IndexReader, String, boolean).
analyzer - analyzer to use (see QueryParser.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, boolean), allows suggestion to be made only if the suggested term is more frequent in the index than the searched term.
qh - the QueryHandler that was used for this query.
Method Detail

getFieldQuery

protected org.apache.lucene.search.Query getFieldQuery(String field,
                                                       String queryText)
                                                throws org.apache.lucene.queryParser.ParseException
Overrides:
getFieldQuery in class org.apache.lucene.queryParser.QueryParser
Throws:
org.apache.lucene.queryParser.ParseException

parse

public org.apache.lucene.search.Query parse(String query)
                                     throws org.apache.lucene.queryParser.ParseException
Overrides:
parse in class org.apache.lucene.queryParser.QueryParser
Throws:
org.apache.lucene.queryParser.ParseException

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.


Copyright © 2001-2010 Jalios SA. All Rights Reserved.