1. DocumentBuilder only sets the boost for the first value in a multi-valued field

2. XML parser sets the document boost as the product of each boost value.
3. Added XmlUpdateRequestHandlerTest (somehow lost in the final patch of SOLR-133)

http://www.nabble.com/Re%3A-svn-commit%3A-r547493---in--lucene-solr-trunk%3A-.--src-java-org-apache-solr-common--src-java-org-apache-solr-schema--src-java-org-apache-solr-update--src-test-org-apache-solr-common--p11159518.html

git-svn-id: https://svn.apache.org/repos/asf/lucene/solr/trunk@548084 13f79535-47bb-0310-9956-ffa450edef68
This commit is contained in:
Ryan McKinley 2007-06-17 18:14:08 +00:00
parent 6ed8e171ad
commit 91c3b6d535
3 changed files with 82 additions and 1 deletions

View File

@ -354,7 +354,17 @@ public class StaxUpdateRequestHandler extends RequestHandlerBase
if (!isNull) {
doc.addField(name, text.toString() );
if(boost != null) {
doc.setBoost( name, boost );
// The lucene API and solr XML field specification make it possible to set boosts
// on multi-value fields even though lucene indexing does not support this.
// To keep behavior consistent with what happens in the lucene index, we accumulate
// the product of all boosts specified for this field.
Float old = doc.getBoost( name );
if( old != null ) {
doc.setBoost( name, boost*old );
}
else {
doc.setBoost( name, boost );
}
}
}
}

View File

@ -197,6 +197,12 @@ public class DocumentBuilder {
val = v.toString();
}
out.add( sfield.createField( val, boost ) );
// In lucene, the boost for a given field is the product of the
// document boost and *all* boosts on values of that field.
// For multi-valued fields, we only want to set the boost on the
// first field.
boost = 1.0f;
}
}

View File

@ -0,0 +1,65 @@
package org.apache.solr.handler;
import java.io.StringReader;
import java.util.Collection;
import javanet.staxutils.BaseXMLInputFactory;
import javax.xml.stream.XMLInputFactory;
import javax.xml.stream.XMLStreamReader;
import junit.framework.TestCase;
import org.apache.solr.common.SolrInputDocument;
public class XmlUpdateRequestHandlerTest extends TestCase
{
private XMLInputFactory inputFactory = BaseXMLInputFactory.newInstance();
protected StaxUpdateRequestHandler handler = new StaxUpdateRequestHandler();
@Override
public void setUp() throws Exception {
super.setUp();
}
@Override
public void tearDown() throws Exception {
super.tearDown();
}
public void testReadDoc() throws Exception
{
String xml =
"<doc boost=\"5.5\">" +
" <field name=\"id\" boost=\"2.2\">12345</field>" +
" <field name=\"name\">kitten</field>" +
" <field name=\"cat\" boost=\"3\">aaa</field>" +
" <field name=\"cat\" boost=\"4\">bbb</field>" +
" <field name=\"cat\" boost=\"5\">bbb</field>" +
" <field name=\"ab\">a&amp;b</field>" +
"</doc>";
XMLStreamReader parser =
inputFactory.createXMLStreamReader( new StringReader( xml ) );
parser.next(); // read the START document...
SolrInputDocument doc = handler.readDoc( parser );
// Read boosts
assertEquals( new Float(5.5f), doc.getBoost(null) );
assertEquals( null, doc.getBoost( "name" ) );
assertEquals( new Float(2.2f), doc.getBoost( "id" ) );
assertEquals( null, doc.getBoost( "ab" ) );
// Boost is the product of each value
assertEquals( new Float(3*4*5), doc.getBoost( "cat" ) );
// Read values
assertEquals( "12345", doc.getFieldValue( "id") );
assertEquals( "kitten", doc.getFieldValue( "name") );
assertEquals( "a&b", doc.getFieldValue( "ab") ); // read something with escaped characters
Collection<Object> out = doc.getFieldValues( "cat" );
assertEquals( 3, out.size() );
assertEquals( "[aaa, bbb, bbb]", out.toString() );
}
}