You are viewing a plain text version of this content. The canonical link for it is here.
Posted to solr-commits@lucene.apache.org by Apache Wiki <wi...@apache.org> on 2009/09/23 23:54:43 UTC

[Solr Wiki] Update of "LocalParams" by naomidushay

Dear Wiki user,

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

The "LocalParams" page has been changed by naomidushay:
http://wiki.apache.org/solr/LocalParams?action=diff&rev1=6&rev2=7

  = LocalParams =
- LocalParams stands for local parameters... arguments in a Solr request that are localized and specific to a parameter.  They provide a way to add meta-data to certain argument types such as query strings.
+ 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.
  
- If localparams exist as prefixes to arguments.
+ LocalParams are expressed as prefixes to arguments to be sent to Solr.  For example:
+ 
- Assuming we have the existing query parameter
+ Assume we have the existing query parameter
- {{{q=solr rocks
+  `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.
+ 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
+  `q={!q.op=AND df=title}solr rocks`
- }}}
  
  === Basic Syntax ===
- An argument with localparams starts with {{{ {! }}}, includes any number of {{{key=value}}} pairs separated by whitespace, and the localparams end with {{{ } }}} followed by the original argument value.  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.
+ 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.
+ 
+  `q={!type=dismax qf='myfield yourfield'}solr rocks` 
+ is equivalent to 
+  `q={!type=dismax qf="myfield yourfield"}solr rocks`
+ but 
+  `q={!type=dismax qf=myfield yourfield}solr rocks`
+ will give an error because "yourfield" is expected to be a key=value pair.
+ 
+ example of backslash escaping:
+  `q={!type=dismax qf="title"}2 \+ 2`
  
  === Query type short-form ===
- If a localparam 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 
+ 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
+  `q={!dismax qf=myfield}solr rocks`
- }}} is equivalent to 
+ is equivalent to 
- {{{q={!type=dismax qf=myfield}solr rocks
+  `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
+  `q={!dismax qf=myfield}solr rocks`
- }}} is equivalent to 
+ is equivalent to 
- {{{q={!type=dismax qf=myfield v='solr rocks'}
+  `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
+  `q={!dismax qf=myfield}solr rocks`
- }}} is equivalent to 
+ is equivalent to 
- {{{q={!type=dismax qf=myfield v=$qq}&qq=solr rocks
+  `q={!type=dismax qf=myfield v=$qq}&qq=solr rocks`
- }}}
  

Re: [Solr Wiki] Update of "LocalParams" by naomidushay

Posted by Yonik Seeley <yo...@lucidimagination.com>.
On Wed, Sep 23, 2009 at 5:54 PM, Apache Wiki <wi...@apache.org> wrote:
> +  `q={!type=dismax qf=myfield yourfield}solr rocks`
> + will give an error because "yourfield" is expected to be a key=value pair.

This doesn't give an error for the reason you think it does :-)
A single word like this is shorthand for type=yourfield... so
q={!type=dismax qf=myfield lucene}solr rocks
would not throw an error and parse to a lucene query.
This shorthand notation is what allows
{!dismax} to mean the same thing as {!type=dismax}
It's undocumented that it actually works if it's not the first
param... perhaps we should limit that in the future.

> + example of backslash escaping:
> +  `q={!type=dismax qf="title"}2 \+ 2`

This isn't an example of local params backslash escaping.
There is no escaping at all in the value (that's considered a feature).

-Yonik
http://www.lucidimagination.com


>  === Query type short-form ===
> - If a localparam 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
> + 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
> +  `q={!dismax qf=myfield}solr rocks`
> - }}} is equivalent to
> + is equivalent to
> - {{{q={!type=dismax qf=myfield}solr rocks
> +  `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
> +  `q={!dismax qf=myfield}solr rocks`
> - }}} is equivalent to
> + is equivalent to
> - {{{q={!type=dismax qf=myfield v='solr rocks'}
> +  `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
> +  `q={!dismax qf=myfield}solr rocks`
> - }}} is equivalent to
> + is equivalent to
> - {{{q={!type=dismax qf=myfield v=$qq}&qq=solr rocks
> +  `q={!type=dismax qf=myfield v=$qq}&qq=solr rocks`
> - }}}
>
>