Apache Solr open-source search software
SOLR-3828: Fixed QueryElevationComponent so that using 'markExcludes' does not modify the result set or ranking of 'excluded' documents relative to not using elevation at all
Chris M. Hostetter5e1ed1e87a72
diff --git a/solr/CHANGES.txt b/solr/CHANGES.txtindex 08a005ea370..629534c595f 100644--- a/solr/CHANGES.txt+++ b/solr/CHANGES.txt@@ -158,6 +158,11 @@ Bug Fixes* SOLR-3809: Fixed config file replication when subdirectories are used(Emmanuel Espina via hossman)+* SOLR-3828: Fixed QueryElevationComponent so that using 'markExcludes' does+ not modify the result set or ranking of 'excluded' documents relative to+ not using elevation at all. (Alexey Serba via hossman)++Other Changes----------------------diff --git a/solr/core/src/java/org/apache/solr/handler/component/QueryElevationComponent.java b/solr/core/src/java/org/apache/solr/handler/component/QueryElevationComponent.javaindex 357cd17f11e..fd9931886b1 100644--- a/solr/core/src/java/org/apache/solr/handler/component/QueryElevationComponent.java+++ b/solr/core/src/java/org/apache/solr/handler/component/QueryElevationComponent.java@@ -385,9 +385,6 @@ public class QueryElevationComponent extends SearchComponent implements SolrCore//we are only going to mark items as excluded, not actually exclude them. This works//with the EditorialMarkerFactoryrb.req.getContext().put(EXCLUDED, booster.excludeIds);- for (TermQuery tq : booster.exclude) {- newq.add(new BooleanClause(tq, BooleanClause.Occur.SHOULD));- }}}rb.setQuery(newq);diff --git a/solr/core/src/test-files/solr/collection1/conf/elevate.xml b/solr/core/src/test-files/solr/collection1/conf/elevate.xmlindex d15bd5eb6fc..1befc5443e7 100644--- a/solr/core/src/test-files/solr/collection1/conf/elevate.xml+++ b/solr/core/src/test-files/solr/collection1/conf/elevate.xml@@ -41,6 +41,11 @@<doc id="5" /><doc id="6" exclude="true" /></query>++ <query text="QQQQ">+ <doc id="10" exclude="true" />+ </query>+<query text="solr"><doc id="7" />diff --git a/solr/core/src/test/org/apache/solr/handler/component/QueryElevationComponentTest.java b/solr/core/src/test/org/apache/solr/handler/component/QueryElevationComponentTest.javaindex 175e39f9fa2..66982fb2263 100644--- a/solr/core/src/test/org/apache/solr/handler/component/QueryElevationComponentTest.java+++ b/solr/core/src/test/org/apache/solr/handler/component/QueryElevationComponentTest.java@@ -159,7 +159,7 @@ public class QueryElevationComponentTest extends SolrTestCaseJ4 {req.close();// Make sure the boosts loaded properly- assertEquals(6, map.size());+ assertEquals(7, map.size());assertEquals(1, map.get("XXXX").priority.size());assertEquals(2, map.get("YYYY").priority.size());assertEquals(3, map.get("ZZZZ").priority.size());@@ -176,7 +176,7 @@ public class QueryElevationComponentTest extends SolrTestCaseJ4 {comp.init(args);comp.inform(core);map = comp.getElevationMap(reader, core);- assertEquals(6, map.size());+ assertEquals(7, map.size());assertEquals(null, map.get("XXXX"));assertEquals(null, map.get("YYYY"));assertEquals(null, map.get("ZZZZ"));@@ -251,21 +251,28 @@ public class QueryElevationComponentTest extends SolrTestCaseJ4 {assertU(adoc("id", "5", "title", "YYYY YYYY", "str_s1", "y"));assertU(adoc("id", "6", "title", "XXXX XXXX", "str_s1", "z"));assertU(adoc("id", "7", "title", "AAAA", "str_s1", "a"));++ assertU(adoc("id", "8", "title", "QQQQ", "str_s1", "q"));+ assertU(adoc("id", "9", "title", "QQQQ QQQQ", "str_s1", "r"));+ assertU(adoc("id", "10", "title", "QQQQ QQQQ QQQQ", "str_s1", "s"));+assertU(commit());assertQ("", req(CommonParams.Q, "XXXX XXXX", CommonParams.QT, "/elevate",QueryElevationParams.MARK_EXCLUDES, "true",+ "indent", "true",CommonParams.FL, "id, score, [excluded]"), "//*[@numFound='4']", "//result/doc[1]/str[@name='id'][.='5']"- , "//result/doc[2]/str[@name='id'][.='6']"- , "//result/doc[3]/str[@name='id'][.='1']"- , "//result/doc[4]/str[@name='id'][.='4']",+ , "//result/doc[2]/str[@name='id'][.='1']"+ , "//result/doc[3]/str[@name='id'][.='4']"+ , "//result/doc[4]/str[@name='id'][.='6']","//result/doc[1]/bool[@name='[excluded]'][.='false']",- "//result/doc[2]/bool[@name='[excluded]'][.='true']",+ "//result/doc[2]/bool[@name='[excluded]'][.='false']","//result/doc[3]/bool[@name='[excluded]'][.='false']",- "//result/doc[4]/bool[@name='[excluded]'][.='false']"+ "//result/doc[4]/bool[@name='[excluded]'][.='true']");+//ask for excluded as a field, but don't actually request the MARK_EXCLUDES//thus, number 6 should not be returned, b/c it is excludedassertQ("", req(CommonParams.Q, "XXXX XXXX", CommonParams.QT, "/elevate",@@ -279,7 +286,32 @@ public class QueryElevationComponentTest extends SolrTestCaseJ4 {"//result/doc[2]/bool[@name='[excluded]'][.='false']","//result/doc[3]/bool[@name='[excluded]'][.='false']");-++ // test that excluded results are on the same positions in the result list+ // as when elevation component is disabled+ // (i.e. test that elevation component with MARK_EXCLUDES does not boost+ // excluded results)+ assertQ("", req(CommonParams.Q, "QQQQ", CommonParams.QT, "/elevate",+ QueryElevationParams.ENABLE, "false",+ "indent", "true",+ CommonParams.FL, "id, score")+ , "//*[@numFound='3']"+ , "//result/doc[1]/str[@name='id'][.='8']"+ , "//result/doc[2]/str[@name='id'][.='9']"+ , "//result/doc[3]/str[@name='id'][.='10']"+ );+ assertQ("", req(CommonParams.Q, "QQQQ", CommonParams.QT, "/elevate",+ QueryElevationParams.MARK_EXCLUDES, "true",+ "indent", "true",+ CommonParams.FL, "id, score, [excluded]")+ , "//*[@numFound='3']"+ , "//result/doc[1]/str[@name='id'][.='8']"+ , "//result/doc[2]/str[@name='id'][.='9']"+ , "//result/doc[3]/str[@name='id'][.='10']",+ "//result/doc[1]/bool[@name='[excluded]'][.='false']",+ "//result/doc[2]/bool[@name='[excluded]'][.='false']",+ "//result/doc[3]/bool[@name='[excluded]'][.='true']"+ );} finally {delete();}