lucene-solr-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Apache Wiki <wikidi...@apache.org>
Subject [Solr Wiki] Update of "UpdateRequestProcessor" by ryan
Date Sun, 28 Oct 2007 23:20:58 GMT
Dear Wiki user,

You have subscribed to a wiki page or wiki category on "Solr Wiki" for change notification.

The following page has been changed by ryan:
http://wiki.apache.org/solr/UpdateRequestProcessor

------------------------------------------------------------------------------
  <!> ["Solr1.3"]
  
- The [http://lucene.apache.org/solr/api/org/apache/solr/update/processor/UpdateRequestProcessor.html
UpdateRequestProcessor] defines how an update request is processed.  By default, this converts
each request into an !UpdateCommand and sends it to the !UpdateHandler.
+ The [http://lucene.apache.org/solr/api/org/apache/solr/update/processor/UpdateRequestProcessor.html
UpdateRequestProcessor] defines how an update request is processed.  By default, this converts
each request into an !UpdateCommand and sends it to the !UpdateHandler.  (see [https://issues.apache.org/jira/browse/SOLR-269
SOLR-269])
  
  /!\ Before 1.3 is released, we should make sure this is something we want to live with publicly.
 It exposes the !UpdateCommand family in a way I don't think it was designed for.
  
  
- == Configuring !UpdateRequestProcessors ==
+ == Configuring UpdateRequestProcessors ==
  
- solrconfig.xml will load !UpdateRequestProcessor 
+ solrconfig.xml will load a UpdateRequestProcessors
  
- {{{
-   TODO show config
+ {{{          
+  <updateRequestProcessor>                                               
+    <factory name="standard" class="solr.ChainedUpdateProcessorFactory" default="true"
>
+      <chain class="org.apache.solr.ConditionalCopyProcessorFactory" />           
                        
+      <chain class="solr.RunUpdateProcessorFactory" />                    
+      <chain class="solr.LogUpdateProcessorFactory" />                   
+    </factory>                                                           
+  </updateRequestProcessor>
  }}}
  
  
  
  == Implementing a conditional copyField ==
  
- TODO, show simple example
+ Here is a quick example that adds the 'cat' 'popular' if the value of 'popularity' is >
5
  
+ {{{
+ package my.solr;
+ 
+ import java.io.IOException;
+ 
+ import org.apache.solr.common.SolrInputDocument;
+ import org.apache.solr.request.SolrQueryRequest;
+ import org.apache.solr.request.SolrQueryResponse;
+ import org.apache.solr.update.AddUpdateCommand;
+ import org.apache.solr.update.processor.NoOpUpdateProcessor;
+ import org.apache.solr.update.processor.UpdateRequestProcessor;
+ import org.apache.solr.update.processor.UpdateRequestProcessorFactory;
+ 
+ public class ConditionalCopyProcessorFactory extends UpdateRequestProcessorFactory 
+ {
+   @Override
+   public UpdateRequestProcessor getInstance(SolrQueryRequest req, SolrQueryResponse rsp,
UpdateRequestProcessor next) 
+   {
+     return new ConditionalCopyProcessor(next);
+   }
+ }
+ 
+ class ConditionalCopyProcessor extends NoOpUpdateProcessor 
+ {
+   public ConditionalCopyProcessor( UpdateRequestProcessor next) {
+     super( next );
+   }
+   
+   @Override
+   public void processAdd(AddUpdateCommand cmd) throws IOException {
+     SolrInputDocument doc = cmd.getSolrInputDocument();
+     
+     Object v = doc.getFieldValue( "popularity" );
+     if( v != null ) {
+       int pop = Integer.parseInt( v.toString() );
+       if( pop > 5 ) {
+         doc.addField( "cat", "popular" );
+       }
+     }
+     
+     // pass it up the chain
+     super.processAdd(cmd);
+   }
+ }
+ 
+ }}}
+ 

Mime
View raw message