2
votes

I use an application that stores data to solr. Unfortunately this one can only write single-values to solr. But some of the data have multiple date-values. So to search them I need them in a multivalue date field.

I already had this problem with some string-values, but solved it by joining the values with an separator (so that it can be transfered as one string) and then using solr.PatternTokenizerFactory.

Thus I tried the same with a multivalued date field, but solr refuses this:

FieldType: TrieDateField does not support specifying an analyzer

Are there any options left to solve this on the solr-side?

tldr: Is there any way to get multivalued dates

2015-07-29T16:50:00Z
2016-04-08T18:15:00Z

out of

2015-07-29T16:50:00Z$2016-04-08T18:15:00Z

Thanks in advance!

[EDIT]

sanjayduttindia was right. It works great! Finally I had to set the arrays values in an iteration..

function processAdd(cmd) {
    doc = cmd.solrDoc;
    id = doc.getFieldValue("id");
    multiDate = doc.getFieldValue("sendebeginn_raw");
    dates = multiDate.split("$");
    dates.forEach(function (item) {
        doc.addField("sendebeginn", item);
    });
    logger.info("UpdateScript processed: "+id);
}
1

1 Answers

3
votes

StatelessScriptUpdateProcessorFactory that enables the use of update processors implemented as scripts during update request.
When Solr update the document then we get the field value in which multiple dates are coming in StatelessScriptUpdateProcessorFactory. We split the value and put into new field.
Lets say multiDate is the string field in which multiple dates are coming and date is multivalued field having tdate as field type.

<field name="multiDate" type="strings"/>
<field name="date" type="tdate" multiValued="true" indexed="true" stored="true"/>

Below is the sample update-script.js.

function processAdd(cmd) {
    doc = cmd.solrDoc;
    multiDate = doc.getFieldValue("multiDate").toString();
    dates = multiDate.split("\\$");
    doc.setField("date",dates);

}
function processDelete(cmd) {
  // no-op
}

function processMergeIndexes(cmd) {
  // no-op
}

function processCommit(cmd) {
  // no-op
}

function processRollback(cmd) {
  // no-op
}

function finish() {
  // no-op
}

Add the StatelessScriptUpdateProcessorFactory processor to the updateRequestProcessorChain in solrconfig.xml.

<processor class="solr.StatelessScriptUpdateProcessorFactory">
   <str name="script">updateProcessor.js</str>
 </processor>

l