Use the custom update request processor (URP) to extend the Solr URP.
DSE Search includes the released version of a plugin API for
Solr updates and a plugin to the CassandraDocumentReader. The plugin API transforms
data from the secondary indexing API before data is submitted to Solr. The plugin to
the CassandraDocumentReader transforms the results data from Cassandra to Solr.
Using the API, applications can tweak a Solr Document before it is mapped and indexed
according to the schema.xml file. The API is a counterpart to
the input/output transformer support in Solr.
The field input transformer (FIT) requires a trailing Z for date field values.
Procedure
To use the API:
-
Configure the custom URP in the solrconfig.xml.
<dseUpdateRequestProcessorChain name="dse">
<processor class="com.datastax.bdp.search.solr.functional.DSEUpdateRequestProcessorFactoryExample">
</processor>
</dseUpdateRequestProcessorChain>
-
Write a class to use the custom URP that extends the Solr UpdateRequestProcessor. For
example:
package com.datastax.bdp.search.solr.functional;
import com.datastax.bdp.search.solr.handler.update.CassandraAddUpdateCommand;
import com.datastax.bdp.search.solr.handler.update.CassandraCommitUpdateCommand;
import com.datastax.bdp.search.solr.handler.update.CassandraDeleteUpdateCommand;
import java.io.IOException;
import org.apache.solr.update.AddUpdateCommand;
import org.apache.solr.update.CommitUpdateCommand;
import org.apache.solr.update.DeleteUpdateCommand;
import org.apache.solr.update.MergeIndexesCommand;
import org.apache.solr.update.processor.UpdateRequestProcessor;
public class TestUpdateRequestProcessor extends UpdateRequestProcessor
{
public boolean cprocessAdd = false;
public boolean processAdd = false;
public boolean cprocessDelete = false;
public boolean processDelete = false;
public boolean cprocessCommit = false;
public boolean processCommit = false;
public TestUpdateRequestProcessor(UpdateRequestProcessor next)
{
super(next);
}
public void processAdd(AddUpdateCommand cmd) throws IOException
{
if (cmd instanceof CassandraAddUpdateCommand)
{
cprocessAdd = true;
}
else
{
processAdd = true;
}
super.processAdd(cmd);
}
public void processDelete(DeleteUpdateCommand cmd) throws IOException
{
if (cmd instanceof CassandraDeleteUpdateCommand)
{
cprocessDelete = true;
}
else
{
processDelete = true;
}
super.processDelete(cmd);
}
public void processMergeIndexes(MergeIndexesCommand cmd) throws IOException
{
super.processMergeIndexes(cmd);
}
public void processCommit(CommitUpdateCommand cmd) throws IOException
{
if (cmd instanceof CassandraCommitUpdateCommand)
{
cprocessCommit = true;
}
else
{
processCommit = true;
}
super.processCommit(cmd);
}
}
-
Export the class to a JAR, and place the JAR in this location:
- Installer-No Services and Tarball installations: install-location/resources/solr/lib
- Installer-Services and Package installations: /usr/share/dse/solr/lib
The JAR is added to the CLASSPATH automatically.
-
Test your implementation. For example:
package com.datastax.bdp.search.solr.functional;
import com.datastax.bdp.search.solr.handler.update.DSEUpdateProcessorFactory;
import org.apache.solr.core.SolrCore;
import org.apache.solr.update.processor.UpdateRequestProcessor;
public class DSEUpdateRequestProcessorFactoryExample extends DSEUpdateProcessorFactory
{
SolrCore core;
public DSEUpdateRequestProcessorFactoryExample(SolrCore core) {
this.core = core;
}
public UpdateRequestProcessor getInstance(
UpdateRequestProcessor next)
{
return new TestUpdateRequestProcessor(next);
}
}