Custom URP example

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. The plugin to the CassandraDocumentReader transforms the results data from the database to DSE Search.

The DSE custom URP implementation is almost always unnecessary. Instead, DataStax recommends using the field input/output (FIT) transformer API.

Using the API, applications can tweak a search document before it is mapped and indexed according to the index schema.

The field input transformer (FIT) requires a trailing Z for date field values.

Procedure

To use the API:

  1. Configure the custom URP in the solrconfig.xml.

    <dseUpdateRequestProcessorChain name="dse">
     <processor class="com.datastax.bdp.search.solr.functional.DSEUpdateRequestProcessorFactoryExample">
     </processor>
    </dseUpdateRequestProcessorChain>
  2. Write a class to use the custom URP that extends the Solr UpdateRequestProcessor. For example:

    package com.datastax.bdp.search.solr.functional;
    
    import java.io.IOException;
    
    import org.slf4j.Logger;
    import org.slf4j.LoggerFactory;
    
    import com.datastax.bdp.search.solr.handler.update.CassandraAddUpdateCommand;
    import com.datastax.bdp.search.solr.handler.update.CassandraCommitUpdateCommand;
    import org.apache.solr.update.AddUpdateCommand;
    import org.apache.solr.update.CommitUpdateCommand;
    import org.apache.solr.update.processor.UpdateRequestProcessor;
    
    public class TestUpdateRequestProcessor extends UpdateRequestProcessor
    {
        protected final Logger logger = LoggerFactory.getLogger(TestUpdateRequestProcessor.class);
    
        public TestUpdateRequestProcessor(UpdateRequestProcessor next)
        {
            super(next);
        }
    
        public void processAdd(AddUpdateCommand cmd) throws IOException
        {
            if (cmd instanceof CassandraAddUpdateCommand)
            {
                logger.info("Processing Cassandra-actuated document update.");
            }
            else
            {
                logger.info("Processing HTTP-based document update.");
            }
    
            super.processAdd(cmd);
        }
    
        public void processCommit(CommitUpdateCommand cmd) throws IOException
        {
            if (cmd instanceof CassandraCommitUpdateCommand)
            {
                logger.info("Processing DSE-actuated commit.");
            }
            else
            {
                logger.info("Processing client-actuated commit.");
            }
            super.processCommit(cmd);
        }
    }
  3. Export the class to a JAR, and place the JAR in this location:

    • Tarball and Installer-No Services installations: <install-location>/resources/solr/lib

    • Package and Installer-Services installations: /usr/share/dse/solr/lib The JAR is added to the CLASSPATH automatically.

  4. 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);
        }
    }

Was this helpful?

Give Feedback

How can we improve the documentation?

© 2024 DataStax | Privacy policy | Terms of use

Apache, Apache Cassandra, Cassandra, Apache Tomcat, Tomcat, Apache Lucene, Apache Solr, Apache Hadoop, Hadoop, Apache Pulsar, Pulsar, Apache Spark, Spark, Apache TinkerPop, TinkerPop, Apache Kafka and Kafka are either registered trademarks or trademarks of the Apache Software Foundation or its subsidiaries in Canada, the United States and/or other countries. Kubernetes is the registered trademark of the Linux Foundation.

General Inquiries: +1 (650) 389-6000, info@datastax.com