lucene-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From sar...@apache.org
Subject svn commit: r1571505 - in /lucene/dev/trunk/solr: ./ core/src/java/org/apache/solr/response/transform/ core/src/java/org/apache/solr/search/ core/src/test/org/apache/solr/response/ core/src/test/org/apache/solr/search/
Date Tue, 25 Feb 2014 01:03:07 GMT
Author: sarowe
Date: Tue Feb 25 01:03:07 2014
New Revision: 1571505

URL: http://svn.apache.org/r1571505
Log:
SOLR-5423: CSV output doesn't include function field

Modified:
    lucene/dev/trunk/solr/CHANGES.txt
    lucene/dev/trunk/solr/core/src/java/org/apache/solr/response/transform/ValueSourceAugmenter.java
    lucene/dev/trunk/solr/core/src/java/org/apache/solr/search/SolrReturnFields.java
    lucene/dev/trunk/solr/core/src/test/org/apache/solr/response/TestCSVResponseWriter.java
    lucene/dev/trunk/solr/core/src/test/org/apache/solr/search/ReturnFieldsTest.java

Modified: lucene/dev/trunk/solr/CHANGES.txt
URL: http://svn.apache.org/viewvc/lucene/dev/trunk/solr/CHANGES.txt?rev=1571505&r1=1571504&r2=1571505&view=diff
==============================================================================
--- lucene/dev/trunk/solr/CHANGES.txt (original)
+++ lucene/dev/trunk/solr/CHANGES.txt Tue Feb 25 01:03:07 2014
@@ -89,6 +89,9 @@ Bug Fixes
 * SOLR-5647: The lib paths in example-schemaless will now load correctly.
   (Paul Westin via Shawn Heisey)
 
+* SOLR-5423: CSV output doesn't include function field
+  (Arun Kumar, hossman, Steve Rowe)
+
 Optimizations
 ----------------------
 * SOLR-1880: Distributed Search skips GET_FIELDS stage if EXECUTE_QUERY

Modified: lucene/dev/trunk/solr/core/src/java/org/apache/solr/response/transform/ValueSourceAugmenter.java
URL: http://svn.apache.org/viewvc/lucene/dev/trunk/solr/core/src/java/org/apache/solr/response/transform/ValueSourceAugmenter.java?rev=1571505&r1=1571504&r2=1571505&view=diff
==============================================================================
--- lucene/dev/trunk/solr/core/src/java/org/apache/solr/response/transform/ValueSourceAugmenter.java
(original)
+++ lucene/dev/trunk/solr/core/src/java/org/apache/solr/response/transform/ValueSourceAugmenter.java
Tue Feb 25 01:03:07 2014
@@ -56,7 +56,7 @@ public class ValueSourceAugmenter extend
   @Override
   public String getName()
   {
-    return "function("+name+")";
+    return name;
   }
 
   @Override

Modified: lucene/dev/trunk/solr/core/src/java/org/apache/solr/search/SolrReturnFields.java
URL: http://svn.apache.org/viewvc/lucene/dev/trunk/solr/core/src/java/org/apache/solr/search/SolrReturnFields.java?rev=1571505&r1=1571504&r2=1571505&view=diff
==============================================================================
--- lucene/dev/trunk/solr/core/src/java/org/apache/solr/search/SolrReturnFields.java (original)
+++ lucene/dev/trunk/solr/core/src/java/org/apache/solr/search/SolrReturnFields.java Tue Feb
25 01:03:07 2014
@@ -198,7 +198,7 @@ public class SolrReturnFields extends Re
             start = sp.pos;
           } else {
             if (Character.isWhitespace(ch) || ch == ',' || ch==0) {
-              addField( field, key, augmenters, req );
+              addField(field, key, augmenters, false);
               continue;
             }
             // an invalid field name... reset the position pointer to retry
@@ -213,7 +213,7 @@ public class SolrReturnFields extends Re
           ch = sp.ch();
           if (field != null && (Character.isWhitespace(ch) || ch == ',' || ch==0))
{
             rename.add(field, key);
-            addField( field, key, augmenters, req );
+            addField(field, key, augmenters, false);
             continue;
           }
           // an invalid field name... reset the position pointer to retry
@@ -266,7 +266,7 @@ public class SolrReturnFields extends Re
           else {
             // unknown transformer?
           }
-          addField(field, disp, augmenters, req);
+          addField(field, disp, augmenters, true);
           continue;
         }
 
@@ -307,6 +307,7 @@ public class SolrReturnFields extends Re
             assert parser.getLocalParams() != null;
             sp.pos = start + parser.localParamsEnd;
           }
+          funcStr = sp.val.substring(start, sp.pos);
 
 
           if (q instanceof FunctionQuery) {
@@ -320,18 +321,12 @@ public class SolrReturnFields extends Re
             if (localParams != null) {
               key = localParams.get("key");
             }
-            if (key == null) {
-              // use the function name itself as the field name
-              key = sp.val.substring(start, sp.pos);
-            }
           }
 
-
           if (key==null) {
             key = funcStr;
           }
-          okFieldNames.add( key );
-          okFieldNames.add( funcStr );
+          addField(funcStr, key, augmenters, true);
           augmenters.addTransformer( new ValueSourceAugmenter( key, parser, vs ) );
         }
         catch (SyntaxError e) {
@@ -341,7 +336,7 @@ public class SolrReturnFields extends Re
 
           if (req.getSchema().getFieldOrNull(field) != null) {
             // OK, it was an oddly named field
-            fields.add(field);
+            addField(field, key, augmenters, false);
             if( key != null ) {
               rename.add(field, key);
             }
@@ -358,7 +353,7 @@ public class SolrReturnFields extends Re
     }
   }
 
-  private void addField(String field, String key, DocTransformers augmenters, SolrQueryRequest
req)
+  private void addField(String field, String key, DocTransformers augmenters, boolean isPseudoField)
   {
     if(reqFieldNames==null) {
       reqFieldNames = new LinkedHashSet<String>();
@@ -371,7 +366,12 @@ public class SolrReturnFields extends Re
       reqFieldNames.add(key);
     }
 
-    fields.add(field); // need to put in the map to maintain order for things like CSVResponseWriter
+    if ( ! isPseudoField) {
+      // fields is returned by getLuceneFieldNames(), to be used to select which real fields
+      // to return, so pseudo-fields should not be added
+      fields.add(field);
+    }
+
     okFieldNames.add( field );
     okFieldNames.add( key );
     // a valid field name

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=1571505&r1=1571504&r2=1571505&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
Tue Feb 25 01:03:07 2014
@@ -22,7 +22,6 @@ import org.apache.solr.common.SolrDocume
 import org.apache.solr.common.SolrDocumentList;
 import org.apache.solr.common.util.DateUtil;
 import org.apache.solr.request.SolrQueryRequest;
-import org.apache.solr.search.ReturnFields;
 import org.apache.solr.search.SolrReturnFields;
 import org.junit.*;
 
@@ -192,6 +191,24 @@ public class TestCSVResponseWriter exten
         "2,,\n",
       buf.toString());
 
+    // Test function queries
+    rsp.setReturnFields( new SolrReturnFields("sum(1,1),id,exists(foo_i),div(9,1),foo_f",
req) );
+    buf = new StringWriter();
+    w.write(buf, req, rsp);
+    assertEquals("\"sum(1,1)\",id,exists(foo_i),\"div(9,1)\",foo_f\n" +
+        "\"\",1,,,1.414\n" +
+        "\"\",2,,,\n",
+        buf.toString());
+
+    // Test transformers
+    rsp.setReturnFields( new SolrReturnFields("mydocid:[docid],[explain]", req) );
+    buf = new StringWriter();
+    w.write(buf, req, rsp);
+    assertEquals("mydocid,[explain]\n" +
+        "\"\",\n" +
+        "\"\",\n",
+        buf.toString());
+
     req.close();
   }
   
@@ -207,6 +224,23 @@ public class TestCSVResponseWriter exten
     assertEquals(2, lines.length);
     assertEquals("XXX,YYY,FOO", lines[0] );
     assertEquals("1,0,hi", lines[1] );
+
+    //assertions specific to multiple pseudofields functions like abs, div, exists, etc..
(SOLR-5423)
+    String funcText = h.query(req("q","*", "wt","csv", "csv.header","true", "fl","XXX:id,YYY:exists(foo_i),exists(shouldbeunstored)"));
+    String[] funcLines = funcText.split("\n");
+    assertEquals(6, funcLines.length);
+    assertEquals("XXX,YYY,exists(shouldbeunstored)", funcLines[0] );
+    assertEquals("1,true,false", funcLines[1] );
+    assertEquals("3,false,true", funcLines[3] );
+    
+    
+    //assertions specific to single function without alias (SOLR-5423)
+    String singleFuncText = h.query(req("q","*", "wt","csv", "csv.header","true", "fl","exists(shouldbeunstored),XXX:id"));
+    String[] singleFuncLines = singleFuncText.split("\n");
+    assertEquals(6, singleFuncLines.length);
+    assertEquals("exists(shouldbeunstored),XXX", singleFuncLines[0] );
+    assertEquals("false,1", singleFuncLines[1] );
+    assertEquals("true,3", singleFuncLines[3] );
   }
     
 

Modified: lucene/dev/trunk/solr/core/src/test/org/apache/solr/search/ReturnFieldsTest.java
URL: http://svn.apache.org/viewvc/lucene/dev/trunk/solr/core/src/test/org/apache/solr/search/ReturnFieldsTest.java?rev=1571505&r1=1571504&r2=1571505&view=diff
==============================================================================
--- lucene/dev/trunk/solr/core/src/test/org/apache/solr/search/ReturnFieldsTest.java (original)
+++ lucene/dev/trunk/solr/core/src/test/org/apache/solr/search/ReturnFieldsTest.java Tue Feb
25 01:03:07 2014
@@ -181,25 +181,31 @@ public class ReturnFieldsTest extends So
 
   @Test
   public void testFunctions() {
-    ReturnFields rf = new SolrReturnFields( req("fl", "id sum(1,1)") );
+    ReturnFields rf = new SolrReturnFields( req("fl", "exists(text),id,sum(1,1)") );
     assertFalse(rf.wantsScore());
     assertTrue( rf.wantsField( "id" ) );
+    assertTrue( rf.wantsField( "sum(1,1)" ));
+    assertTrue( rf.wantsField( "exists(text)" ));
     assertFalse( rf.wantsAllFields() );
     assertFalse( rf.wantsField( "xxx" ) );
-    assertTrue( rf.getTransformer() instanceof ValueSourceAugmenter);
-    assertEquals("sum(1,1)", ((ValueSourceAugmenter) rf.getTransformer()).name);
+    assertTrue( rf.getTransformer() instanceof DocTransformers);
+    DocTransformers transformers = (DocTransformers)rf.getTransformer();
+    assertEquals("exists(text)", transformers.getTransformer(0).getName());
+    assertEquals("sum(1,1)", transformers.getTransformer(1).getName());
   }
 
   @Test
   public void testTransformers() {
     ReturnFields rf = new SolrReturnFields( req("fl", "[explain]") );
     assertFalse( rf.wantsScore() );
+    assertTrue(rf.wantsField("[explain]"));
     assertFalse(rf.wantsField("id"));
     assertFalse(rf.wantsAllFields());
     assertEquals( "[explain]", rf.getTransformer().getName() );
 
     rf = new SolrReturnFields( req("fl", "[shard],id") );
     assertFalse( rf.wantsScore() );
+    assertTrue(rf.wantsField("[shard]"));
     assertTrue(rf.wantsField("id"));
     assertFalse(rf.wantsField("xxx"));
     assertFalse(rf.wantsAllFields());
@@ -207,6 +213,7 @@ public class ReturnFieldsTest extends So
 
     rf = new SolrReturnFields( req("fl", "[docid]") );
     assertFalse( rf.wantsScore() );
+    assertTrue(rf.wantsField("[docid]"));
     assertFalse( rf.wantsField( "id" ) );
     assertFalse(rf.wantsField("xxx"));
     assertFalse(rf.wantsAllFields());
@@ -214,6 +221,7 @@ public class ReturnFieldsTest extends So
 
     rf = new SolrReturnFields( req("fl", "mydocid:[docid]") );
     assertFalse( rf.wantsScore() );
+    assertTrue(rf.wantsField("mydocid"));
     assertFalse( rf.wantsField( "id" ) );
     assertFalse(rf.wantsField("xxx"));
     assertFalse(rf.wantsAllFields());
@@ -221,6 +229,8 @@ public class ReturnFieldsTest extends So
 
     rf = new SolrReturnFields( req("fl", "[docid][shard]") );
     assertFalse( rf.wantsScore() );
+    assertTrue(rf.wantsField("[docid]"));
+    assertTrue(rf.wantsField("[shard]"));
     assertFalse(rf.wantsField("xxx"));
     assertFalse(rf.wantsAllFields());
     assertTrue( rf.getTransformer() instanceof DocTransformers);
@@ -228,6 +238,7 @@ public class ReturnFieldsTest extends So
 
     rf = new SolrReturnFields( req("fl", "[xxxxx]") );
     assertFalse( rf.wantsScore() );
+    assertTrue(rf.wantsField("[xxxxx]"));
     assertFalse( rf.wantsField( "id" ) );
     assertFalse(rf.wantsAllFields());
     assertNull(rf.getTransformer());



Mime
View raw message