lucene-solr-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From yo...@apache.org
Subject svn commit: r883315 - in /lucene/solr/trunk: CHANGES.txt src/solrj/org/apache/solr/client/solrj/SolrQuery.java src/test/org/apache/solr/client/solrj/SolrQueryTest.java
Date Mon, 23 Nov 2009 12:14:39 GMT
Author: yonik
Date: Mon Nov 23 12:14:38 2009
New Revision: 883315

URL: http://svn.apache.org/viewvc?rev=883315&view=rev
Log:
SOLR-1584: fix SolrQuery.setIncludeScore()

Modified:
    lucene/solr/trunk/CHANGES.txt
    lucene/solr/trunk/src/solrj/org/apache/solr/client/solrj/SolrQuery.java
    lucene/solr/trunk/src/test/org/apache/solr/client/solrj/SolrQueryTest.java

Modified: lucene/solr/trunk/CHANGES.txt
URL: http://svn.apache.org/viewvc/lucene/solr/trunk/CHANGES.txt?rev=883315&r1=883314&r2=883315&view=diff
==============================================================================
--- lucene/solr/trunk/CHANGES.txt (original)
+++ lucene/solr/trunk/CHANGES.txt Mon Nov 23 12:14:38 2009
@@ -44,14 +44,14 @@
 
 * SOLR-1574: Add many new functions from java Math (e.g. sin, cos) (yonik)
 
+* SOLR-1569: Allow functions to take in literal strings by modifying the FunctionQParser
and adding LiteralValueSource (gsingers)
+
 Optimizations
 ----------------------
 
 Bug Fixes
 ----------------------
 
-* SOLR-1569: Allow functions to take in literal strings by modifying the FunctionQParser
and adding LiteralValueSource (gsingers)
-
 * SOLR-1432: Make the new ValueSource.getValues(context,reader) delegate
   to the original ValueSource.getValues(reader) so custom sources
   will work. (yonik)
@@ -70,6 +70,10 @@
   string, which is treated the same as if no dataDir had been specified,
   hence the "data" directory under the solr home will be used.  (yonik)
 
+* SOLR-1584: SolrJ - SolrQuery.setIncludeScore() incorrectly added
+  fl=score to the parameter list instead of appending score to the
+  existing field list. (yonik)
+
 
 Other Changes
 ----------------------

Modified: lucene/solr/trunk/src/solrj/org/apache/solr/client/solrj/SolrQuery.java
URL: http://svn.apache.org/viewvc/lucene/solr/trunk/src/solrj/org/apache/solr/client/solrj/SolrQuery.java?rev=883315&r1=883314&r2=883315&view=diff
==============================================================================
--- lucene/solr/trunk/src/solrj/org/apache/solr/client/solrj/SolrQuery.java (original)
+++ lucene/solr/trunk/src/solrj/org/apache/solr/client/solrj/SolrQuery.java Mon Nov 23 12:14:38
2009
@@ -23,6 +23,8 @@
 import org.apache.solr.common.params.ModifiableSolrParams;
 import org.apache.solr.common.params.StatsParams;
 
+import java.util.regex.Pattern;
+
 
 /**
  * This is an augmented SolrParams with get/set/add fields for common fields used
@@ -445,11 +447,16 @@
     return fields;
   }
 
+  private static Pattern scorePattern = Pattern.compile("(^|[, ])score");
+
   public SolrQuery setIncludeScore(boolean includeScore) {
+    String fields = get(CommonParams.FL,"*");
     if (includeScore) {
-      this.add(CommonParams.FL, "score");
+      if (!scorePattern.matcher(fields).find()) {   
+        this.set(CommonParams.FL, fields+",score");
+      }
     } else {
-      this.remove(CommonParams.FL, "score");
+      this.set(CommonParams.FL, scorePattern.matcher(fields).replaceAll(""));
     }
     return this;
   }

Modified: lucene/solr/trunk/src/test/org/apache/solr/client/solrj/SolrQueryTest.java
URL: http://svn.apache.org/viewvc/lucene/solr/trunk/src/test/org/apache/solr/client/solrj/SolrQueryTest.java?rev=883315&r1=883314&r2=883315&view=diff
==============================================================================
--- lucene/solr/trunk/src/test/org/apache/solr/client/solrj/SolrQueryTest.java (original)
+++ lucene/solr/trunk/src/test/org/apache/solr/client/solrj/SolrQueryTest.java Mon Nov 23
12:14:38 2009
@@ -130,6 +130,13 @@
       assertEquals( Boolean.TRUE, q.setMissing(Boolean.TRUE.toString()).getBool( FacetParams.FACET_MISSING
) );
       assertEquals( Boolean.FALSE, q.setFacetMissing( Boolean.FALSE ).getBool( FacetParams.FACET_MISSING
) );      
       assertEquals( "true", q.setParam( "xxx", true ).getParams( "xxx" )[0] );
+
+      assertEquals( "x,y", q.setFields("x","y").getFields() );    
+      assertEquals( "x,y,score", q.setIncludeScore(true).getFields() );
+      assertEquals( "x,y,score", q.setIncludeScore(true).getFields() ); // set twice on purpose
+      assertEquals( "x,y", q.setIncludeScore(false).getFields() );
+      assertEquals( "x,y", q.setIncludeScore(false).getFields() ); // remove twice on purpose
+
   }
   
   public void testOrder() {



Mime
View raw message