Dear Wiki user,

You have subscribed to a wiki page or wiki category on "Solr Wiki" for change 
notification.

The "SolrQuerySyntax" page has been changed by MichaelLong:
http://wiki.apache.org/solr/SolrQuerySyntax?action=diff&rev1=36&rev2=37

Comment:
solr 4.0 changes query syntax due to regular expression support

+ 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  
[[http://lucene.apache.org/solr/api/org/apache/solr/search/QParserPlugin.html|QParserPlugin]]
 in the javadoc.
- 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 
- 
[[http://lucene.apache.org/solr/api/org/apache/solr/search/QParserPlugin.html|QParserPlugin]]
 in the javadoc.
  
  <<TableOfContents>>
  
  = 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}}}
- 
- 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|lucene]]".
  
+ {{{q={!func}popularity}}} is thus equivalent to 
{{{defType=func&q=popularity}}} in the standard Solr search handler.
- {{{q={!func}popularity}}}
- is thus equivalent to
- {{{defType=func&q=popularity}}}
- in the standard Solr search handler.
  
  <<Anchor(lucene)>>
+ 
  = Default QParserPlugin: LuceneQParserPlugin =
+ The standard Solr Query Parser syntax is a superset of the Lucene Query 
Parser Syntax 
([[http://lucene.apache.org/java/3_6_0/queryparsersyntax.html|pre-4.0]]) or 
([[http://lucene.apache.org/core/4_0_0/queryparser/org/apache/lucene/queryparser/classic/package-summary.html|4.0+]]).
 Certain characters are special 
([[http://lucene.apache.org/java/3_6_0/queryparsersyntax.html#Escaping.2520Special.2520Characters|pre-4.0]])
 or 
([[http://lucene.apache.org/core/4_0_0/queryparser/org/apache/lucene/queryparser/classic/package-summary.html#Escaping%20Special%20Characters|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...
- 
- The standard Solr Query Parser syntax is a superset of the 
[[http://lucene.apache.org/java/3_6_0/queryparsersyntax.html|Lucene Query 
Parser syntax]].  
[[http://lucene.apache.org/java/3_6_0/queryparsersyntax.html#Escaping%20Special%20Characters|Certain
 characters are special]] 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...
  
  {{{
  \(1\+1\)\:2
  "(1+1):2"
  }}}
+ <!> 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
  
- Differences in the Solr Query Parser include
   * Range queries {{{[a TO z]}}}, prefix queries {{{a*}}}, and wildcard 
queries {{{a*b}}} are constant-scoring (all matching documents get an equal 
score).  The scoring factors tf, idf, index boost, and coord are not used.  
There is no limitation on the number of terms that match (as there was in past 
versions of Lucene).
-    * Lucene 2.1 has also switched to use !ConstantScoreRangeQuery for its 
range queries.
+   * Lucene 2.1 has also switched to use !ConstantScoreRangeQuery for its 
range queries.
   * A {{{*}}} may be used for either or both endpoints to specify an 
open-ended range query.
-    * {{{field:[* TO 100]}}} finds all field values less than or equal to 100
+   * {{{field:[* TO 100]}}} finds all field values less than or equal to 100
-    * {{{field:[100 TO *]}}} finds all field values greater than or equal to 
100
+   * {{{field:[100 TO *]}}} finds all field values greater than or equal to 100
-    * {{{field:[* TO *]}}} matches all documents with the field
+   * {{{field:[* TO *]}}} matches all documents with the field
   * Pure negative queries (all clauses prohibited) are allowed.
-    * {{{-inStock:false}}} finds all field values where inStock is not false
+   * {{{-inStock:false}}} finds all field values where inStock is not false
-    * {{{-field:[* TO *]}}} finds all documents without a value for field
+   * {{{-field:[* TO *]}}} finds all documents without a value for field
   * A hook into FunctionQuery syntax.  Quotes will be necessary to encapsulate 
the function when it includes parentheses.
-    * Example: {{{_val_:myfield}}}
+   * Example: {{{_val_:myfield}}}
-    * Example: {{{_val_:"recip(rord(myfield),1,2,3)"}}}
+   * Example: {{{_val_:"recip(rord(myfield),1,2,3)"}}}
   * Nested query support for any type of query parser (via QParserPlugin).  
Quotes will often be necessary to encapsulate the nested query if it contains 
reserved characters.
-    * Example: {{{_query_:"{!dismax qf=myfield}how now brown cow"}}}
+   * Example: {{{_query_:"{!dismax qf=myfield}how now brown cow"}}}
  
  Although not technically a Syntax difference, please note that if you use the 
Solr 
"[[http://lucene.apache.org/solr/api/org/apache/solr/schema/DateField.html|DateField]]"
 type, any queries on those fields (typically range queries) should use either 
the Complete ISO 8601 Date syntax that field supports, or the 
[[http://lucene.apache.org/solr/api/org/apache/solr/util/DateMathParser.html|DateMath]]
 Syntax to get relative dates.  Examples:
  
-    * {{{timestamp:[* TO NOW]}}}
+  * {{{timestamp:[* TO NOW]}}}
-    * {{{createdate:[1976-03-06T23:59:59.999Z TO *]}}}
+  * {{{createdate:[1976-03-06T23:59:59.999Z TO *]}}}
-    * {{{createdate:[1995-12-31T23:59:59.999Z TO 2007-03-06T00:00:00Z]}}}
+  * {{{createdate:[1995-12-31T23:59:59.999Z TO 2007-03-06T00:00:00Z]}}}
-    * {{{pubdate:[NOW-1YEAR/DAY TO NOW/DAY+1DAY]}}}
+  * {{{pubdate:[NOW-1YEAR/DAY TO NOW/DAY+1DAY]}}}
-    * {{{createdate:[1976-03-06T23:59:59.999Z TO 
1976-03-06T23:59:59.999Z+1YEAR]}}}
+  * {{{createdate:[1976-03-06T23:59:59.999Z TO 
1976-03-06T23:59:59.999Z+1YEAR]}}}
-    * {{{createdate:[1976-03-06T23:59:59.999Z/YEAR TO 
1976-03-06T23:59:59.999Z]}}}
+  * {{{createdate:[1976-03-06T23:59:59.999Z/YEAR TO 
1976-03-06T23:59:59.999Z]}}}
  
  '''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]].
+ 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.
  
  = Other built-in useful query parsers =
- 
-   * 
[[http://lucene.apache.org/solr/api/org/apache/solr/search/FunctionQParserPlugin.html|func]]
 - create a function query
+  * 
[[http://lucene.apache.org/solr/api/org/apache/solr/search/FunctionQParserPlugin.html|func]]
 - create a function query
-   * 
[[http://lucene.apache.org/solr/api/org/apache/solr/search/BoostQParserPlugin.html|boost]]
 - boost a query by a function query
+  * 
[[http://lucene.apache.org/solr/api/org/apache/solr/search/BoostQParserPlugin.html|boost]]
 - boost a query by a function query
-   * 
[[http://lucene.apache.org/solr/api/org/apache/solr/search/FunctionRangeQParserPlugin.html|frange]]
 - functions as range filters, also see this 
[[http://www.lucidimagination.com/blog/2009/07/06/ranges-over-functions-in-solr-14|intro
 blog]]
+  * 
[[http://lucene.apache.org/solr/api/org/apache/solr/search/FunctionRangeQParserPlugin.html|frange]]
 - functions as range filters, also see this 
[[http://www.lucidimagination.com/blog/2009/07/06/ranges-over-functions-in-solr-14|intro
 blog]]
-   * 
[[http://lucene.apache.org/solr/api/org/apache/solr/search/FieldQParserPlugin.html|field]]
 - simple field query
+  * 
[[http://lucene.apache.org/solr/api/org/apache/solr/search/FieldQParserPlugin.html|field]]
 - simple field query
-   * 
[[http://lucene.apache.org/solr/api/org/apache/solr/search/PrefixQParserPlugin.html|prefix]]
 - simple prefix query
+  * 
[[http://lucene.apache.org/solr/api/org/apache/solr/search/PrefixQParserPlugin.html|prefix]]
 - simple prefix query
-   * 
[[http://lucene.apache.org/solr/api/org/apache/solr/search/RawQParserPlugin.html|raw]]
 - create a term query from the input value without any text analysis or 
transformation whatsoever. This is useful in debugging, or when raw terms are 
returned from the terms component (this is not the default). also useful for 
debugging, or for avoiding query parser escaping madness when drilling into 
facets on text or string fields via fq parameters. Note: use "term" for this in 
Solr 4.0 or above.  Example: {{{ &fq={!raw f=field_name}crazy+\"field+value }}}
+  * 
[[http://lucene.apache.org/solr/api/org/apache/solr/search/RawQParserPlugin.html|raw]]
 - create a term query from the input value without any text analysis or 
transformation whatsoever. This is useful in debugging, or when raw terms are 
returned from the terms component (this is not the default). also useful for 
debugging, or for avoiding query parser escaping madness when drilling into 
facets on text or string fields via fq parameters. Note: use "term" for this in 
Solr 4.0 or above.  Example: {{{ &fq={!raw f=field_name}crazy+\"field+value }}}
-   * <!> [[Solr4.0]] [[Solr3.2]] 
[[http://lucene.apache.org/solr/api/org/apache/solr/search/TermQParserPlugin.html|term]]
 - term query, useful for avoiding query parser escaping madness when drilling 
into facets via fq parameters.  Example: {{{ &fq={!term f=weight}1.5 }}}
+  * <!> [[Solr4.0]] [[Solr3.2]] 
[[http://lucene.apache.org/solr/api/org/apache/solr/search/TermQParserPlugin.html|term]]
 - term query, useful for avoiding query parser escaping madness when drilling 
into facets via fq parameters.  Example: {{{ &fq={!term f=weight}1.5 }}}
-   * <!> [[Solr4.0]] [[SurroundQueryParser|surround]] - rich !SpanQuery support
+  * <!> [[Solr4.0]] [[SurroundQueryParser|surround]] - rich !SpanQuery support
-   * 
[[http://lucene.apache.org/solr/api/org/apache/solr/search/NestedQParserPlugin.html|query]]
 - nested query parsing
+  * 
[[http://lucene.apache.org/solr/api/org/apache/solr/search/NestedQParserPlugin.html|query]]
 - nested query parsing
  
  See also SolrPlugins for information on writing your own query parser.
  
  <<Anchor(urlescaping)>>
+ 
  = 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.
  
- 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
     
http://localhost:8983/solr/select?q=%2Bpopularity:[10%20TO%20*]%20%2Bsection:0
  }}}
+ = For more information =
+  * See Yonik Seeley's blog on 
[[http://www.lucidimagination.com/blog/2009/03/31/nested-queries-in-solr/|Nested
 Queries in Solr]]
  
- = For more information =
- 
-   * See Yonik Seeley's blog on 
[[http://www.lucidimagination.com/blog/2009/03/31/nested-queries-in-solr/|Nested
 Queries in Solr]]
- 

Reply via email to