Class AnalyzingQueryParser
- java.lang.Object
-
- org.apache.lucene.queryParser.QueryParser
-
- org.apache.lucene.queryParser.analyzing.AnalyzingQueryParser
-
- All Implemented Interfaces:
org.apache.lucene.queryParser.QueryParserConstants
public class AnalyzingQueryParser extends org.apache.lucene.queryParser.QueryParser
Overrides Lucene's default QueryParser so that Fuzzy-, Prefix-, Range-, and WildcardQuerys are also passed through the given analyzer, but wild card characters (like*
) don't get removed from the search terms.Warning: This class should only be used with analyzers that do not use stopwords or that add tokens. Also, several stemming analyzers are inappropriate: for example, GermanAnalyzer will turn
Häuser
intohau
, butH?user
will becomeh?user
when using this parser and thus no match would be found (i.e. using this parser will be no improvement over QueryParser in such cases).- Version:
- $Revision$, $Date$
-
-
Field Summary
-
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, BAREOPER, 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
Constructors Constructor Description AnalyzingQueryParser(org.apache.lucene.util.Version matchVersion, String field, org.apache.lucene.analysis.Analyzer analyzer)
Constructs a query parser.
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description protected org.apache.lucene.search.Query
getFuzzyQuery(String field, String termStr, float minSimilarity)
Called when parser parses an input term token that has the fuzzy suffix (~) appended.protected org.apache.lucene.search.Query
getPrefixQuery(String field, String termStr)
Called when parser parses an input term token that uses prefix notation; that is, contains a single '*' wildcard character as its last character.protected org.apache.lucene.search.Query
getRangeQuery(String field, String part1, String part2, boolean inclusive)
Overrides super class, by passing terms through analyzer.protected org.apache.lucene.search.Query
getWildcardQuery(String field, String termStr)
Called when parser parses an input term token that contains one or more wildcard characters (like*
), but is not a prefix term token (one that has just a single * character at the end).-
Methods inherited from class org.apache.lucene.queryParser.QueryParser
addClause, Clause, Conjunction, disable_tracing, enable_tracing, escape, generateParseException, getAllowLeadingWildcard, getAnalyzer, getAutoGeneratePhraseQueries, getBooleanQuery, getBooleanQuery, getDateResolution, getDefaultOperator, getEnablePositionIncrements, getField, getFieldQuery, getFieldQuery, getFieldQuery, getFuzzyMinSim, getFuzzyPrefixLength, getLocale, getLowercaseExpandedTerms, getMultiTermRewriteMethod, getNextToken, getPhraseSlop, getRangeCollator, getToken, main, Modifiers, newBooleanClause, newBooleanQuery, newFuzzyQuery, newMatchAllDocsQuery, newMultiPhraseQuery, newPhraseQuery, newPrefixQuery, newRangeQuery, newTermQuery, newWildcardQuery, parse, Query, ReInit, ReInit, setAllowLeadingWildcard, setAutoGeneratePhraseQueries, setDateResolution, setDateResolution, setDefaultOperator, setEnablePositionIncrements, setFuzzyMinSim, setFuzzyPrefixLength, setLocale, setLowercaseExpandedTerms, setMultiTermRewriteMethod, setPhraseSlop, setRangeCollator, Term, TopLevelQuery
-
-
-
-
Constructor Detail
-
AnalyzingQueryParser
public AnalyzingQueryParser(org.apache.lucene.util.Version matchVersion, String field, org.apache.lucene.analysis.Analyzer analyzer)
Constructs a query parser.- Parameters:
field
- the default field for query terms.analyzer
- used to find terms in the query text.
-
-
Method Detail
-
getWildcardQuery
protected org.apache.lucene.search.Query getWildcardQuery(String field, String termStr) throws org.apache.lucene.queryParser.ParseException
Called when parser parses an input term token that contains one or more wildcard characters (like*
), but is not a prefix term token (one that has just a single * character at the end).Example: will be called for
H?user
or forH*user
but not for*user
.Depending on analyzer and settings, a wildcard term may (most probably will) be lower-cased automatically. It will go through the default Analyzer.
Overrides super class, by passing terms through analyzer.
- Overrides:
getWildcardQuery
in classorg.apache.lucene.queryParser.QueryParser
- Parameters:
field
- Name of the field query will use.termStr
- Term token that contains one or more wild card characters (? or *), but is not simple prefix term- Returns:
- Resulting
Query
built for the term - Throws:
org.apache.lucene.queryParser.ParseException
-
getPrefixQuery
protected org.apache.lucene.search.Query getPrefixQuery(String field, String termStr) throws org.apache.lucene.queryParser.ParseException
Called when parser parses an input term token that uses prefix notation; that is, contains a single '*' wildcard character as its last character. Since this is a special case of generic wildcard term, and such a query can be optimized easily, this usually results in a different query object.Depending on analyzer and settings, a prefix term may (most probably will) be lower-cased automatically. It will go through the default Analyzer.
Overrides super class, by passing terms through analyzer.
- Overrides:
getPrefixQuery
in classorg.apache.lucene.queryParser.QueryParser
- Parameters:
field
- Name of the field query will use.termStr
- Term token to use for building term for the query (without trailing '*' character!)- Returns:
- Resulting
Query
built for the term - Throws:
org.apache.lucene.queryParser.ParseException
-
getFuzzyQuery
protected org.apache.lucene.search.Query getFuzzyQuery(String field, String termStr, float minSimilarity) throws org.apache.lucene.queryParser.ParseException
Called when parser parses an input term token that has the fuzzy suffix (~) appended.Depending on analyzer and settings, a fuzzy term may (most probably will) be lower-cased automatically. It will go through the default Analyzer.
Overrides super class, by passing terms through analyzer.
- Overrides:
getFuzzyQuery
in classorg.apache.lucene.queryParser.QueryParser
- Parameters:
field
- Name of the field query will use.termStr
- Term token to use for building term for the query- Returns:
- Resulting
Query
built for the term - Throws:
org.apache.lucene.queryParser.ParseException
-
getRangeQuery
protected org.apache.lucene.search.Query getRangeQuery(String field, String part1, String part2, boolean inclusive) throws org.apache.lucene.queryParser.ParseException
Overrides super class, by passing terms through analyzer.- Overrides:
getRangeQuery
in classorg.apache.lucene.queryParser.QueryParser
- Throws:
org.apache.lucene.queryParser.ParseException
-
-