public abstract class SolrQueryParserBase extends QueryBuilder
Modifier and Type | Class and Description |
---|---|
static class |
SolrQueryParserBase.MagicFieldName
Identifies the list of all known "magic fields" that trigger
special parsing behavior
|
static class |
SolrQueryParserBase.RawQuery |
static class |
SolrQueryParserBase.SynonymQueryStyle
Query strategy when analyzed query terms overlap the same position (ie synonyms)
consider if pants and khakis are query time synonyms
SolrQueryParserBase.SynonymQueryStyle.AS_SAME_TERM
SolrQueryParserBase.SynonymQueryStyle.PICK_BEST
SolrQueryParserBase.SynonymQueryStyle.AS_DISTINCT_TERMS |
Modifier and Type | Field and Description |
---|---|
static QueryParser.Operator |
AND_OPERATOR
Alternative form of QueryParser.Operator.AND
|
protected String |
explicitField |
protected QueryParser.Operator |
operator
The default operator that parser uses to combine query terms
|
static QueryParser.Operator |
OR_OPERATOR
Alternative form of QueryParser.Operator.OR
|
protected QParser |
parser |
protected static String |
REVERSE_WILDCARD_LOWER_BOUND |
protected IndexSchema |
schema |
protected SolrQueryParserBase.SynonymQueryStyle |
synonymQueryStyle |
static int |
TERMS_QUERY_THRESHOLD |
analyzer, autoGenerateMultiTermSynonymsPhraseQuery, enableGraphQueries, enablePositionIncrements
Modifier | Constructor and Description |
---|---|
protected |
SolrQueryParserBase() |
Modifier and Type | Method and Description |
---|---|
protected void |
addClause(List<BooleanClause> clauses,
int conj,
int mods,
Query q) |
protected void |
addMultiTermClause(List<BooleanClause> clauses,
Query q)
Called from QueryParser's MultiTerm rule.
|
protected String |
analyzeIfMultitermTermText(String field,
String part,
FieldType fieldType) |
static String |
escape(String s)
Returns a String where those characters that QueryParser
expects to be escaped are escaped by a preceding
\ . |
boolean |
getAllowLeadingWildcard() |
boolean |
getAutoGeneratePhraseQueries() |
protected Query |
getBooleanQuery(List<BooleanClause> clauses)
Factory method for generating query, given a set of clauses.
|
String |
getDefaultField() |
QueryParser.Operator |
getDefaultOperator()
Gets implicit operator setting, which will be either AND_OPERATOR
or OR_OPERATOR.
|
String |
getExplicitField()
For a fielded query, returns the actual field specified (i.e.
|
String |
getField(String fieldName)
Handles the default field if null is passed
|
protected Query |
getFieldQuery(String field,
List<String> queryTerms,
boolean raw) |
protected Query |
getFieldQuery(String field,
String queryText,
boolean quoted) |
protected Query |
getFieldQuery(String field,
String queryText,
boolean quoted,
boolean raw) |
protected Query |
getFieldQuery(String field,
String queryText,
int slop)
Base implementation delegates to
getFieldQuery(String,String,boolean,boolean) . |
float |
getFuzzyMinSim()
Get the minimal similarity for fuzzy queries.
|
int |
getFuzzyPrefixLength()
Get the prefix length for fuzzy queries.
|
protected Query |
getFuzzyQuery(String field,
String termStr,
float minSimilarity) |
protected Query |
getLocalParams(String qfield,
String lparams) |
MultiTermQuery.RewriteMethod |
getMultiTermRewriteMethod() |
int |
getPhraseSlop()
Gets the default slop for phrases.
|
protected Query |
getPrefixQuery(String field,
String termStr) |
protected Query |
getRangeQuery(String field,
String part1,
String part2,
boolean startInclusive,
boolean endInclusive) |
protected Query |
getRangeQueryImpl(String field,
String part1,
String part2,
boolean startInclusive,
boolean endInclusive) |
protected Query |
getRegexpQuery(String field,
String termStr) |
protected ReversedWildcardFilterFactory |
getReversedWildcardFilterFactory(FieldType fieldType) |
SolrQueryParserBase.SynonymQueryStyle |
getSynonymQueryStyle()
Gets how overlapping query terms should be scored
|
protected Query |
getWildcardQuery(String field,
String termStr) |
void |
init(String defaultField,
QParser parser) |
boolean |
isAllowSubQueryParsing() |
protected boolean |
isRangeShouldBeProtectedFromReverse(String field,
String part1) |
protected BooleanClause |
newBooleanClause(Query q,
BooleanClause.Occur occur)
Builds a new BooleanClause instance
|
protected Query |
newFieldQuery(Analyzer analyzer,
String field,
String queryText,
boolean quoted,
boolean fieldAutoGenPhraseQueries,
boolean fieldEnableGraphQueries,
SolrQueryParserBase.SynonymQueryStyle synonymQueryStyle) |
protected Query |
newFuzzyQuery(Term term,
float minimumSimilarity,
int prefixLength)
Builds a new FuzzyQuery instance
|
protected Query |
newMatchAllDocsQuery()
Builds a new MatchAllDocsQuery instance
|
protected Query |
newPrefixQuery(Term prefix)
Builds a new PrefixQuery instance
|
protected Query |
newRegexpQuery(Term regexp)
Builds a new RegexpQuery instance
|
protected Query |
newSynonymQuery(Term[] terms) |
protected Query |
newWildcardQuery(Term t)
Builds a new WildcardQuery instance
|
Query |
parse(String query)
Parses a query string, returning a
Query . |
abstract void |
ReInit(CharStream stream) |
void |
setAllowLeadingWildcard(boolean allowLeadingWildcard)
Set to
true to allow leading wildcard characters. |
void |
setAllowSubQueryParsing(boolean allowSubQueryParsing)
Set to enable subqueries to be parsed.
|
void |
setAutoGeneratePhraseQueries(boolean value)
Set to true if phrase queries will be automatically generated
when the analyzer returns more than one term from whitespace
delimited text.
|
void |
setDefaultOperator(QueryParser.Operator op)
Sets the boolean operator of the QueryParser.
|
void |
setFuzzyMinSim(float fuzzyMinSim)
Set the minimum similarity for fuzzy queries.
|
void |
setFuzzyPrefixLength(int fuzzyPrefixLength)
Set the prefix length for fuzzy queries.
|
void |
setMultiTermRewriteMethod(MultiTermQuery.RewriteMethod method)
By default QueryParser uses
MultiTermQuery.CONSTANT_SCORE_REWRITE
when creating a PrefixQuery, WildcardQuery or RangeQuery. |
void |
setPhraseSlop(int phraseSlop)
Sets the default slop for phrases.
|
void |
setSynonymQueryStyle(SolrQueryParserBase.SynonymQueryStyle synonymQueryStyle)
Set how overlapping query terms (ie synonyms) should be scored, as if they're the same term,
picking highest scoring term, or OR'ing them together
|
abstract Query |
TopLevelQuery(String field) |
add, analyzeBoolean, analyzeGraphBoolean, analyzeGraphPhrase, analyzeMultiBoolean, analyzeMultiPhrase, analyzePhrase, analyzeTerm, createBooleanQuery, createBooleanQuery, createFieldQuery, createFieldQuery, createMinShouldMatchQuery, createPhraseQuery, createPhraseQuery, createSpanQuery, getAnalyzer, getAutoGenerateMultiTermSynonymsPhraseQuery, getEnableGraphQueries, getEnablePositionIncrements, newBooleanQuery, newGraphSynonymQuery, newMultiPhraseQueryBuilder, newTermQuery, setAnalyzer, setAutoGenerateMultiTermSynonymsPhraseQuery, setEnableGraphQueries, setEnablePositionIncrements
protected static final String REVERSE_WILDCARD_LOWER_BOUND
public static final int TERMS_QUERY_THRESHOLD
protected SolrQueryParserBase.SynonymQueryStyle synonymQueryStyle
public static final QueryParser.Operator AND_OPERATOR
public static final QueryParser.Operator OR_OPERATOR
protected QueryParser.Operator operator
protected IndexSchema schema
protected QParser parser
protected String explicitField
public abstract void ReInit(CharStream stream)
public abstract Query TopLevelQuery(String field) throws ParseException, SyntaxError
ParseException
SyntaxError
public Query parse(String query) throws SyntaxError
Query
.query
- the query string to be parsed.SyntaxError
public String getDefaultField()
public String getExplicitField()
public final boolean getAutoGeneratePhraseQueries()
setAutoGeneratePhraseQueries(boolean)
public final void setAutoGeneratePhraseQueries(boolean value)
Set to false if phrase queries should only be generated when surrounded by double quotes.
public float getFuzzyMinSim()
public void setFuzzyMinSim(float fuzzyMinSim)
public int getFuzzyPrefixLength()
public void setFuzzyPrefixLength(int fuzzyPrefixLength)
fuzzyPrefixLength
- The fuzzyPrefixLength to set.public void setPhraseSlop(int phraseSlop)
public int getPhraseSlop()
public boolean isAllowSubQueryParsing()
setAllowLeadingWildcard(boolean)
public void setAllowSubQueryParsing(boolean allowSubQueryParsing)
SyntaxError
will likely be thrown.
Here is the preferred syntax using local-params:
{!prefix f=field v=foo}
and here is the older one, using a magic field name:
_query_:"{!prefix f=field v=foo}"
.public void setSynonymQueryStyle(SolrQueryParserBase.SynonymQueryStyle synonymQueryStyle)
synonymQueryStyle
- how to score terms that overlap see {SolrQueryParserBase.SynonymQueryStyle
}public SolrQueryParserBase.SynonymQueryStyle getSynonymQueryStyle()
public void setAllowLeadingWildcard(boolean allowLeadingWildcard)
true
to allow leading wildcard characters.
When set, *
or ?
are allowed as
the first character of a PrefixQuery and WildcardQuery.
Note that this can produce very slow
queries on big indexes.
Default: false.
public boolean getAllowLeadingWildcard()
setAllowLeadingWildcard(boolean)
public void setDefaultOperator(QueryParser.Operator op)
OR_OPERATOR
) terms without any modifiers
are considered optional: for example capital of Hungary
is equal to
capital OR of OR Hungary
.AND_OPERATOR
mode terms are considered to be in conjunction: the
above mentioned query is parsed as capital AND of AND Hungary
public QueryParser.Operator getDefaultOperator()
public void setMultiTermRewriteMethod(MultiTermQuery.RewriteMethod method)
MultiTermQuery.CONSTANT_SCORE_REWRITE
when creating a PrefixQuery, WildcardQuery or RangeQuery. This implementation is generally preferable because it
a) Runs faster b) Does not have the scarcity of terms unduly influence score
c) avoids any "TooManyBooleanClauses" exception.
However, if your application really needs to use the
old-fashioned BooleanQuery expansion rewriting and the above
points are not relevant then use this to change
the rewrite method.public MultiTermQuery.RewriteMethod getMultiTermRewriteMethod()
protected void addClause(List<BooleanClause> clauses, int conj, int mods, Query q)
protected void addMultiTermClause(List<BooleanClause> clauses, Query q)
protected Query newFieldQuery(Analyzer analyzer, String field, String queryText, boolean quoted, boolean fieldAutoGenPhraseQueries, boolean fieldEnableGraphQueries, SolrQueryParserBase.SynonymQueryStyle synonymQueryStyle) throws SyntaxError
SyntaxError
protected Query getFieldQuery(String field, String queryText, int slop) throws SyntaxError
getFieldQuery(String,String,boolean,boolean)
.
This method may be overridden, for example, to return
a SpanNearQuery instead of a PhraseQuery.SyntaxError
protected BooleanClause newBooleanClause(Query q, BooleanClause.Occur occur)
q
- sub queryoccur
- how this clause should occur when matching documentsprotected Query newPrefixQuery(Term prefix)
prefix
- Prefix termprotected Query newRegexpQuery(Term regexp)
regexp
- Regexp termprotected Query newSynonymQuery(Term[] terms)
newSynonymQuery
in class QueryBuilder
protected Query newFuzzyQuery(Term term, float minimumSimilarity, int prefixLength)
term
- TermminimumSimilarity
- minimum similarityprefixLength
- prefix lengthprotected Query newMatchAllDocsQuery()
protected Query newWildcardQuery(Term t)
t
- wildcard termprotected Query getBooleanQuery(List<BooleanClause> clauses) throws SyntaxError
clauses
- List that contains BooleanClause
instances
to join.Query
object.SyntaxError
public static String escape(String s)
\
.protected ReversedWildcardFilterFactory getReversedWildcardFilterFactory(FieldType fieldType)
protected String analyzeIfMultitermTermText(String field, String part, FieldType fieldType)
protected Query getFieldQuery(String field, String queryText, boolean quoted) throws SyntaxError
SyntaxError
protected Query getFieldQuery(String field, String queryText, boolean quoted, boolean raw) throws SyntaxError
SyntaxError
protected Query getFieldQuery(String field, List<String> queryTerms, boolean raw) throws SyntaxError
SyntaxError
protected boolean isRangeShouldBeProtectedFromReverse(String field, String part1)
protected Query getRangeQuery(String field, String part1, String part2, boolean startInclusive, boolean endInclusive) throws SyntaxError
SyntaxError
protected Query getRangeQueryImpl(String field, String part1, String part2, boolean startInclusive, boolean endInclusive) throws SyntaxError
SyntaxError
protected Query getPrefixQuery(String field, String termStr) throws SyntaxError
SyntaxError
protected Query getWildcardQuery(String field, String termStr) throws SyntaxError
SyntaxError
protected Query getRegexpQuery(String field, String termStr) throws SyntaxError
SyntaxError
protected Query getFuzzyQuery(String field, String termStr, float minSimilarity) throws SyntaxError
SyntaxError
protected Query getLocalParams(String qfield, String lparams) throws SyntaxError
SyntaxError
Copyright © 2000-2017 Apache Software Foundation. All Rights Reserved.