GoetzOnline
GoetzOnline

Reputation: 427

SOLR field fallback behavior

(using solr 4.10.3)

I have a solr schema with three dates:

  1. requiredDate (a required field)

  2. optionalDate (not required)

  3. resolvedDate (populated by #1 or #2)

    Because I need to use ResolvedDate for sorting, it is multiValued="false". I am trying to populate resolvedDate using the behavior; "Use the optional field value if available, else fallback to the required field value". My attempt with:


<copyField source="requiredDate" dest="resolvedDate" />
<copyField source="optionalDate" dest="resolvedDate" />

has failed due to trying to copy multiple values to a single value field.

Can I implement a field with this fallback behavior in either the schema or the UpdateRequestHandler definition? How?

Upvotes: 1

Views: 235

Answers (1)

EricLavault
EricLavault

Reputation: 16035

You can use a StatelessScriptUpdateProcessor (cf. Update Request Processors) which allows the use of scripts to process documents during update requests. Several global variables are provided for each script defined so you can easily perform the operation you want.

You will have to define an UpdateRequestProcessorChain where you can put the script processor definition, and declare the use of your processor chain in your update requestHandler (solrconfig.xml).

Upvotes: 2

Related Questions