Apache Solr Documentation

6.5 Ref Guide (PDF Download)
Solr Tutorial
Solr Community Wiki

Older Versions of this Guide (PDF)

6.6 Draft Ref Guide Topics

Meta-Documentation

This Unreleased Guide Covers Apache Solr 6.6
As of 5 May 2017, committer editing of this Ref Guide is LOCKED for migration to the new Ref Guide. See SOLR-10290 for details.

Versions Compared

Key

  • This line was added.
  • This line was removed.
  • Formatting was changed.
Comment: Migrated to Confluence 5.3

Parameter Substitution or Macro Expansion is a request templating mechanism that works for search requests across all request parameters, including any JSON body that may be passed via the JSON Request API.

The macro expansion is done at the same point in time that default parameters are applied (i.e. when the request reaches the correct 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:

Code Block
borderColor#666666
borderStylesolid
q=popularity:[ ${low} TO ${high} ]
&low=50
&high=100

One can also specify default values:

Code Block
borderColor#666666
borderStylesolid
q=popularity:[ ${low:0} TO ${high:100} ]
Substitutions can themselves contain further macro expansions:
Code Block
borderColor#666666
borderStylesolid
q=${pop_query}
&pop_query=${pop_field}:[ ${low} TO ${high} ] AND inStock:true
&pop_field=popularity
&low=50
&high=100

If you want to disable macro expansion, simply pass expandMacros=false as a request parameter.

References

This page was adapted from http://yonik.com/solr-query-parameter-substitution/