diff --git a/solr/CHANGES.txt b/solr/CHANGES.txt index 14144218ed3..12adecdec3b 100644 --- a/solr/CHANGES.txt +++ b/solr/CHANGES.txt @@ -250,6 +250,9 @@ New Features the same behaviour as solr 3.5, favouring throughput over latency. More information can be found on the wiki (http://wiki.apache.org/solr/SolrConfigXml) (Greg Bowyer) +* SOLR-3278: Negative boost support to the Extended Dismax Query Parser Boost Query (bq). + (James Dyer) + Optimizations ---------------------- diff --git a/solr/core/src/java/org/apache/solr/search/ExtendedDismaxQParserPlugin.java b/solr/core/src/java/org/apache/solr/search/ExtendedDismaxQParserPlugin.java index 0f6a2f4a605..8ce05c1c50f 100755 --- a/solr/core/src/java/org/apache/solr/search/ExtendedDismaxQParserPlugin.java +++ b/solr/core/src/java/org/apache/solr/search/ExtendedDismaxQParserPlugin.java @@ -344,13 +344,17 @@ class ExtendedDismaxQParser extends QParser { /* * * Boosting Query * * */ boostParams = solrParams.getParams(DisMaxParams.BQ); - //List boostQueries = U.parseQueryStrings(req, boostParams); boostQueries=null; if (boostParams!=null && boostParams.length>0) { + Map bqBoosts = SolrPluginUtils.parseFieldBoosts(boostParams); boostQueries = new ArrayList(); - for (String qs : boostParams) { - if (qs.trim().length()==0) continue; - Query q = subQuery(qs, null).getQuery(); + for (Map.Entry bqs : bqBoosts.entrySet()) { + if (bqs.getKey().trim().length()==0) continue; + Query q = subQuery(bqs.getKey(), null).getQuery(); + Float b = bqs.getValue(); + if(b!=null) { + q.setBoost(b); + } boostQueries.add(q); } } diff --git a/solr/core/src/test/org/apache/solr/search/TestExtendedDismaxParser.java b/solr/core/src/test/org/apache/solr/search/TestExtendedDismaxParser.java index a9c83f157b6..b60d61e8c55 100755 --- a/solr/core/src/test/org/apache/solr/search/TestExtendedDismaxParser.java +++ b/solr/core/src/test/org/apache/solr/search/TestExtendedDismaxParser.java @@ -53,8 +53,11 @@ public class TestExtendedDismaxParser extends AbstractSolrTestCase { "text", "line up and fly directly at the enemy death cannons, clogging them with wreckage!")); assertU(adoc("id", "48", "text_sw", "this has gigabyte potential", "foo_i","100")); assertU(adoc("id", "49", "text_sw", "start the big apple end", "foo_i","-100")); - assertU(adoc("id", "50", "text_sw", "start new big city end")); + assertU(adoc("id", "50", "text_sw", "start new big city end")); assertU(adoc("id", "51", "store", "12.34,-56.78")); + assertU(adoc("id", "52", "text_sw", "tekna theou klethomen")); + assertU(adoc("id", "53", "text_sw", "nun tekna theou esmen")); + assertU(adoc("id", "54", "text_sw", "phanera estin ta tekna tou theou")); assertU(commit()); } @Override @@ -63,7 +66,7 @@ public class TestExtendedDismaxParser extends AbstractSolrTestCase { // the super classes version super.tearDown(); } - + // test the edismax query parser based on the dismax parser public void testFocusQueryParser() { String allq = "id:[42 TO 51]"; @@ -294,6 +297,22 @@ public class TestExtendedDismaxParser extends AbstractSolrTestCase { ***/ } + + public void testBoostQuery() { + assertQ( + req("q", "tekna", "qf", "text_sw", "defType", "edismax", "bq", "id:54^100", "bq", "id:53^10", "fq", "id:[52 TO 54]", "fl", "id,score"), + "//doc[1]/str[@name='id'][.='54']", + "//doc[2]/str[@name='id'][.='53']", + "//doc[3]/str[@name='id'][.='52']" + ); + + assertQ( + req("q", "tekna", "qf", "text_sw", "defType", "edismax", "bq", "id:54^-100", "bq", "id:53^10", "bq", "id:52", "fq", "id:[52 TO 54]", "fl", "id,score"), + "//doc[1]/str[@name='id'][.='53']", + "//doc[2]/str[@name='id'][.='52']", + "//doc[3]/str[@name='id'][.='54']" + ); + } public void testUserFields() { String oner = "*[count(//doc)=1]";