You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@lucene.apache.org by sh...@apache.org on 2014/07/29 18:47:01 UTC

svn commit: r1614417 - in /lucene/dev/branches/branch_4x: ./ solr/ solr/core/ solr/core/src/java/org/apache/solr/update/processor/ solr/core/src/test-files/solr/collection1/conf/ solr/core/src/test/org/apache/solr/update/processor/ solr/example/ solr/e...

Author: shalin
Date: Tue Jul 29 16:47:00 2014
New Revision: 1614417

URL: http://svn.apache.org/r1614417
Log:
SOLR-6020: Auto-generate a unique key in schema-less example if data does not have an id field

Added:
    lucene/dev/branches/branch_4x/solr/core/src/test/org/apache/solr/update/processor/UUIDUpdateProcessorFallbackTest.java
      - copied unchanged from r1614416, lucene/dev/trunk/solr/core/src/test/org/apache/solr/update/processor/UUIDUpdateProcessorFallbackTest.java
Modified:
    lucene/dev/branches/branch_4x/   (props changed)
    lucene/dev/branches/branch_4x/solr/   (props changed)
    lucene/dev/branches/branch_4x/solr/CHANGES.txt   (contents, props changed)
    lucene/dev/branches/branch_4x/solr/core/   (props changed)
    lucene/dev/branches/branch_4x/solr/core/src/java/org/apache/solr/update/processor/AbstractDefaultValueUpdateProcessorFactory.java
    lucene/dev/branches/branch_4x/solr/core/src/java/org/apache/solr/update/processor/UUIDUpdateProcessorFactory.java
    lucene/dev/branches/branch_4x/solr/core/src/test-files/solr/collection1/conf/solrconfig-update-processor-chains.xml
    lucene/dev/branches/branch_4x/solr/example/   (props changed)
    lucene/dev/branches/branch_4x/solr/example/example-schemaless/solr/collection1/conf/solrconfig.xml

Modified: lucene/dev/branches/branch_4x/solr/CHANGES.txt
URL: http://svn.apache.org/viewvc/lucene/dev/branches/branch_4x/solr/CHANGES.txt?rev=1614417&r1=1614416&r2=1614417&view=diff
==============================================================================
--- lucene/dev/branches/branch_4x/solr/CHANGES.txt (original)
+++ lucene/dev/branches/branch_4x/solr/CHANGES.txt Tue Jul 29 16:47:00 2014
@@ -94,6 +94,11 @@ New Features
 * SOLR-6267: Let user override Interval Faceting key with LocalParams (Tomas Fernandez_Lobbe
   via Erick Erickson)
 
+* SOLR-6020: Auto-generate a unique key in schema-less example if data does not have an id field.
+  The UUIDUpdateProcessor was improved to not require a field name in configuration and generate
+  a UUID into the unique Key field.
+  (Vitaliy Zhovtyuk, hossman, Steve Rowe, Erik Hatcher, shalin)
+
 
 Bug Fixes
 ----------------------

Modified: lucene/dev/branches/branch_4x/solr/core/src/java/org/apache/solr/update/processor/AbstractDefaultValueUpdateProcessorFactory.java
URL: http://svn.apache.org/viewvc/lucene/dev/branches/branch_4x/solr/core/src/java/org/apache/solr/update/processor/AbstractDefaultValueUpdateProcessorFactory.java?rev=1614417&r1=1614416&r2=1614417&view=diff
==============================================================================
--- lucene/dev/branches/branch_4x/solr/core/src/java/org/apache/solr/update/processor/AbstractDefaultValueUpdateProcessorFactory.java (original)
+++ lucene/dev/branches/branch_4x/solr/core/src/java/org/apache/solr/update/processor/AbstractDefaultValueUpdateProcessorFactory.java Tue Jul 29 16:47:00 2014
@@ -72,7 +72,7 @@ public abstract class AbstractDefaultVal
    * to any document which does not already have a value in 
    * <code>fieldName</code>
    */
-  protected static abstract class DefaultValueUpdateProcessor 
+  static abstract class DefaultValueUpdateProcessor
     extends UpdateRequestProcessor {
 
     final String fieldName;

Modified: lucene/dev/branches/branch_4x/solr/core/src/java/org/apache/solr/update/processor/UUIDUpdateProcessorFactory.java
URL: http://svn.apache.org/viewvc/lucene/dev/branches/branch_4x/solr/core/src/java/org/apache/solr/update/processor/UUIDUpdateProcessorFactory.java?rev=1614417&r1=1614416&r2=1614417&view=diff
==============================================================================
--- lucene/dev/branches/branch_4x/solr/core/src/java/org/apache/solr/update/processor/UUIDUpdateProcessorFactory.java (original)
+++ lucene/dev/branches/branch_4x/solr/core/src/java/org/apache/solr/update/processor/UUIDUpdateProcessorFactory.java Tue Jul 29 16:47:00 2014
@@ -17,29 +17,28 @@
 
 package org.apache.solr.update.processor;
 
-import java.io.IOException;
 import java.util.UUID;
 import java.util.Locale;
 
+import org.apache.commons.lang.StringUtils;
 import org.apache.solr.common.SolrException;
 import static org.apache.solr.common.SolrException.ErrorCode.*;
-import org.apache.solr.common.SolrInputDocument;
 import org.apache.solr.common.util.NamedList;
 import org.apache.solr.request.SolrQueryRequest;
 import org.apache.solr.response.SolrQueryResponse;
-import org.apache.solr.update.AddUpdateCommand;
+import org.apache.solr.schema.SchemaField;
 
 
 /**
  * <p>
- * An update processor that adds a newly generated <code>UUID</code> value 
- * to any document being added that does not already have a value in the 
+ * An update processor that adds a newly generated <code>UUID</code> value
+ * to any document being added that does not already have a value in the
  * specified field.
  * </p>
  *
  * <p>
- * In the example configuration below, if a document does not contain a value 
- * in the <code>id</code> field, a new <code>UUID</code> will be generated 
+ * In the example configuration below, if a document does not contain a value
+ * in the <code>id</code> field, a new <code>UUID</code> will be generated
  * and added as the value of that field.
  * <p>
  *
@@ -48,19 +47,46 @@ import org.apache.solr.update.AddUpdateC
  *   &lt;str name="fieldName"&gt;id&lt;/str&gt;
  * &lt;/processor&gt;
  * </pre>
- * 
+ *
+ * <p>
+ * If field name is omitted in processor configuration,
+ * then  @{link org.apache.solr.schema.IndexSchema#getUniqueKeyField()}</code>
+ * is used as field and a new <code>UUID</code> will be generated
+ * and added as the value of that field. The field type of the uniqueKeyField
+ * must be anything which accepts a string or UUID value.
+ * <p>
  * @see UUID
  */
-public class UUIDUpdateProcessorFactory
-  extends AbstractDefaultValueUpdateProcessorFactory {
+public class UUIDUpdateProcessorFactory extends UpdateRequestProcessorFactory {
+
+  protected String fieldName = null;
 
-  @Override
-  public UpdateRequestProcessor getInstance(SolrQueryRequest req, 
-                                            SolrQueryResponse rsp, 
+  @SuppressWarnings("unchecked")
+  public void init(NamedList args) {
+
+    Object obj = args.remove("fieldName");
+    if (null != obj) {
+      fieldName = obj.toString();
+    }
+
+    if (0 < args.size()) {
+      throw new SolrException(SERVER_ERROR,
+          "Unexpected init param(s): '" +
+              args.getName(0) + "'");
+    }
+  }
+
+  public UpdateRequestProcessor getInstance(SolrQueryRequest req,
+                                            SolrQueryResponse rsp,
                                             UpdateRequestProcessor next ) {
-    return new DefaultValueUpdateProcessor(fieldName, next) {
+    if (StringUtils.isEmpty(fieldName)) {
+      SchemaField schemaField = req.getSchema().getUniqueKeyField();
+      fieldName = schemaField.getName();
+    }
+
+    return new AbstractDefaultValueUpdateProcessorFactory.DefaultValueUpdateProcessor(fieldName, next) {
       @Override
-      public Object getDefaultValue() { 
+      public Object getDefaultValue() {
         return UUID.randomUUID().toString().toLowerCase(Locale.ROOT);
       }
     };

Modified: lucene/dev/branches/branch_4x/solr/core/src/test-files/solr/collection1/conf/solrconfig-update-processor-chains.xml
URL: http://svn.apache.org/viewvc/lucene/dev/branches/branch_4x/solr/core/src/test-files/solr/collection1/conf/solrconfig-update-processor-chains.xml?rev=1614417&r1=1614416&r2=1614417&view=diff
==============================================================================
--- lucene/dev/branches/branch_4x/solr/core/src/test-files/solr/collection1/conf/solrconfig-update-processor-chains.xml (original)
+++ lucene/dev/branches/branch_4x/solr/core/src/test-files/solr/collection1/conf/solrconfig-update-processor-chains.xml Tue Jul 29 16:47:00 2014
@@ -468,6 +468,18 @@
     </processor>
   </updateRequestProcessorChain>
 
+
+  <updateRequestProcessorChain name="default-values-fallback-to-unique">
+    <processor class="solr.UUIDUpdateProcessorFactory">
+      <str name="fieldName">id</str>
+    </processor>
+  </updateRequestProcessorChain>
+
+  <updateRequestProcessorChain name="default-values-fallback-to-unique-automatically">
+    <processor class="solr.UUIDUpdateProcessorFactory">
+    </processor>
+  </updateRequestProcessorChain>
+
   <updateRequestProcessorChain name="uniq-values">
     <processor class="solr.UniqFieldsUpdateProcessorFactory">
       <str name="fieldRegex">uniq_.*</str>

Modified: lucene/dev/branches/branch_4x/solr/example/example-schemaless/solr/collection1/conf/solrconfig.xml
URL: http://svn.apache.org/viewvc/lucene/dev/branches/branch_4x/solr/example/example-schemaless/solr/collection1/conf/solrconfig.xml?rev=1614417&r1=1614416&r2=1614417&view=diff
==============================================================================
--- lucene/dev/branches/branch_4x/solr/example/example-schemaless/solr/collection1/conf/solrconfig.xml (original)
+++ lucene/dev/branches/branch_4x/solr/example/example-schemaless/solr/collection1/conf/solrconfig.xml Tue Jul 29 16:47:00 2014
@@ -1563,6 +1563,9 @@
        See http://wiki.apache.org/solr/GuessingFieldTypes
     -->
   <updateRequestProcessorChain name="add-unknown-fields-to-the-schema">
+    <!-- UUIDUpdateProcessorFactory will generate an id if none is present in the incoming document -->
+    <processor class="solr.UUIDUpdateProcessorFactory" />
+
     <processor class="solr.LogUpdateProcessorFactory"/>
     <processor class="solr.DistributedUpdateProcessorFactory"/>
     <processor class="solr.RemoveBlankFieldUpdateProcessorFactory"/>