Package org.apache.solr.parser
Class SolrQueryParserBase
- java.lang.Object
- 
- org.apache.lucene.util.QueryBuilder
- 
- org.apache.solr.parser.SolrQueryParserBase
 
 
- 
- Direct Known Subclasses:
- QueryParser
 
 public abstract class SolrQueryParserBase extends org.apache.lucene.util.QueryBuilderThis class is overridden by QueryParser in QueryParser.jj and acts to separate the majority of the Java code from the .jj grammar file.
- 
- 
Nested Class SummaryNested Classes Modifier and Type Class Description static classSolrQueryParserBase.MagicFieldNameIdentifies the list of all known "magic fields" that trigger special parsing behaviorstatic classSolrQueryParserBase.RawQuerystatic classSolrQueryParserBase.SynonymQueryStyleQuery strategy when analyzed query terms overlap the same position (ie synonyms) consider if pants and khakis are query time synonymsSolrQueryParserBase.SynonymQueryStyle.AS_SAME_TERMSolrQueryParserBase.SynonymQueryStyle.PICK_BESTSolrQueryParserBase.SynonymQueryStyle.AS_DISTINCT_TERMS
 - 
Field SummaryFields Modifier and Type Field Description static QueryParser.OperatorAND_OPERATORAlternative form of QueryParser.Operator.ANDprotected StringexplicitFieldprotected QueryParser.OperatoroperatorThe default operator that parser uses to combine query termsstatic QueryParser.OperatorOR_OPERATORAlternative form of QueryParser.Operator.ORprotected QParserparserprotected static StringREVERSE_WILDCARD_LOWER_BOUNDprotected IndexSchemaschemaprotected SolrQueryParserBase.SynonymQueryStylesynonymQueryStylestatic intTERMS_QUERY_THRESHOLD
 - 
Constructor SummaryConstructors Modifier Constructor Description protectedSolrQueryParserBase()
 - 
Method SummaryAll Methods Static Methods Instance Methods Abstract Methods Concrete Methods Modifier and Type Method Description protected voidaddClause(List<org.apache.lucene.search.BooleanClause> clauses, int conj, int mods, org.apache.lucene.search.Query q)protected voidaddMultiTermClause(List<org.apache.lucene.search.BooleanClause> clauses, org.apache.lucene.search.Query q)Called from QueryParser's MultiTerm rule.protected StringanalyzeIfMultitermTermText(String field, String part, FieldType fieldType)static Stringescape(String s)Returns a String where those characters that QueryParser expects to be escaped are escaped by a preceding\.booleangetAllowLeadingWildcard()booleangetAutoGeneratePhraseQueries()protected org.apache.lucene.search.QuerygetBooleanQuery(List<org.apache.lucene.search.BooleanClause> clauses)Factory method for generating query, given a set of clauses.StringgetDefaultField()QueryParser.OperatorgetDefaultOperator()Gets implicit operator setting, which will be either AND_OPERATOR or OR_OPERATOR.StringgetExplicitField()For a fielded query, returns the actual field specified (i.e.StringgetField(String fieldName)Handles the default field if null is passedprotected org.apache.lucene.search.QuerygetFieldQuery(String field, String queryText, boolean quoted)protected org.apache.lucene.search.QuerygetFieldQuery(String field, String queryText, boolean quoted, boolean raw)protected org.apache.lucene.search.QuerygetFieldQuery(String field, String queryText, int slop)Base implementation delegates togetFieldQuery(String,String,boolean,boolean).protected org.apache.lucene.search.QuerygetFieldQuery(String field, List<String> queryTerms, boolean raw)floatgetFuzzyMinSim()Get the minimal similarity for fuzzy queries.intgetFuzzyPrefixLength()Get the prefix length for fuzzy queries.protected org.apache.lucene.search.QuerygetFuzzyQuery(String field, String termStr, float minSimilarity)protected org.apache.lucene.search.QuerygetLocalParams(String qfield, String lparams)org.apache.lucene.search.MultiTermQuery.RewriteMethodgetMultiTermRewriteMethod()intgetPhraseSlop()Gets the default slop for phrases.protected org.apache.lucene.search.QuerygetPrefixQuery(String field, String termStr)protected org.apache.lucene.search.QuerygetRangeQuery(String field, String part1, String part2, boolean startInclusive, boolean endInclusive)protected org.apache.lucene.search.QuerygetRangeQueryImpl(String field, String part1, String part2, boolean startInclusive, boolean endInclusive)protected org.apache.lucene.search.QuerygetRegexpQuery(String field, String termStr)protected ReversedWildcardFilterFactorygetReversedWildcardFilterFactory(FieldType fieldType)SolrQueryParserBase.SynonymQueryStylegetSynonymQueryStyle()Gets how overlapping query terms should be scoredprotected org.apache.lucene.search.QuerygetWildcardQuery(String field, String termStr)voidinit(String defaultField, QParser parser)booleanisAllowSubQueryParsing()protected booleanisRangeShouldBeProtectedFromReverse(String field, String part1)protected org.apache.lucene.search.BooleanClausenewBooleanClause(org.apache.lucene.search.Query q, org.apache.lucene.search.BooleanClause.Occur occur)Builds a new BooleanClause instanceprotected org.apache.lucene.search.QuerynewFieldQuery(org.apache.lucene.analysis.Analyzer analyzer, String field, String queryText, boolean quoted, boolean fieldAutoGenPhraseQueries, boolean fieldEnableGraphQueries, SolrQueryParserBase.SynonymQueryStyle synonymQueryStyle)protected org.apache.lucene.search.QuerynewFuzzyQuery(org.apache.lucene.index.Term term, float minimumSimilarity, int prefixLength)Builds a new FuzzyQuery instanceprotected org.apache.lucene.search.QuerynewMatchAllDocsQuery()Builds a new MatchAllDocsQuery instanceprotected org.apache.lucene.search.QuerynewPrefixQuery(org.apache.lucene.index.Term prefix)Builds a new PrefixQuery instanceprotected org.apache.lucene.search.QuerynewRegexpQuery(org.apache.lucene.index.Term regexp)Builds a new RegexpQuery instanceprotected org.apache.lucene.search.QuerynewSynonymQuery(org.apache.lucene.index.Term[] terms)protected org.apache.lucene.search.QuerynewWildcardQuery(org.apache.lucene.index.Term t)Builds a new WildcardQuery instanceorg.apache.lucene.search.Queryparse(String query)Parses a query string, returning aQuery.abstract voidReInit(CharStream stream)voidsetAllowLeadingWildcard(boolean allowLeadingWildcard)Set totrueto allow leading wildcard characters.voidsetAllowSubQueryParsing(boolean allowSubQueryParsing)Set to enable subqueries to be parsed.voidsetAutoGeneratePhraseQueries(boolean value)Set to true if phrase queries will be automatically generated when the analyzer returns more than one term from whitespace delimited text.voidsetDefaultOperator(QueryParser.Operator op)Sets the boolean operator of the QueryParser.voidsetFuzzyMinSim(float fuzzyMinSim)Set the minimum similarity for fuzzy queries.voidsetFuzzyPrefixLength(int fuzzyPrefixLength)Set the prefix length for fuzzy queries.voidsetMultiTermRewriteMethod(org.apache.lucene.search.MultiTermQuery.RewriteMethod method)By default QueryParser usesMultiTermQuery.CONSTANT_SCORE_REWRITEwhen creating a PrefixQuery, WildcardQuery or RangeQuery.voidsetPhraseSlop(int phraseSlop)Sets the default slop for phrases.voidsetSynonymQueryStyle(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 togetherabstract org.apache.lucene.search.QueryTopLevelQuery(String field)- 
Methods inherited from class org.apache.lucene.util.QueryBuilderadd, 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
 
- 
 
- 
- 
- 
Field Detail- 
REVERSE_WILDCARD_LOWER_BOUNDprotected static final String REVERSE_WILDCARD_LOWER_BOUND 
 - 
TERMS_QUERY_THRESHOLDpublic static final int TERMS_QUERY_THRESHOLD - See Also:
- Constant Field Values
 
 - 
synonymQueryStyleprotected SolrQueryParserBase.SynonymQueryStyle synonymQueryStyle 
 - 
AND_OPERATORpublic static final QueryParser.Operator AND_OPERATOR Alternative form of QueryParser.Operator.AND
 - 
OR_OPERATORpublic static final QueryParser.Operator OR_OPERATOR Alternative form of QueryParser.Operator.OR
 - 
operatorprotected QueryParser.Operator operator The default operator that parser uses to combine query terms
 - 
schemaprotected IndexSchema schema 
 - 
parserprotected QParser parser 
 - 
explicitFieldprotected String explicitField 
 
- 
 - 
Method Detail- 
ReInitpublic abstract void ReInit(CharStream stream) 
 - 
TopLevelQuerypublic abstract org.apache.lucene.search.Query TopLevelQuery(String field) throws ParseException, SyntaxError - Throws:
- ParseException
- SyntaxError
 
 - 
parsepublic org.apache.lucene.search.Query parse(String query) throws SyntaxError Parses a query string, returning aQuery.- Parameters:
- query- the query string to be parsed.
- Throws:
- SyntaxError
 
 - 
getDefaultFieldpublic String getDefaultField() - Returns:
- Returns the default field.
 
 - 
getExplicitFieldpublic String getExplicitField() For a fielded query, returns the actual field specified (i.e. null if default is being used) myfield:A or myfield:(A B C) will both return "myfield"
 - 
getAutoGeneratePhraseQueriespublic final boolean getAutoGeneratePhraseQueries() - See Also:
- setAutoGeneratePhraseQueries(boolean)
 
 - 
setAutoGeneratePhraseQueriespublic final 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. NOTE: this behavior may not be suitable for all languages.Set to false if phrase queries should only be generated when surrounded by double quotes. 
 - 
getFuzzyMinSimpublic float getFuzzyMinSim() Get the minimal similarity for fuzzy queries.
 - 
setFuzzyMinSimpublic void setFuzzyMinSim(float fuzzyMinSim) Set the minimum similarity for fuzzy queries. Default is 2f.
 - 
getFuzzyPrefixLengthpublic int getFuzzyPrefixLength() Get the prefix length for fuzzy queries.- Returns:
- Returns the fuzzyPrefixLength.
 
 - 
setFuzzyPrefixLengthpublic void setFuzzyPrefixLength(int fuzzyPrefixLength) Set the prefix length for fuzzy queries. Default is 0.- Parameters:
- fuzzyPrefixLength- The fuzzyPrefixLength to set.
 
 - 
setPhraseSloppublic void setPhraseSlop(int phraseSlop) Sets the default slop for phrases. If zero, then exact phrase matches are required. Default value is zero.
 - 
getPhraseSloppublic int getPhraseSlop() Gets the default slop for phrases.
 - 
isAllowSubQueryParsingpublic boolean isAllowSubQueryParsing() - See Also:
- setAllowLeadingWildcard(boolean)
 
 - 
setAllowSubQueryParsingpublic void setAllowSubQueryParsing(boolean allowSubQueryParsing) Set to enable subqueries to be parsed. If now allowed, the default, aSyntaxErrorwill 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}".
 - 
setSynonymQueryStylepublic 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- Parameters:
- synonymQueryStyle- how to score terms that overlap see {- SolrQueryParserBase.SynonymQueryStyle}
 
 - 
getSynonymQueryStylepublic SolrQueryParserBase.SynonymQueryStyle getSynonymQueryStyle() Gets how overlapping query terms should be scored
 - 
setAllowLeadingWildcardpublic void setAllowLeadingWildcard(boolean allowLeadingWildcard) Set totrueto 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. 
 - 
getAllowLeadingWildcardpublic boolean getAllowLeadingWildcard() - See Also:
- setAllowLeadingWildcard(boolean)
 
 - 
setDefaultOperatorpublic void setDefaultOperator(QueryParser.Operator op) Sets the boolean operator of the QueryParser. In default mode (OR_OPERATOR) terms without any modifiers are considered optional: for examplecapital of Hungaryis equal tocapital OR of OR Hungary.
 InAND_OPERATORmode terms are considered to be in conjunction: the above mentioned query is parsed ascapital AND of AND Hungary
 - 
getDefaultOperatorpublic QueryParser.Operator getDefaultOperator() Gets implicit operator setting, which will be either AND_OPERATOR or OR_OPERATOR.
 - 
setMultiTermRewriteMethodpublic void setMultiTermRewriteMethod(org.apache.lucene.search.MultiTermQuery.RewriteMethod method) By default QueryParser usesMultiTermQuery.CONSTANT_SCORE_REWRITEwhen 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.
 - 
getMultiTermRewriteMethodpublic org.apache.lucene.search.MultiTermQuery.RewriteMethod getMultiTermRewriteMethod() 
 - 
addClauseprotected void addClause(List<org.apache.lucene.search.BooleanClause> clauses, int conj, int mods, org.apache.lucene.search.Query q) 
 - 
addMultiTermClauseprotected void addMultiTermClause(List<org.apache.lucene.search.BooleanClause> clauses, org.apache.lucene.search.Query q) Called from QueryParser's MultiTerm rule. Assumption: no conjunction or modifiers (conj == CONJ_NONE and mods == MOD_NONE)
 - 
newFieldQueryprotected org.apache.lucene.search.Query newFieldQuery(org.apache.lucene.analysis.Analyzer analyzer, String field, String queryText, boolean quoted, boolean fieldAutoGenPhraseQueries, boolean fieldEnableGraphQueries, SolrQueryParserBase.SynonymQueryStyle synonymQueryStyle) throws SyntaxError- Throws:
- SyntaxError
 
 - 
getFieldQueryprotected org.apache.lucene.search.Query getFieldQuery(String field, String queryText, int slop) throws SyntaxError Base implementation delegates togetFieldQuery(String,String,boolean,boolean). This method may be overridden, for example, to return a SpanNearQuery instead of a PhraseQuery.- Throws:
- SyntaxError
 
 - 
newBooleanClauseprotected org.apache.lucene.search.BooleanClause newBooleanClause(org.apache.lucene.search.Query q, org.apache.lucene.search.BooleanClause.Occur occur)Builds a new BooleanClause instance- Parameters:
- q- sub query
- occur- how this clause should occur when matching documents
- Returns:
- new BooleanClause instance
 
 - 
newPrefixQueryprotected org.apache.lucene.search.Query newPrefixQuery(org.apache.lucene.index.Term prefix) Builds a new PrefixQuery instance- Parameters:
- prefix- Prefix term
- Returns:
- new PrefixQuery instance
 
 - 
newRegexpQueryprotected org.apache.lucene.search.Query newRegexpQuery(org.apache.lucene.index.Term regexp) Builds a new RegexpQuery instance- Parameters:
- regexp- Regexp term
- Returns:
- new RegexpQuery instance
 
 - 
newSynonymQueryprotected org.apache.lucene.search.Query newSynonymQuery(org.apache.lucene.index.Term[] terms) - Overrides:
- newSynonymQueryin class- org.apache.lucene.util.QueryBuilder
 
 - 
newFuzzyQueryprotected org.apache.lucene.search.Query newFuzzyQuery(org.apache.lucene.index.Term term, float minimumSimilarity, int prefixLength)Builds a new FuzzyQuery instance- Parameters:
- term- Term
- minimumSimilarity- minimum similarity
- prefixLength- prefix length
- Returns:
- new FuzzyQuery Instance
 
 - 
newMatchAllDocsQueryprotected org.apache.lucene.search.Query newMatchAllDocsQuery() Builds a new MatchAllDocsQuery instance- Returns:
- new MatchAllDocsQuery instance
 
 - 
newWildcardQueryprotected org.apache.lucene.search.Query newWildcardQuery(org.apache.lucene.index.Term t) Builds a new WildcardQuery instance- Parameters:
- t- wildcard term
- Returns:
- new WildcardQuery instance
 
 - 
getBooleanQueryprotected org.apache.lucene.search.Query getBooleanQuery(List<org.apache.lucene.search.BooleanClause> clauses) throws SyntaxError Factory method for generating query, given a set of clauses. By default creates a boolean query composed of clauses passed in. Can be overridden by extending classes, to modify query being returned.- Parameters:
- clauses- List that contains- BooleanClauseinstances to join.
- Returns:
- Resulting Queryobject.
- Throws:
- SyntaxError
 
 - 
escapepublic static String escape(String s) Returns a String where those characters that QueryParser expects to be escaped are escaped by a preceding\.
 - 
getReversedWildcardFilterFactoryprotected ReversedWildcardFilterFactory getReversedWildcardFilterFactory(FieldType fieldType) 
 - 
analyzeIfMultitermTermTextprotected String analyzeIfMultitermTermText(String field, String part, FieldType fieldType) 
 - 
getFieldQueryprotected org.apache.lucene.search.Query getFieldQuery(String field, String queryText, boolean quoted) throws SyntaxError - Throws:
- SyntaxError
 
 - 
getFieldQueryprotected org.apache.lucene.search.Query getFieldQuery(String field, String queryText, boolean quoted, boolean raw) throws SyntaxError - Throws:
- SyntaxError
 
 - 
getFieldQueryprotected org.apache.lucene.search.Query getFieldQuery(String field, List<String> queryTerms, boolean raw) throws SyntaxError - Throws:
- SyntaxError
 
 - 
isRangeShouldBeProtectedFromReverseprotected boolean isRangeShouldBeProtectedFromReverse(String field, String part1) 
 - 
getRangeQueryprotected org.apache.lucene.search.Query getRangeQuery(String field, String part1, String part2, boolean startInclusive, boolean endInclusive) throws SyntaxError - Throws:
- SyntaxError
 
 - 
getRangeQueryImplprotected org.apache.lucene.search.Query getRangeQueryImpl(String field, String part1, String part2, boolean startInclusive, boolean endInclusive) throws SyntaxError - Throws:
- SyntaxError
 
 - 
getPrefixQueryprotected org.apache.lucene.search.Query getPrefixQuery(String field, String termStr) throws SyntaxError - Throws:
- SyntaxError
 
 - 
getWildcardQueryprotected org.apache.lucene.search.Query getWildcardQuery(String field, String termStr) throws SyntaxError - Throws:
- SyntaxError
 
 - 
getRegexpQueryprotected org.apache.lucene.search.Query getRegexpQuery(String field, String termStr) throws SyntaxError - Throws:
- SyntaxError
 
 - 
getFuzzyQueryprotected org.apache.lucene.search.Query getFuzzyQuery(String field, String termStr, float minSimilarity) throws SyntaxError - Throws:
- SyntaxError
 
 - 
getLocalParamsprotected org.apache.lucene.search.Query getLocalParams(String qfield, String lparams) throws SyntaxError - Throws:
- SyntaxError
 
 
- 
 
-