From 2c711868082a6b99c5d5e2eb3f350d411685c075 Mon Sep 17 00:00:00 2001 From: Mike Klaas Date: Fri, 3 Nov 2006 23:44:11 +0000 Subject: [PATCH] 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 --- CHANGES.txt | 1 + src/java/org/apache/solr/core/SolrCore.java | 5 ++- .../apache/solr/BasicFunctionalityTest.java | 37 +++++++++++++++++++ 3 files changed, 41 insertions(+), 2 deletions(-) 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("" + "1"+ + "hello" + + "2" + + "hello" + + ""); + + assertEquals("", res); + assertU(""); + 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("" + "1"+ + "hello" + + "2" + + "hello" + + ""); + + assertEquals("", res); + assertU(""); + 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();