Differences between revisions 8 and 9
Revision 8 as of 2009-10-14 16:15:57
Size: 2301
Editor: YonikSeeley
Comment: simplify+correct explanation
Revision 9 as of 2013-02-23 00:33:24
Size: 2326
Editor: HossMan
Comment: TOC
Deletions are marked like this. Additions are marked like this.
Line 2: Line 2:

<<TableOfContents>>

LocalParams

LocalParams stands for local parameters: they provide a way to "localize" information about a specific argument that is being sent to Solr. In other words, LocalParams provide a way to add meta-data to certain argument types such as query strings.

LocalParams are expressed as prefixes to arguments to be sent to Solr. For example:

Assume we have the existing query parameter

  • q=solr rocks

We can prefix this query string with LocalParams to provide more information to the query parser, for example changing the default operator type to "AND" and the default field to "title" for the lucene query parser:

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

Basic Syntax

To indicate a LocalParam, the argument is prefixed with curly braces whose contents begin with an exclamation point and include any number of key=value pairs separated by whitespace. So if the original argument is foo, applying LocalParams would look something like {!k1=v1 k2=v2 k3=v3}foo.

There may only be one LocalParams prefix per argument, preventing the need for any escaping of the original argument. Values in the key-value pairs may be quoted via single or double quotes, and backslash escaping works within quoted strings.

Example:

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

Query type short-form

If a LocalParams 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

Parameter value

A special key of "v" within local parameters 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 allows one to 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

LocalParams (last edited 2013-02-23 00:33:24 by HossMan)