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

svn commit: r1498561 - in /lucene/dev/branches/branch_4x: ./ solr/ solr/core/ solr/core/src/java/org/apache/solr/request/ solr/core/src/java/org/apache/solr/schema/ solr/core/src/java/org/apache/solr/update/processor/ solr/core/src/test-files/solr/coll...

Author: sarowe
Date: Mon Jul  1 16:47:37 2013
New Revision: 1498561

URL: http://svn.apache.org/r1498561
Log:
SOLR-4894: Add AddSchemaFieldsUpdateProcessorFactory: dynamically add fields to the schema if an input document contains unknown fields (merged trunk r1498555)

Added:
    lucene/dev/branches/branch_4x/solr/core/src/java/org/apache/solr/update/processor/AddSchemaFieldsUpdateProcessorFactory.java
      - copied unchanged from r1498555, lucene/dev/trunk/solr/core/src/java/org/apache/solr/update/processor/AddSchemaFieldsUpdateProcessorFactory.java
    lucene/dev/branches/branch_4x/solr/core/src/test-files/solr/collection1/conf/schema-add-schema-fields-update-processor.xml
      - copied unchanged from r1498555, lucene/dev/trunk/solr/core/src/test-files/solr/collection1/conf/schema-add-schema-fields-update-processor.xml
    lucene/dev/branches/branch_4x/solr/core/src/test-files/solr/collection1/conf/solrconfig-add-schema-fields-update-processor-chains.xml
      - copied unchanged from r1498555, lucene/dev/trunk/solr/core/src/test-files/solr/collection1/conf/solrconfig-add-schema-fields-update-processor-chains.xml
    lucene/dev/branches/branch_4x/solr/core/src/test/org/apache/solr/update/processor/AddSchemaFieldsUpdateProcessorFactoryTest.java
      - copied unchanged from r1498555, lucene/dev/trunk/solr/core/src/test/org/apache/solr/update/processor/AddSchemaFieldsUpdateProcessorFactoryTest.java
Modified:
    lucene/dev/branches/branch_4x/   (props changed)
    lucene/dev/branches/branch_4x/solr/   (props changed)
    lucene/dev/branches/branch_4x/solr/core/   (props changed)
    lucene/dev/branches/branch_4x/solr/core/src/java/org/apache/solr/request/SolrQueryRequest.java
    lucene/dev/branches/branch_4x/solr/core/src/java/org/apache/solr/request/SolrQueryRequestBase.java
    lucene/dev/branches/branch_4x/solr/core/src/java/org/apache/solr/schema/ManagedIndexSchema.java
    lucene/dev/branches/branch_4x/solr/core/src/java/org/apache/solr/update/processor/FieldMutatingUpdateProcessorFactory.java

Modified: lucene/dev/branches/branch_4x/solr/core/src/java/org/apache/solr/request/SolrQueryRequest.java
URL: http://svn.apache.org/viewvc/lucene/dev/branches/branch_4x/solr/core/src/java/org/apache/solr/request/SolrQueryRequest.java?rev=1498561&r1=1498560&r2=1498561&view=diff
==============================================================================
--- lucene/dev/branches/branch_4x/solr/core/src/java/org/apache/solr/request/SolrQueryRequest.java (original)
+++ lucene/dev/branches/branch_4x/solr/core/src/java/org/apache/solr/request/SolrQueryRequest.java Mon Jul  1 16:47:37 2013
@@ -73,6 +73,9 @@ public interface SolrQueryRequest {
 
   /** The schema snapshot from core.getLatestSchema() at request creation. */
   public IndexSchema getSchema();
+  
+  /** Replaces the current schema snapshot with the latest from the core. */
+  public void updateSchemaToLatest();
 
   /**
    * Returns a string representing all the important parameters.

Modified: lucene/dev/branches/branch_4x/solr/core/src/java/org/apache/solr/request/SolrQueryRequestBase.java
URL: http://svn.apache.org/viewvc/lucene/dev/branches/branch_4x/solr/core/src/java/org/apache/solr/request/SolrQueryRequestBase.java?rev=1498561&r1=1498560&r2=1498561&view=diff
==============================================================================
--- lucene/dev/branches/branch_4x/solr/core/src/java/org/apache/solr/request/SolrQueryRequestBase.java (original)
+++ lucene/dev/branches/branch_4x/solr/core/src/java/org/apache/solr/request/SolrQueryRequestBase.java Mon Jul  1 16:47:37 2013
@@ -42,8 +42,8 @@ import java.util.HashMap;
  */
 public abstract class SolrQueryRequestBase implements SolrQueryRequest {
   protected final SolrCore core;
-  protected final IndexSchema schema;
   protected final SolrParams origParams;
+  protected volatile IndexSchema schema;
   protected SolrParams params;
   protected Map<Object,Object> context;
   protected Iterable<ContentStream> streams;
@@ -112,6 +112,11 @@ public abstract class SolrQueryRequestBa
     return schema;
   }
 
+  @Override
+  public void updateSchemaToLatest() {
+    schema = core.getLatestSchema();
+  }
+
   /**
    * Frees resources associated with this request, this method <b>must</b>
    * be called when the object is no longer in use.

Modified: lucene/dev/branches/branch_4x/solr/core/src/java/org/apache/solr/schema/ManagedIndexSchema.java
URL: http://svn.apache.org/viewvc/lucene/dev/branches/branch_4x/solr/core/src/java/org/apache/solr/schema/ManagedIndexSchema.java?rev=1498561&r1=1498560&r2=1498561&view=diff
==============================================================================
--- lucene/dev/branches/branch_4x/solr/core/src/java/org/apache/solr/schema/ManagedIndexSchema.java (original)
+++ lucene/dev/branches/branch_4x/solr/core/src/java/org/apache/solr/schema/ManagedIndexSchema.java Mon Jul  1 16:47:37 2013
@@ -169,6 +169,12 @@ public final class ManagedIndexSchema ex
     return addFields(Arrays.asList(newField));
   }
 
+  public class FieldExistsException extends SolrException {
+    public FieldExistsException(ErrorCode code, String msg) {
+      super(code, msg);
+    }
+  }
+  
   @Override
   public ManagedIndexSchema addFields(Collection<SchemaField> newFields) {
     ManagedIndexSchema newSchema = null;
@@ -183,7 +189,7 @@ public final class ManagedIndexSchema ex
           for (SchemaField newField : newFields) {
             if (null != newSchema.getFieldOrNull(newField.getName())) {
               String msg = "Field '" + newField.getName() + "' already exists.";
-              throw new SolrException(ErrorCode.BAD_REQUEST, msg);
+              throw new FieldExistsException(ErrorCode.BAD_REQUEST, msg);
             }
             newSchema.fields.put(newField.getName(), newField);
 

Modified: lucene/dev/branches/branch_4x/solr/core/src/java/org/apache/solr/update/processor/FieldMutatingUpdateProcessorFactory.java
URL: http://svn.apache.org/viewvc/lucene/dev/branches/branch_4x/solr/core/src/java/org/apache/solr/update/processor/FieldMutatingUpdateProcessorFactory.java?rev=1498561&r1=1498560&r2=1498561&view=diff
==============================================================================
--- lucene/dev/branches/branch_4x/solr/core/src/java/org/apache/solr/update/processor/FieldMutatingUpdateProcessorFactory.java (original)
+++ lucene/dev/branches/branch_4x/solr/core/src/java/org/apache/solr/update/processor/FieldMutatingUpdateProcessorFactory.java Mon Jul  1 16:47:37 2013
@@ -165,41 +165,47 @@ public abstract class FieldMutatingUpdat
     
     return params;
   }
-                                                            
-
-  /**
-   * Handles common initialization related to source fields for 
-   * constructing the FieldNameSelector to be used.
-   *
-   * Will error if any unexpected init args are found, so subclasses should
-   * remove any subclass-specific init args before calling this method.
-   */
-  @SuppressWarnings("unchecked")
-  @Override
-  public void init(NamedList args) {
-
-    inclusions = parseSelectorParams(args);
-
+                               
+  public static Collection<SelectorParams> parseSelectorExclusionParams(NamedList args) {
+    Collection<SelectorParams> exclusions = new ArrayList<SelectorParams>();
     List<Object> excList = args.getAll("exclude");
     for (Object excObj : excList) {
       if (null == excObj) {
         throw new SolrException
-          (SERVER_ERROR, "'exclude' init param can not be null"); 
+            (SERVER_ERROR, "'exclude' init param can not be null");
       }
       if (! (excObj instanceof NamedList) ) {
         throw new SolrException
-          (SERVER_ERROR, "'exclude' init param must be <lst/>"); 
+            (SERVER_ERROR, "'exclude' init param must be <lst/>");
       }
       NamedList exc = (NamedList) excObj;
       exclusions.add(parseSelectorParams(exc));
       if (0 < exc.size()) {
-        throw new SolrException(SERVER_ERROR, 
-                                "Unexpected 'exclude' init sub-param(s): '" + 
-                                args.getName(0) + "'");
+        throw new SolrException(SERVER_ERROR,
+            "Unexpected 'exclude' init sub-param(s): '" +
+                args.getName(0) + "'");
       }
       // call once per instance
       args.remove("exclude");
     }
+    return exclusions;
+  }
+  
+
+  /**
+   * Handles common initialization related to source fields for 
+   * constructing the FieldNameSelector to be used.
+   *
+   * Will error if any unexpected init args are found, so subclasses should
+   * remove any subclass-specific init args before calling this method.
+   */
+  @SuppressWarnings("unchecked")
+  @Override
+  public void init(NamedList args) {
+
+    inclusions = parseSelectorParams(args);
+    exclusions = parseSelectorExclusionParams(args);
+
     if (0 < args.size()) {
       throw new SolrException(SERVER_ERROR, 
                               "Unexpected init param(s): '" +