You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@lucene.apache.org by ho...@apache.org on 2012/09/25 00:19:43 UTC

svn commit: r1389628 - in /lucene/dev/trunk/solr: CHANGES.txt core/src/java/org/apache/solr/update/DocumentBuilder.java core/src/test/org/apache/solr/update/DocumentBuilderTest.java

Author: hossman
Date: Mon Sep 24 22:19:43 2012
New Revision: 1389628

URL: http://svn.apache.org/viewvc?rev=1389628&view=rev
Log:
SOLR-3875: Fixed index boosts on multi-valued fields when docBoost is used

Modified:
    lucene/dev/trunk/solr/CHANGES.txt
    lucene/dev/trunk/solr/core/src/java/org/apache/solr/update/DocumentBuilder.java
    lucene/dev/trunk/solr/core/src/test/org/apache/solr/update/DocumentBuilderTest.java

Modified: lucene/dev/trunk/solr/CHANGES.txt
URL: http://svn.apache.org/viewvc/lucene/dev/trunk/solr/CHANGES.txt?rev=1389628&r1=1389627&r2=1389628&view=diff
==============================================================================
--- lucene/dev/trunk/solr/CHANGES.txt (original)
+++ lucene/dev/trunk/solr/CHANGES.txt Mon Sep 24 22:19:43 2012
@@ -341,6 +341,9 @@ Bug Fixes
 * SOLR-3869: A PeerSync attempt to it's replicas by a candidate leader should
   not fail on o.a.http.conn.ConnectTimeoutException. (Mark Miller)
 
+* SOLR-3875: Fixed index boosts on multi-valued fields when docBoost is used 
+  (hossman)
+
 Other Changes
 ----------------------
 

Modified: lucene/dev/trunk/solr/core/src/java/org/apache/solr/update/DocumentBuilder.java
URL: http://svn.apache.org/viewvc/lucene/dev/trunk/solr/core/src/java/org/apache/solr/update/DocumentBuilder.java?rev=1389628&r1=1389627&r2=1389628&view=diff
==============================================================================
--- lucene/dev/trunk/solr/core/src/java/org/apache/solr/update/DocumentBuilder.java (original)
+++ lucene/dev/trunk/solr/core/src/java/org/apache/solr/update/DocumentBuilder.java Mon Sep 24 22:19:43 2012
@@ -237,6 +237,7 @@ public class DocumentBuilder {
       String name = field.getName();
       SchemaField sfield = schema.getFieldOrNull(name);
       boolean used = false;
+
       float boost = field.getBoost();
       boolean applyBoost = sfield != null && sfield.indexed() && !sfield.omitNorms();
       
@@ -253,6 +254,12 @@ public class DocumentBuilder {
               sfield.getName() + ": " +field.getValue() );
       }
 
+      // Lucene no longer has a native docBoost, so we have to multiply 
+      // it ourselves (do this after the applyBoost error check so we don't 
+      // give an error on fields that don't support boost just because of a 
+      // docBoost)
+      boost *= docBoost;
+
       // load each field value
       boolean hasField = false;
       try {
@@ -263,7 +270,7 @@ public class DocumentBuilder {
           hasField = true;
           if (sfield != null) {
             used = true;
-            addField(out, sfield, v, applyBoost ? docBoost*boost : 1f);
+            addField(out, sfield, v, applyBoost ? boost : 1f);
           }
   
           // Check if we should copy this field to any other fields.
@@ -285,14 +292,14 @@ public class DocumentBuilder {
             if( val instanceof String && cf.getMaxChars() > 0 ) {
               val = cf.getLimitedValue((String)val);
             }
-            addField(out, destinationField, val, destinationField.indexed() && !destinationField.omitNorms() ? docBoost*boost : 1F);
+            addField(out, destinationField, val, destinationField.indexed() && !destinationField.omitNorms() ? boost : 1F);
           }
           
-          // In lucene, the boost for a given field is the product of the 
-          // document boost and *all* boosts on values of that field. 
+          // The boost for a given field is the product of the 
+          // *all* boosts on values of that field. 
           // For multi-valued fields, we only want to set the boost on the
           // first field.
-          boost = docBoost;
+          boost = 1.0f;
         }
       }
       catch( SolrException ex ) {

Modified: lucene/dev/trunk/solr/core/src/test/org/apache/solr/update/DocumentBuilderTest.java
URL: http://svn.apache.org/viewvc/lucene/dev/trunk/solr/core/src/test/org/apache/solr/update/DocumentBuilderTest.java?rev=1389628&r1=1389627&r2=1389628&view=diff
==============================================================================
--- lucene/dev/trunk/solr/core/src/test/org/apache/solr/update/DocumentBuilderTest.java (original)
+++ lucene/dev/trunk/solr/core/src/test/org/apache/solr/update/DocumentBuilderTest.java Mon Sep 24 22:19:43 2012
@@ -18,9 +18,11 @@
 package org.apache.solr.update;
 
 import org.apache.lucene.document.Document;
+import org.apache.lucene.index.IndexableField;
 import org.apache.solr.SolrTestCaseJ4;
 import org.apache.solr.common.SolrException;
 import org.apache.solr.common.SolrInputDocument;
+import org.apache.solr.common.SolrInputField;
 import org.apache.solr.core.SolrCore;
 import org.apache.solr.schema.FieldType;
 import org.apache.solr.schema.IndexSchema;
@@ -206,6 +208,32 @@ public class DocumentBuilderTest extends
     assertNull(h.validateUpdate(add(xml, new String[0])));
   }
   
+  public void testMultiValuedFielAndDocBoosts() throws Exception {
+    SolrCore core = h.getCore();
+    IndexSchema schema = core.getSchema();
+    SolrInputDocument doc = new SolrInputDocument();
+    doc.setDocumentBoost(3.0f);
+    SolrInputField field = new SolrInputField( "foo_t" );
+    field.addValue( "summer time" , 1.0f );
+    field.addValue( "in the city" , 5.0f ); // using boost
+    field.addValue( "living is easy" , 1.0f );
+    doc.put( field.getName(), field );
+
+    Document out = DocumentBuilder.toDocument( doc, core.getSchema() );
+    IndexableField[] outF = out.getFields( field.getName() );
+    assertEquals("wrong number of field values",
+                 3, outF.length);
+
+    // since Lucene no longer has native documnt boosts, we should find
+    // the doc boost multiplied into the boost o nthe first field value
+    // all other field values should be 1.0f
+    // (lucene will multiply all of the field boosts later)
+    assertEquals(15.0f, outF[0].boost(), 0.0f);
+    assertEquals(1.0f, outF[1].boost(), 0.0f);
+    assertEquals(1.0f, outF[2].boost(), 0.0f);
+    
+  }
+
   /**
    * Its not ok to boost a field if it omits norms
    */