org.apache.solr.search
Class SolrQueryParser

java.lang.Object
  extended by org.apache.lucene.queryParser.QueryParser
      extended by org.apache.solr.search.SolrQueryParser
All Implemented Interfaces:
org.apache.lucene.queryParser.QueryParserConstants
Direct Known Subclasses:
SolrPluginUtils.DisjunctionMaxQueryParser

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

A variation on the Lucene QueryParser which knows about the field types and query time analyzers configured in Solr's schema.xml.

This class also deviates from the Lucene QueryParser by using ConstantScore versions of RangeQuery and PrefixQuery to prevent TooManyClauses exceptions.

If the magic field name "_val_" is used in a term or phrase query, the value is parsed as a function.

See Also:
QueryParsing.parseFunction(java.lang.String, org.apache.solr.schema.IndexSchema)

Nested Class Summary
 
Nested classes/interfaces inherited from class org.apache.lucene.queryParser.QueryParser
org.apache.lucene.queryParser.QueryParser.Operator
 
Field Summary
protected  String defaultField
           
protected  Map<String,ReversedWildcardFilterFactory> leadingWildcards
           
protected  QParser parser
           
protected  IndexSchema schema
           
 
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
SolrQueryParser(IndexSchema schema, String defaultField)
          Constructs a SolrQueryParser using the schema to understand the formats and datatypes of each field.
SolrQueryParser(QParser parser, String defaultField)
           
SolrQueryParser(QParser parser, String defaultField, org.apache.lucene.analysis.Analyzer analyzer)
           
 
Method Summary
protected  void checkAllowLeadingWildcards()
           
protected  org.apache.lucene.search.Query getFieldQuery(String field, String queryText, boolean quoted)
           
protected  org.apache.lucene.search.Query getPrefixQuery(String field, String termStr)
           
protected  org.apache.lucene.search.Query getRangeQuery(String field, String part1, String part2, boolean inclusive)
           
protected  org.apache.lucene.search.Query getWildcardQuery(String field, String termStr)
           
 
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, getFuzzyMinSim, getFuzzyPrefixLength, getFuzzyQuery, 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
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

schema

protected final IndexSchema schema

parser

protected final QParser parser

defaultField

protected final String defaultField

leadingWildcards

protected final Map<String,ReversedWildcardFilterFactory> leadingWildcards
Constructor Detail

SolrQueryParser

public SolrQueryParser(IndexSchema schema,
                       String defaultField)
Constructs a SolrQueryParser using the schema to understand the formats and datatypes of each field. Only the defaultSearchField will be used from the IndexSchema (unless overridden), <solrQueryParser> will not be used.

Parameters:
schema - Used for default search field name if defaultField is null and field information is used for analysis
defaultField - default field used for unspecified search terms. if null, the schema default field is used
See Also:
IndexSchema.getDefaultSearchFieldName()

SolrQueryParser

public SolrQueryParser(QParser parser,
                       String defaultField)

SolrQueryParser

public SolrQueryParser(QParser parser,
                       String defaultField,
                       org.apache.lucene.analysis.Analyzer analyzer)
Method Detail

checkAllowLeadingWildcards

protected void checkAllowLeadingWildcards()

getFieldQuery

protected org.apache.lucene.search.Query getFieldQuery(String field,
                                                       String queryText,
                                                       boolean quoted)
                                                throws org.apache.lucene.queryParser.ParseException
Overrides:
getFieldQuery in class org.apache.lucene.queryParser.QueryParser
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:
getRangeQuery in class org.apache.lucene.queryParser.QueryParser
Throws:
org.apache.lucene.queryParser.ParseException

getPrefixQuery

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

getWildcardQuery

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


Copyright © 2000-2011 Apache Software Foundation. All Rights Reserved.