Apache Lucene open-source search software
SOLR-3875: Fixed index boosts on multi-valued fields when docBoost is used
Chris M. Hostetter3f35d9be82d8
diff --git a/solr/CHANGES.txt b/solr/CHANGES.txtindex 4dead5dfcff..d3a66208199 100644--- a/solr/CHANGES.txt+++ b/solr/CHANGES.txt@@ -341,6 +341,9 @@ Bug Fixes* SOLR-3869: A PeerSync attempt to it's replicas by a candidate leader shouldnot 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----------------------diff --git a/solr/core/src/java/org/apache/solr/update/DocumentBuilder.java b/solr/core/src/java/org/apache/solr/update/DocumentBuilder.javaindex 236491acab8..d849d5ef7c6 100644--- a/solr/core/src/java/org/apache/solr/update/DocumentBuilder.java+++ b/solr/core/src/java/org/apache/solr/update/DocumentBuilder.java@@ -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 valueboolean 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 ) {diff --git a/solr/core/src/test/org/apache/solr/update/DocumentBuilderTest.java b/solr/core/src/test/org/apache/solr/update/DocumentBuilderTest.javaindex 79be74f50ac..a249d99b8b7 100644--- a/solr/core/src/test/org/apache/solr/update/DocumentBuilderTest.java+++ b/solr/core/src/test/org/apache/solr/update/DocumentBuilderTest.java@@ -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 SolrTestCaseJ4 {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*/