Interface TransformerFactory.FieldRenamer
- All Known Implementing Classes:
GeoTransformerFactory,RawValueTransformerFactory
- Enclosing class:
TransformerFactory
TransformerFactory.FieldRenamer interface should be implemented by any TransformerFactory
capable of generating transformers that might rename fields, and should implement create(String, SolrParams, SolrQueryRequest, Map, Set) in place of TransformerFactory.create(String, SolrParams, SolrQueryRequest) (with the latter method overridden to throw UnsupportedOperationException).
DocTransformers returned via create(String, SolrParams, SolrQueryRequest, Map, Set) will be added in a second pass, allowing simplified logic in TransformerFactory.create(String, SolrParams, SolrQueryRequest) for non-renaming factories.
create(String, SolrParams, SolrQueryRequest, Map, Set) must implement extra logic
to be aware of preceding field renames, and to make subsequent TransformerFactory.FieldRenamer
transformers aware of its own field renames.
It is harmless for a DocTransformer that does _not_ in practice rename fields to be
returned from a factory that implements this interface (e.g., for conditional renames?); but
doing so opens the possibility of create(String, SolrParams, SolrQueryRequest, Map, Set) being called _after_ fields have been renamed, so such implementations must still check
whether the field with which they are concerned has been renamed ... and if it _has_, must copy
the field back to its original name. This situation also demonstrates the motivation for
separating the creation of DocTransformers into two phases: an initial phase involving
no field renames, and a subsequent phase that implement extra logic to properly handle field
renames.
-
Method Summary
Modifier and TypeMethodDescriptioncreate(String field, org.apache.solr.common.params.SolrParams params, SolrQueryRequest req, Map<String, String> renamedFields, Set<String> reqFieldNames) Analogous toTransformerFactory.create(String, SolrParams, SolrQueryRequest), but to be implemented byTransformerFactorys that produceDocTransformers that may rename fields.default booleanReturnstrueif implementations of this class may (even subtly) modify field values.
-
Method Details
-
create
DocTransformer create(String field, org.apache.solr.common.params.SolrParams params, SolrQueryRequest req, Map<String, String> renamedFields, Set<String> reqFieldNames) Analogous toTransformerFactory.create(String, SolrParams, SolrQueryRequest), but to be implemented byTransformerFactorys that produceDocTransformers that may rename fields.- Parameters:
field- The destination fieldparams- Local params associated with this transformer (e.g., source field)req- The current requestrenamedFields- Maps source=>dest renamed fields. Implementations should check this first, updating their own "source" field(s) as necessary, and if renaming (not copying) fields, should also update this map with the implementations "own" introduced source=>dest field mappingreqFieldNames- Set of explicitly requested field names; implementations should consult this set to determine whether it's appropriate to rename (vs. copy) a field (e.g.:boolean copy = reqFieldNames != null && reqFieldNames.contains(sourceField))- Returns:
- A transformer to be used in processing field values in returned documents.
-
mayModifyValue
default boolean mayModifyValue()Returnstrueif implementations of this class may (even subtly) modify field values. (GeoTransformerFactorymay do this, e.g.). To fail safe, the default implementation returnstrue. This method should be overridden to returnfalseif the implementing class is guaranteed to not modify any values for the fields that it renames.
-