Macro Expansion is a new Solr 5.1 feature that does parameter substitution across all request parameters.
The macro expansion is done at the same point in time that default parameters are applied (i.e. when the request reaches the correct solr request handler). This means that request handler defaults, appends, and invariants configured for the handler may reference request parameters, and vice-versa.
Here’s a very simple example of parameterizing a range query in lucene/solr syntax:
q=price:[ ${low} TO ${high} ] &low=100 &high=200
One can also specify default values:
q=price:[ ${low:0} TO ${high:100} ]
Substitutions can themselves contain further macro expansions:
q=${price_query} &price_query=${price_field}:[ ${low} TO ${high} ] AND inStock:true &price_field=specialPrice &low=50 &high=100
Even parameter names can have macro expansion applied. A simple example is faceting on a field to be specified via another parameter ff
:
&facet.field=${ff} &f.${ff}.facet.mincount=1 &f.${ff}.facet.limit=5 &ff=categoryField1
If you want to disable macro expansion, simply pass expandMacros=false
as a request parameter.
We’ll be adding even more powerful macro expansion capabilities in the future, so drop by the solr-user mailing list to join the discussion!
Go to the Download page to try out the current functionality.