Solr supports multiple query syntaxes through its query parser plugin framework. For documentation on the full list of available parser types, see the all subclasses of QParserPlugin in the javadoc, and also the QueryParser wiki page.

Specifying a Query Parser

Users can specify the type of a query in most places that accept a query string using LocalParams syntax. For example, the following query string specifies a lucene/solr query with a default operator of "AND" and a default field of "text": q={!lucene q.op=AND df=text}myfield:foo +bar -baz

In standard Solr search handlers, the defType param can be used to specify the default type of the main query (ie: the q param) but it only affects the main query -- The default type of all other query parameters will remain "lucene".

q={!func}popularity is thus equivalent to defType=func&q=popularity in the standard Solr search handler.

Default QParserPlugin: LuceneQParserPlugin

The standard Solr Query Parser syntax is a superset of the Lucene Query Parser Syntax (pre-4.0) or (4.0+). Certain characters are special (pre-4.0) or (4.0+) and those characters need to be escaped using quotes or a backslash if you want them to be treated as literals. For example, to search for (1+1):2 use one of the following syntaxes...


<!> Solr 4.0 added regular expression support, which means that '/' is now a special character and must be escaped if searching for literal forward slash.

Differences From Lucene Query Parser

Differences in the Solr Query Parser include

Although not technically a Syntax difference, please note that if you use the Solr "DateField" type, any queries on those fields (typically range queries) should use either the Complete ISO 8601 Date syntax that field supports, or the DateMath Syntax to get relative dates. Examples:

NOTE: TO must be uppercase, or Solr will report a 'RANGE_GOOP' error.

Dismax and eDismax Query Parser

The (e)dismax query parser provides query time field level boosting granularity, with less special syntax. (e)Dismax generally makes the best first choice query parser for user facing Solr applications. The (e)dismax handler parameters are described in detail here: DisMaxQParserPlugin and ExtendedDisMax.

More information

See SolrPlugins for information on writing your own query parser.

See QueryParser for a list of supported query parsers.

NOTE: URL Escaping Special Characters

Please note that many characters in the Solr Query Syntax (most notable the plus sign: "+") are special characters in URLs, so when constructing request URLs manually, you must properly URL-Encode these characters.

                                     q=  +popularity:[10   TO   *]     +section:0

For more information

SolrQuerySyntax (last edited 2013-11-15 23:01:27 by ShawnHeisey)