Differences between revisions 7 and 8
Revision 7 as of 2011-11-18 17:33:18
Size: 2836
Editor: 108-70-134-51
Comment:
Revision 8 as of 2014-06-17 23:47:16
Size: 727
Editor: 76
Comment: migrated to ef guide
Deletions are marked like this. Additions are marked like this.
Line 1: Line 1:
/!\ EXPERIMENTAL -- Since Solr 4.0 {{{#!wiki important
This page exists for the Solr Community to share Tips, Tricks, and Advice about
[[https://cwiki.apache.org/confluence/display/solr/Transforming+Result+Documents|DocTransformers]].
Line 3: Line 5:
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. Reference material previously located on this page has been migrated to the
[[https://cwiki.apache.org/solr/|Official Solr Ref Guide]].
If you need help, please consult the ref guide for the version of Solr you are using
for the specific details about using [[https://cwiki.apache.org/confluence/display/solr/Transforming+Result+Documents|this feature]].
Line 5: Line 10:
See also: http://wiki.apache.org/solr/CommonQueryParameters#Transformers:

<<TableOfContents>>

== 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" />
If you'd like to share information about how you use this feature, please [[FrontPage#How_to_edit_this_Wiki|add it to this page]].
/* cwikimigrated */
Line 14: Line 13:

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

This page exists for the Solr Community to share Tips, Tricks, and Advice about DocTransformers.

Reference material previously located on this page has been migrated to the Official Solr Ref Guide. If you need help, please consult the ref guide for the version of Solr you are using for the specific details about using this feature.

If you'd like to share information about how you use this feature, please add it to this page.

DocTransformers (last edited 2014-06-17 23:47:16 by 76)