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 2012/12/23 11:01:09 UTC

svn commit: r1425448 - in /lucene/dev/trunk/solr: CHANGES.txt solrj/src/java/org/apache/solr/client/solrj/util/ClientUtils.java solrj/src/test/org/apache/solr/client/solrj/SolrExampleTests.java

Author: shalin
Date: Sun Dec 23 10:01:08 2012
New Revision: 1425448

URL: http://svn.apache.org/viewvc?rev=1425448&view=rev
Log:
SOLR-4133: Cannot "set" field to null with partial updates when using the
  standard RequestWriter

Modified:
    lucene/dev/trunk/solr/CHANGES.txt
    lucene/dev/trunk/solr/solrj/src/java/org/apache/solr/client/solrj/util/ClientUtils.java
    lucene/dev/trunk/solr/solrj/src/test/org/apache/solr/client/solrj/SolrExampleTests.java

Modified: lucene/dev/trunk/solr/CHANGES.txt
URL: http://svn.apache.org/viewvc/lucene/dev/trunk/solr/CHANGES.txt?rev=1425448&r1=1425447&r2=1425448&view=diff
==============================================================================
--- lucene/dev/trunk/solr/CHANGES.txt (original)
+++ lucene/dev/trunk/solr/CHANGES.txt Sun Dec 23 10:01:08 2012
@@ -378,6 +378,9 @@ Bug Fixes
 * SOLR-3972: Fix ShowFileRequestHandler to not log a warning in the 
   (expected) situation of a file not found.  (hossman)
 
+* SOLR-4133: Cannot "set" field to null with partial updates when using the
+  standard RequestWriter. (Will Butler, shalin)
+
 Other Changes
 ----------------------
 

Modified: lucene/dev/trunk/solr/solrj/src/java/org/apache/solr/client/solrj/util/ClientUtils.java
URL: http://svn.apache.org/viewvc/lucene/dev/trunk/solr/solrj/src/java/org/apache/solr/client/solrj/util/ClientUtils.java?rev=1425448&r1=1425447&r2=1425448&view=diff
==============================================================================
--- lucene/dev/trunk/solr/solrj/src/java/org/apache/solr/client/solrj/util/ClientUtils.java (original)
+++ lucene/dev/trunk/solr/solrj/src/java/org/apache/solr/client/solrj/util/ClientUtils.java Sun Dec 23 10:01:08 2012
@@ -147,8 +147,12 @@ public class ClientUtils 
     } else {
       if( boost != 1.0f ) {
         XML.writeXML(writer, "field", v.toString(), "name", name, "boost", boost, "update", update);
-      } else if (v != null) {
-        XML.writeXML(writer, "field", v.toString(), "name", name, "update", update);
+      } else {
+        if (v == null)  {
+          XML.writeXML(writer, "field", null, "name", name, "update", update, "null", true);
+        } else  {
+          XML.writeXML(writer, "field", v.toString(), "name", name, "update", update);
+        }
       }
     }
   }

Modified: lucene/dev/trunk/solr/solrj/src/test/org/apache/solr/client/solrj/SolrExampleTests.java
URL: http://svn.apache.org/viewvc/lucene/dev/trunk/solr/solrj/src/test/org/apache/solr/client/solrj/SolrExampleTests.java?rev=1425448&r1=1425447&r2=1425448&view=diff
==============================================================================
--- lucene/dev/trunk/solr/solrj/src/test/org/apache/solr/client/solrj/SolrExampleTests.java (original)
+++ lucene/dev/trunk/solr/solrj/src/test/org/apache/solr/client/solrj/SolrExampleTests.java Sun Dec 23 10:01:08 2012
@@ -21,6 +21,7 @@ package org.apache.solr.client.solrj;
 import java.io.IOException;
 import java.lang.reflect.Field;
 import java.util.ArrayList;
+import java.util.Arrays;
 import java.util.Collection;
 import java.util.HashMap;
 import java.util.List;
@@ -29,6 +30,7 @@ import java.util.Random;
 import java.util.concurrent.atomic.AtomicInteger;
 
 import com.google.common.collect.Lists;
+import com.google.common.collect.Maps;
 import junit.framework.Assert;
 
 import org.apache.lucene.util._TestUtil;
@@ -1392,7 +1394,7 @@ abstract public class SolrExampleTests e
     assertEquals("Failed to add doc to cloud server", 1, response.getResults().getNumFound());
 
     Map<String, List<String>> operation = new HashMap<String, List<String>>();
-    operation.put("set", Lists.asList("first", "second", new String[]{"third"}));
+    operation.put("set", Arrays.asList("first", "second", "third"));
     doc.addField("multi_ss", operation);
     solrServer.add(doc);
     solrServer.commit(true, true);
@@ -1402,7 +1404,7 @@ abstract public class SolrExampleTests e
     assertEquals("Field values was not updated with all values via atomic update", 3, values.size());
 
     operation.clear();
-    operation.put("add", Lists.asList("fourth", new String[]{"fifth"}));
+    operation.put("add", Arrays.asList("fourth", "fifth"));
     doc.removeField("multi_ss");
     doc.addField("multi_ss", operation);
     solrServer.add(doc);
@@ -1411,6 +1413,27 @@ abstract public class SolrExampleTests e
     values = (List<String>) response.getResults().get(0).get("multi_ss");
     assertEquals("Field values was not updated with all values via atomic update", 5, values.size());
   }
+
+  @Test
+  public void testSetNullUpdates() throws Exception {
+    SolrServer solrServer = getSolrServer();
+    SolrInputDocument doc = new SolrInputDocument();
+    doc.addField("id", "testSetNullUpdates");
+    doc.addField("single_s", "test-value");
+    doc.addField("multi_ss", Arrays.asList("first", "second"));
+    solrServer.add(doc);
+    solrServer.commit(true, true);
+    doc.removeField("single_s");
+    doc.removeField("multi_ss");
+    Map<String, Object> map = Maps.newHashMap();
+    map.put("set", null);
+    doc.addField("multi_ss", map);
+    solrServer.add(doc);
+    solrServer.commit(true, true);
+    QueryResponse response = solrServer.query(new SolrQuery("id:testSetNullUpdates"));
+    assertNotNull("Entire doc was replaced because null update was not written", response.getResults().get(0).getFieldValue("single_s"));
+    assertNull("Null update failed. Value still exists in document", response.getResults().get(0).getFieldValue("multi_ss"));
+  }
   
   @Test
   public void testQueryWithParams() throws SolrServerException {