Local Params

Local params are arguments in a Solr request that are specific to a query parameter.

Local params provide a way to add meta-data to certain argument types such as query strings. Local params are also sometimes referred to as LocalParams.

Local params are specified as prefixes to arguments. Take the following query argument, for example:

q=solr rocks

We can prefix this query string with local params to provide more information to the Standard Query Parser. For example, we can change the default operator type to "AND" and the default field to "title":

q={!q.op=AND df=title}solr rocks

These local params would change the query to require a match on both "solr" and "rocks" while searching the "title" field by default.

Basic Syntax of Local Params

To specify a local param, insert the following before the argument to be modified:

  • Begin with {!

  • Insert any number of key=value pairs separated by white space

  • End with } and immediately follow with the query argument

You may specify only one local params prefix per argument. Values in the key-value pairs may be quoted via single or double quotes, and backslash escaping works within quoted strings.

Query Type Short Form

If a local param value appears without a name, it is given the implicit name of "type". This allows short-form representation for the type of query parser to use when parsing a query string. Thus:

q={!dismax qf=myfield}solr rocks

is equivalent to:

q={!type=dismax qf=myfield}solr rocks

If no "type" is specified (either explicitly or implicitly) then the Standard Query Parser is used by default. Thus:

fq={!df=summary}solr rocks

is equivalent to:

fq={!type=lucene df=summary}solr rocks

Specifying the Parameter Value with the v Key

A special key of v within local params is an alternate way to specify the value of that parameter.

q={!dismax qf=myfield}solr rocks

is equivalent to

q={!type=dismax qf=myfield v='solr rocks'}

Parameter Dereferencing

Parameter dereferencing, or indirection, lets you use the value of another argument rather than specifying it directly. This can be used to simplify queries, decouple user input from query parameters, or decouple front-end GUI parameters from defaults set in solrconfig.xml.

q={!dismax qf=myfield}solr rocks

is equivalent to:

q={!type=dismax qf=myfield v=$qq}&qq=solr rocks