SOLR-3278: Negative boost support to the Extended Dismax Query Parser Boost Query

git-svn-id: https://svn.apache.org/repos/asf/lucene/dev/trunk@1305908 13f79535-47bb-0310-9956-ffa450edef68
This commit is contained in:
James Dyer 2012-03-27 17:16:10 +00:00
parent ce1cead6eb
commit aed1330b54
3 changed files with 32 additions and 6 deletions

View File

@ -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
----------------------

View File

@ -344,13 +344,17 @@ class ExtendedDismaxQParser extends QParser {
/* * * Boosting Query * * */
boostParams = solrParams.getParams(DisMaxParams.BQ);
//List<Query> boostQueries = U.parseQueryStrings(req, boostParams);
boostQueries=null;
if (boostParams!=null && boostParams.length>0) {
Map<String,Float> bqBoosts = SolrPluginUtils.parseFieldBoosts(boostParams);
boostQueries = new ArrayList<Query>();
for (String qs : boostParams) {
if (qs.trim().length()==0) continue;
Query q = subQuery(qs, null).getQuery();
for (Map.Entry<String,Float> 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);
}
}

View File

@ -55,6 +55,9 @@ public class TestExtendedDismaxParser extends AbstractSolrTestCase {
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", "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
@ -295,6 +298,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]";
String nor = "*[count(//doc)=0]";