lucene-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From sar...@apache.org
Subject svn commit: r1581014 - in /lucene/dev/branches/lucene_solr_4_7: ./ solr/ solr/CHANGES.txt solr/core/ solr/core/src/java/org/apache/solr/handler/loader/JsonLoader.java solr/core/src/test/org/apache/solr/handler/JsonLoaderTest.java
Date Mon, 24 Mar 2014 19:37:17 GMT
Author: sarowe
Date: Mon Mar 24 19:37:16 2014
New Revision: 1581014

URL: http://svn.apache.org/r1581014
Log:
SOLR-5777: Fix ordering of field values in JSON updates where field name key is repeated (merged
branch_4x r1572271)

Modified:
    lucene/dev/branches/lucene_solr_4_7/   (props changed)
    lucene/dev/branches/lucene_solr_4_7/solr/   (props changed)
    lucene/dev/branches/lucene_solr_4_7/solr/CHANGES.txt   (contents, props changed)
    lucene/dev/branches/lucene_solr_4_7/solr/core/   (props changed)
    lucene/dev/branches/lucene_solr_4_7/solr/core/src/java/org/apache/solr/handler/loader/JsonLoader.java
    lucene/dev/branches/lucene_solr_4_7/solr/core/src/test/org/apache/solr/handler/JsonLoaderTest.java

Modified: lucene/dev/branches/lucene_solr_4_7/solr/CHANGES.txt
URL: http://svn.apache.org/viewvc/lucene/dev/branches/lucene_solr_4_7/solr/CHANGES.txt?rev=1581014&r1=1581013&r2=1581014&view=diff
==============================================================================
--- lucene/dev/branches/lucene_solr_4_7/solr/CHANGES.txt (original)
+++ lucene/dev/branches/lucene_solr_4_7/solr/CHANGES.txt Mon Mar 24 19:37:16 2014
@@ -78,6 +78,9 @@ Bug Fixes
 * SOLR-5550: shards.info is not returned by a short circuited distributed query.
   (Timothy Potter, shalin)
 
+* SOLR-5777: Fix ordering of field values in JSON updates where
+  field name key is repeated (hossman)
+
 ==================  4.7.0 ==================
 
 Versions of Major Components

Modified: lucene/dev/branches/lucene_solr_4_7/solr/core/src/java/org/apache/solr/handler/loader/JsonLoader.java
URL: http://svn.apache.org/viewvc/lucene/dev/branches/lucene_solr_4_7/solr/core/src/java/org/apache/solr/handler/loader/JsonLoader.java?rev=1581014&r1=1581013&r2=1581014&view=diff
==============================================================================
--- lucene/dev/branches/lucene_solr_4_7/solr/core/src/java/org/apache/solr/handler/loader/JsonLoader.java
(original)
+++ lucene/dev/branches/lucene_solr_4_7/solr/core/src/java/org/apache/solr/handler/loader/JsonLoader.java
Mon Mar 24 19:37:16 2014
@@ -418,11 +418,11 @@ public class JsonLoader extends ContentS
       for (;;) {
         SolrInputField sif = parseField();
         if (sif == null) return sdoc;
-        SolrInputField prev = sdoc.put(sif.getName(), sif);
-        if (prev != null) {
-          // blech - repeated keys
-          sif.addValue(prev.getValue(), prev.getBoost());
-        }
+        // pulling out hte pieces may seem weird, but it's because
+        // SolrInputDocument.addField will do the right thing
+        // if the doc already has another value for this field
+        // (ie: repeating fieldname keys)
+        sdoc.addField(sif.getName(), sif.getValue(), sif.getBoost());
       }
     }
   
@@ -550,4 +550,4 @@ public class JsonLoader extends ContentS
     }
   }
 
-}
\ No newline at end of file
+}

Modified: lucene/dev/branches/lucene_solr_4_7/solr/core/src/test/org/apache/solr/handler/JsonLoaderTest.java
URL: http://svn.apache.org/viewvc/lucene/dev/branches/lucene_solr_4_7/solr/core/src/test/org/apache/solr/handler/JsonLoaderTest.java?rev=1581014&r1=1581013&r2=1581014&view=diff
==============================================================================
--- lucene/dev/branches/lucene_solr_4_7/solr/core/src/test/org/apache/solr/handler/JsonLoaderTest.java
(original)
+++ lucene/dev/branches/lucene_solr_4_7/solr/core/src/test/org/apache/solr/handler/JsonLoaderTest.java
Mon Mar 24 19:37:16 2014
@@ -209,6 +209,54 @@ public class JsonLoaderTest extends Solr
     req.close();
   }
 
+  public void testFieldValueOrdering() throws Exception {
+    final String pre = "{'add':[{'id':'1',";
+    final String post = "},{'id':'2'}]}";
+
+    // list
+    checkFieldValueOrdering((pre+ "'f':[45,67,89]" +post)
+                            .replace('\'', '"'),
+                            1.0F);
+    // dup fieldname keys
+    checkFieldValueOrdering((pre+ "'f':45,'f':67,'f':89" +post)
+                            .replace('\'', '"'),
+                            1.0F);
+    // extended w/boost
+    checkFieldValueOrdering((pre+ "'f':{'boost':4.0,'value':[45,67,89]}" +post)
+                            .replace('\'', '"'),
+                            4.0F);
+    // dup keys extended w/ multiplicitive boost
+    checkFieldValueOrdering((pre+ 
+                             "'f':{'boost':2.0,'value':[45,67]}," +
+                             "'f':{'boost':2.0,'value':89}" 
+                             +post)
+                            .replace('\'', '"'),
+                            4.0F);
+
+  }
+  private void checkFieldValueOrdering(String rawJson, float fBoost) throws Exception {
+    SolrQueryRequest req = req();
+    SolrQueryResponse rsp = new SolrQueryResponse();
+    BufferingRequestProcessor p = new BufferingRequestProcessor(null);
+    JsonLoader loader = new JsonLoader();
+    loader.load(req, rsp, new ContentStreamBase.StringStream(rawJson), p);
+    assertEquals( 2, p.addCommands.size() );
+
+    SolrInputDocument d = p.addCommands.get(0).solrDoc;
+    assertEquals(2, d.getFieldNames().size());
+    assertEquals("1", d.getFieldValue("id"));
+    assertEquals(new Object[] {45L, 67L, 89L} , d.getFieldValues("f").toArray());
+    assertEquals(0.0F, fBoost, d.getField("f").getBoost());
+
+    d = p.addCommands.get(1).solrDoc;
+    assertEquals(1, d.getFieldNames().size());
+    assertEquals("2", d.getFieldValue("id"));
+
+    req.close();
+  }
+
+
+
   public void testExtendedFieldValues() throws Exception {
     String str = "[{'id':'1', 'val_s':{'add':'foo'}}]".replace('\'', '"');
     SolrQueryRequest req = req();
@@ -500,4 +548,4 @@ public class JsonLoaderTest extends Solr
   }
 
 
-}
\ No newline at end of file
+}



Mime
View raw message