/!\ EXPERIMENTAL -- Since Solr 4.0

Document Transformers give you a way to modify fields that are returned to the user. For instance, you can use them to include the results of a FunctionQuery or to mark items that have been editorially boosted by the QueryElevationComponent.

See also: http://wiki.apache.org/solr/CommonQueryParameters#Transformers:

Configuring

You can add a DocTransformer to your application by configuring it in the solrconfig.xml, as in:

<transformer name="elevated" class="org.apache.solr.response.transform.EditorialMarkerFactory" />

This will add an instance of the EditorialMarkerFactory (used to mark items that have been editorially boosted by the QueryElevationComponent so that an application has the option of treating them specially) to the system.

Just like other components, you can initialize DocTransformers:

<transformer name="mytrans3" class="org.apache.solr.response.transform.ValueAugmenterFactory" >
  <double name="defaultValue">5</double>
</transformer>

See the example solrconfig.xml for other examples of adding transformers.

Invoking

To add a transformed field to your results, pass in the name of the configured transformer as a field name, enclosed in brackets in the &fl field list, as in

...&fl=id,score,[elevated]

In this case, assuming our configuration from above, the EditorialMarkerFactory will be invoked and a new field will be added to the document with the name elevated and a value of true for any document that was editorially boosted.

You can also pass run time specific values by adding them as attributes inside of the brackets, as in:

...&fl=id,score,[myTransformer foo=1 bar=good]

<!> TODO: Example of using functions <!>

Standard Transformers

By default some transformers are enabled:

[explain]

Add explain info to the document.

can use [explain style=nl], [explain style=text], [explain style=html]

To configured the default value use:

<transformer name="explain" class="org.apache.solr.response.transform.ExplainAugmenterFactory" >
  <str name="args">nl</str>
</transformer>

[value]

Add a constant value to a document. For example:

[value v=hello]

[value v=10 t=int]

this can also be configured in the solrconfig.xml with default values. like:

<transformer name="mytrans2" class="org.apache.solr.response.transform.ValueAugmenterFactory" >
  <int name="value">5</int>
</transformer>
<transformer name="mytrans3" class="org.apache.solr.response.transform.ValueAugmenterFactory" >
  <double name="defaultValue">5</double>
</transformer>

[shard]

will add the shard to the request

[docid]

Add the internal docid to the request

DocTransformers (last edited 2011-11-18 17:33:18 by GrantIngersoll)