lucene-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From rm...@apache.org
Subject svn commit: r1410917 - in /lucene/dev/trunk/solr: ./ core/src/java/org/apache/solr/response/ core/src/java/org/apache/solr/schema/ core/src/test-files/solr/collection1/conf/ core/src/test/org/apache/solr/response/
Date Sun, 18 Nov 2012 16:29:03 GMT
Author: rmuir
Date: Sun Nov 18 16:29:02 2012
New Revision: 1410917

URL: http://svn.apache.org/viewvc?rev=1410917&view=rev
Log:
SOLR-3959: escape the internal comma separator of poly fields

Modified:
    lucene/dev/trunk/solr/CHANGES.txt
    lucene/dev/trunk/solr/core/src/java/org/apache/solr/response/CSVResponseWriter.java
    lucene/dev/trunk/solr/core/src/java/org/apache/solr/schema/CurrencyField.java
    lucene/dev/trunk/solr/core/src/java/org/apache/solr/schema/LatLonType.java
    lucene/dev/trunk/solr/core/src/java/org/apache/solr/schema/PointType.java
    lucene/dev/trunk/solr/core/src/test-files/solr/collection1/conf/schema12.xml
    lucene/dev/trunk/solr/core/src/test/org/apache/solr/response/TestCSVResponseWriter.java

Modified: lucene/dev/trunk/solr/CHANGES.txt
URL: http://svn.apache.org/viewvc/lucene/dev/trunk/solr/CHANGES.txt?rev=1410917&r1=1410916&r2=1410917&view=diff
==============================================================================
--- lucene/dev/trunk/solr/CHANGES.txt (original)
+++ lucene/dev/trunk/solr/CHANGES.txt Sun Nov 18 16:29:02 2012
@@ -207,6 +207,8 @@ Bug Fixes
   (used when cache=false), spatial queries, and frange queires.
   (Eirik Lygre, yonik)
 
+* SOLR-3959: Ensure the internal comma separator of poly fields is escaped
+  for CSVResponseWriter.  (Areek Zillur via Robert Muir)
 
 Other Changes
 ----------------------

Modified: lucene/dev/trunk/solr/core/src/java/org/apache/solr/response/CSVResponseWriter.java
URL: http://svn.apache.org/viewvc/lucene/dev/trunk/solr/core/src/java/org/apache/solr/response/CSVResponseWriter.java?rev=1410917&r1=1410916&r2=1410917&view=diff
==============================================================================
--- lucene/dev/trunk/solr/core/src/java/org/apache/solr/response/CSVResponseWriter.java (original)
+++ lucene/dev/trunk/solr/core/src/java/org/apache/solr/response/CSVResponseWriter.java Sun
Nov 18 16:29:02 2012
@@ -202,7 +202,6 @@ class CSVWriter extends TextResponseWrit
       // be escaped.
       strat.setUnicodeEscapeInterpretation(true);
     }
-
     printer = new CSVPrinter(writer, strategy);
     
 
@@ -261,7 +260,6 @@ class CSVWriter extends TextResponseWrit
        if (!returnFields.wantsField(field)) {
          continue;
        }
-
       if (field.equals("score")) {
         CSVField csvField = new CSVField();
         csvField.name = "score";
@@ -284,6 +282,11 @@ class CSVWriter extends TextResponseWrit
       sep = params.get("f." + field + '.' + CSV_SEPARATOR);
       encapsulator = params.get("f." + field + '.' + CSV_ENCAPSULATOR);
       escape = params.get("f." + field + '.' + CSV_ESCAPE);
+     
+      // if polyfield and no escape is provided, add "\\" escape by default
+      if (sf.isPolyField()) {
+        escape = (escape==null)?"\\":escape;
+      }
 
       CSVSharedBufPrinter csvPrinter = csvPrinterMV;
       if (sep != null || encapsulator != null || escape != null) {
@@ -310,7 +313,6 @@ class CSVWriter extends TextResponseWrit
         csvPrinter = new CSVSharedBufPrinter(mvWriter, strat);
       }
 
-
       CSVField csvField = new CSVField();
       csvField.name = field;
       csvField.sf = sf;
@@ -407,7 +409,19 @@ class CSVWriter extends TextResponseWrit
           Collection values = (Collection)val;
           val = values.iterator().next();
         }
-        writeVal(csvField.name, val);
+        // if field is polyfield, use the multi-valued printer to apply appropriate escaping
+        if (csvField.sf != null && csvField.sf.isPolyField()) {
+          mvWriter.reset();
+          csvField.mvPrinter.reset();
+          CSVPrinter tmp = printer;
+          printer = csvField.mvPrinter;
+          writeVal(csvField.name, val);
+          printer = tmp;
+          mvWriter.freeze();
+          printer.print(mvWriter.getFrozenBuf(), 0, mvWriter.getFrozenSize(), true);
+        } else {
+          writeVal(csvField.name, val);
+        }
       }
     }
 

Modified: lucene/dev/trunk/solr/core/src/java/org/apache/solr/schema/CurrencyField.java
URL: http://svn.apache.org/viewvc/lucene/dev/trunk/solr/core/src/java/org/apache/solr/schema/CurrencyField.java?rev=1410917&r1=1410916&r2=1410917&view=diff
==============================================================================
--- lucene/dev/trunk/solr/core/src/java/org/apache/solr/schema/CurrencyField.java (original)
+++ lucene/dev/trunk/solr/core/src/java/org/apache/solr/schema/CurrencyField.java Sun Nov
18 16:29:02 2012
@@ -250,7 +250,7 @@ public class CurrencyField extends Field
 
   @Override
   public void write(TextResponseWriter writer, String name, StorableField field) throws IOException
{
-    writer.writeStr(name, field.stringValue(), false);
+    writer.writeStr(name, field.stringValue(), true);
   }
 
   public ExchangeRateProvider getProvider() {

Modified: lucene/dev/trunk/solr/core/src/java/org/apache/solr/schema/LatLonType.java
URL: http://svn.apache.org/viewvc/lucene/dev/trunk/solr/core/src/java/org/apache/solr/schema/LatLonType.java?rev=1410917&r1=1410916&r2=1410917&view=diff
==============================================================================
--- lucene/dev/trunk/solr/core/src/java/org/apache/solr/schema/LatLonType.java (original)
+++ lucene/dev/trunk/solr/core/src/java/org/apache/solr/schema/LatLonType.java Sun Nov 18
16:29:02 2012
@@ -241,7 +241,7 @@ public class LatLonType extends Abstract
 
   @Override
   public void write(TextResponseWriter writer, String name, StorableField f) throws IOException
{
-    writer.writeStr(name, f.stringValue(), false);
+    writer.writeStr(name, f.stringValue(), true);
   }
 
   @Override

Modified: lucene/dev/trunk/solr/core/src/java/org/apache/solr/schema/PointType.java
URL: http://svn.apache.org/viewvc/lucene/dev/trunk/solr/core/src/java/org/apache/solr/schema/PointType.java?rev=1410917&r1=1410916&r2=1410917&view=diff
==============================================================================
--- lucene/dev/trunk/solr/core/src/java/org/apache/solr/schema/PointType.java (original)
+++ lucene/dev/trunk/solr/core/src/java/org/apache/solr/schema/PointType.java Sun Nov 18 16:29:02
2012
@@ -121,7 +121,7 @@ public class PointType extends Coordinat
 
   @Override
   public void write(TextResponseWriter writer, String name, StorableField f) throws IOException
{
-    writer.writeStr(name, f.stringValue(), false);
+    writer.writeStr(name, f.stringValue(), true);
   }
 
   @Override

Modified: lucene/dev/trunk/solr/core/src/test-files/solr/collection1/conf/schema12.xml
URL: http://svn.apache.org/viewvc/lucene/dev/trunk/solr/core/src/test-files/solr/collection1/conf/schema12.xml?rev=1410917&r1=1410916&r2=1410917&view=diff
==============================================================================
--- lucene/dev/trunk/solr/core/src/test-files/solr/collection1/conf/schema12.xml (original)
+++ lucene/dev/trunk/solr/core/src/test-files/solr/collection1/conf/schema12.xml Sun Nov 18
16:29:02 2012
@@ -428,6 +428,7 @@
     <!-- A specialized field for geospatial search. If indexed, this fieldType must not
be multivalued. -->
     <fieldType name="location" class="solr.LatLonType" subFieldSuffix="_coordinate"/>
 
+  <fieldType name="currency" class="solr.CurrencyField" currencyConfig="currency.xml"
multiValued="false" />
  </types>
 
 
@@ -524,6 +525,8 @@
    <field name="point_hash" type="geohash" indexed="true" stored="true" multiValued="false"/>
    <field name="store" type="location" indexed="true" stored="true"/>
    
+   <!-- Test currency field -->
+   <field name="amount_c" type="currency" indexed="true" stored="true" multiValued="false"/>
    <!-- to test uniq fields -->   
    <field name="uniq" type="string" indexed="true" stored="true" multiValued="true"/>
    <field name="uniq2" type="string" indexed="true" stored="true" multiValued="true"/>

Modified: lucene/dev/trunk/solr/core/src/test/org/apache/solr/response/TestCSVResponseWriter.java
URL: http://svn.apache.org/viewvc/lucene/dev/trunk/solr/core/src/test/org/apache/solr/response/TestCSVResponseWriter.java?rev=1410917&r1=1410916&r2=1410917&view=diff
==============================================================================
--- lucene/dev/trunk/solr/core/src/test/org/apache/solr/response/TestCSVResponseWriter.java
(original)
+++ lucene/dev/trunk/solr/core/src/test/org/apache/solr/response/TestCSVResponseWriter.java
Sun Nov 18 16:29:02 2012
@@ -39,6 +39,8 @@ public class TestCSVResponseWriter exten
     assertU(adoc("id","1", "foo_i","-1", "foo_s","hi", "foo_l","12345678987654321", "foo_b","false",
"foo_f","1.414","foo_d","-1.0E300","foo_dt","2000-01-02T03:04:05Z"));
     assertU(adoc("id","2", "v_ss","hi",  "v_ss","there", "v2_ss","nice", "v2_ss","output",
"shouldbeunstored","foo"));
     assertU(adoc("id","3", "shouldbeunstored","foo"));
+    assertU(adoc("id","4", "amount_c", "1.50,EUR"));
+    assertU(adoc("id","5", "store", "12.434,-134.1"));
     assertU(commit());
   }
 
@@ -69,6 +71,13 @@ public class TestCSVResponseWriter exten
     assertEquals("2,hi|there,nice:output\n"
     , h.query(req("q","id:2", "wt","csv", "csv.header","false", "csv.mv.separator","|", "f.v2_ss.csv.separator",":",
"fl","id,v_ss,v2_ss")));
 
+    // test csv field for polyfield (currency) SOLR-3959
+    assertEquals("4,\"1.50\\,EUR\"\n"
+    , h.query(req("q","id:4", "wt","csv", "csv.header","false", "fl","id,amount_c")));
+ 
+    // test csv field for polyfield (latlon) SOLR-3959
+    assertEquals("5,\"12.434\\,-134.1\"\n"
+    , h.query(req("q","id:5", "wt","csv", "csv.header","false", "fl","id,store")) );
     // test retrieving fields from index
     String result = h.query(req("q","*:*", "wt","csv", "csv.header","true", "fl","*,score"));
     for (String field : "id,foo_s,foo_i,foo_l,foo_b,foo_f,foo_d,foo_dt,v_ss,v2_ss,score".split(","))
{
@@ -100,7 +109,7 @@ public class TestCSVResponseWriter exten
     , h.query(req("q","id:[1 TO 2]", "wt","csv", "csv.header","false", "fl","id,v_ss,foo_s")));
 
     // test SOLR-2970 not returning non-stored fields by default. Compare sorted list
-    assertEquals(sortHeader("v_ss,foo_b,v2_ss,foo_f,foo_i,foo_d,foo_s,foo_dt,id,foo_l\n")
+    assertEquals(sortHeader("amount_c,store,v_ss,foo_b,v2_ss,foo_f,foo_i,foo_d,foo_s,foo_dt,id,foo_l\n")
     , sortHeader(h.query(req("q","id:3", "wt","csv", "csv.header","true", "fl","*", "rows","0"))));
 
 



Mime
View raw message