Skip to content

armgit / solr

Public Imported from GitHub
0

Apache Solr open-source search software

BugFix: field boosts were being ignored and doc boosts applied to fields rather than the doc (testcase + fix)

Mike Klaas2c711868082a
diff --git a/CHANGES.txt b/CHANGES.txt
index fe8d4218d9a..74bbdfa7f23 100644
--- a/CHANGES.txt
+++ b/CHANGES.txt
@@ -112,6 +112,7 @@ Bug Fixes
7. WordDelimiterFilter can throw exceptions if configured with both
generate and catenate off. (Mike Klaas via yonik, SOLR-34)
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
1. Upgrade to Lucene 2.0 nightly build 2006-06-22, lucene SVN revision 416224,
diff --git a/src/java/org/apache/solr/core/SolrCore.java b/src/java/org/apache/solr/core/SolrCore.java
index 1251ee0ef80..dd65078a8f4 100644
--- a/src/java/org/apache/solr/core/SolrCore.java
+++ b/src/java/org/apache/solr/core/SolrCore.java
@@ -864,6 +864,7 @@ public final class SolrCore {
String attrVal = xpp.getAttributeValue(i);
if ("boost".equals(attrName)) {
docBoost = Float.parseFloat(attrVal);
+ builder.setBoost(docBoost);
} else {
log.warning("Unknown attribute doc/@" + attrName);
}
@@ -911,8 +912,8 @@ public final class SolrCore {
// need this line for isNull???
// Don't add fields marked as null (for now at least)
if (!isNull) {
- if (docBoost != 1.0f) {
- builder.addField(name,val,docBoost);
+ if (boost != 1.0f) {
+ builder.addField(name,val,boost);
} else {
builder.addField(name,val);
}
diff --git a/src/test/org/apache/solr/BasicFunctionalityTest.java b/src/test/org/apache/solr/BasicFunctionalityTest.java
index c5b5928c0e5..b7634c35c4b 100644
--- a/src/test/org/apache/solr/BasicFunctionalityTest.java
+++ b/src/test/org/apache/solr/BasicFunctionalityTest.java
@@ -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 {
SolrQueryResponse rsp = new SolrQueryResponse();