BugFix: field boosts were being ignored and doc boosts applied to fields rather than the doc

(testcase + fix)


git-svn-id: https://svn.apache.org/repos/asf/incubator/solr/trunk@471059 13f79535-47bb-0310-9956-ffa450edef68
This commit is contained in:
Mike Klaas 2006-11-03 23:44:11 +00:00
parent a0239f9f42
commit 2c71186808
3 changed files with 41 additions and 2 deletions

View File

@ -112,6 +112,7 @@ Bug Fixes
7. WordDelimiterFilter can throw exceptions if configured with both 7. WordDelimiterFilter can throw exceptions if configured with both
generate and catenate off. (Mike Klaas via yonik, SOLR-34) generate and catenate off. (Mike Klaas via yonik, SOLR-34)
8. Escape '>' in XML output (because ]]> is illegal in CharData) 8. Escape '>' in XML output (because ]]> is illegal in CharData)
9. field boosts weren't being applied and doc boosts were being applied to fields (klaas)
Other Changes Other Changes
1. Upgrade to Lucene 2.0 nightly build 2006-06-22, lucene SVN revision 416224, 1. Upgrade to Lucene 2.0 nightly build 2006-06-22, lucene SVN revision 416224,

View File

@ -864,6 +864,7 @@ public final class SolrCore {
String attrVal = xpp.getAttributeValue(i); String attrVal = xpp.getAttributeValue(i);
if ("boost".equals(attrName)) { if ("boost".equals(attrName)) {
docBoost = Float.parseFloat(attrVal); docBoost = Float.parseFloat(attrVal);
builder.setBoost(docBoost);
} else { } else {
log.warning("Unknown attribute doc/@" + attrName); log.warning("Unknown attribute doc/@" + attrName);
} }
@ -911,8 +912,8 @@ public final class SolrCore {
// need this line for isNull??? // need this line for isNull???
// Don't add fields marked as null (for now at least) // Don't add fields marked as null (for now at least)
if (!isNull) { if (!isNull) {
if (docBoost != 1.0f) { if (boost != 1.0f) {
builder.addField(name,val,docBoost); builder.addField(name,val,boost);
} else { } else {
builder.addField(name,val); builder.addField(name,val);
} }

View File

@ -157,6 +157,43 @@ public class BasicFunctionalityTest extends AbstractSolrTestCase {
} }
public void testDocBoost() throws Exception {
String res = h.update("<add>" + "<doc><field name=\"id\">1</field>"+
"<field name=\"text\">hello</field></doc>" +
"<doc boost=\"2.0\"><field name=\"id\">2</field>" +
"<field name=\"text\">hello</field></doc>" +
"</add>");
assertEquals("<result status=\"0\"></result><result status=\"0\"></result>", res);
assertU("<commit/>");
assertQ(req("text:hello")
,"//*[@numFound='2']"
);
String resp = h.query(lrf.makeRequest("q", "text:hello", "debugQuery", "true"));
//System.out.println(resp);
// second doc ranked first
assertTrue( resp.indexOf("id=2") < resp.indexOf("id=1") );
}
public void testFieldBoost() throws Exception {
String res = h.update("<add>" + "<doc><field name=\"id\">1</field>"+
"<field name=\"text\">hello</field></doc>" +
"<doc><field name=\"id\">2</field>" +
"<field boost=\"2.0\" name=\"text\">hello</field></doc>" +
"</add>");
assertEquals("<result status=\"0\"></result><result status=\"0\"></result>", res);
assertU("<commit/>");
assertQ(req("text:hello"),
"//*[@numFound='2']"
);
String resp = h.query(lrf.makeRequest("q", "text:hello", "debugQuery", "true"));
//System.out.println(resp);
// second doc ranked first
assertTrue( resp.indexOf("id=2") < resp.indexOf("id=1") );
}
public void testXMLWriter() throws Exception { public void testXMLWriter() throws Exception {
SolrQueryResponse rsp = new SolrQueryResponse(); SolrQueryResponse rsp = new SolrQueryResponse();