You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@lucene.apache.org by sa...@apache.org on 2017/04/19 23:03:16 UTC
lucene-solr:branch_6x: SOLR-10527: edismax with sow=false fails to
create dismax-per-term queries when any field is boosted
Repository: lucene-solr
Updated Branches:
refs/heads/branch_6x 4b30834bc -> 141961b00
SOLR-10527: edismax with sow=false fails to create dismax-per-term queries when any field is boosted
Project: http://git-wip-us.apache.org/repos/asf/lucene-solr/repo
Commit: http://git-wip-us.apache.org/repos/asf/lucene-solr/commit/141961b0
Tree: http://git-wip-us.apache.org/repos/asf/lucene-solr/tree/141961b0
Diff: http://git-wip-us.apache.org/repos/asf/lucene-solr/diff/141961b0
Branch: refs/heads/branch_6x
Commit: 141961b00a062422b078b327ba334978ad97604e
Parents: 4b30834
Author: Steve Rowe <sa...@gmail.com>
Authored: Wed Apr 19 19:02:32 2017 -0400
Committer: Steve Rowe <sa...@gmail.com>
Committed: Wed Apr 19 19:02:59 2017 -0400
----------------------------------------------------------------------
solr/CHANGES.txt | 3 ++
.../solr/search/ExtendedDismaxQParser.java | 55 +++++++++++++++++---
.../solr/search/TestExtendedDismaxParser.java | 23 ++++++++
3 files changed, 73 insertions(+), 8 deletions(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/lucene-solr/blob/141961b0/solr/CHANGES.txt
----------------------------------------------------------------------
diff --git a/solr/CHANGES.txt b/solr/CHANGES.txt
index 8337db5..3a2fde4 100644
--- a/solr/CHANGES.txt
+++ b/solr/CHANGES.txt
@@ -113,6 +113,9 @@ Bug Fixes
* SOLR-10047: Mismatched Docvalues segments cause exception in Sorting/Faceting. Solr now uninverts per segment
to avoid such exceptions. (Keith Laban via shalin)
+
+* SOLR-10527: edismax with sow=false fails to create dismax-per-term queries when any field is boosted.
+ (Steve Rowe)
* SOLR-10472: Fixed uninversion (aka: FieldCache) bugs with the numeric PointField classes, and CurrencyField (hossman)
http://git-wip-us.apache.org/repos/asf/lucene-solr/blob/141961b0/solr/core/src/java/org/apache/solr/search/ExtendedDismaxQParser.java
----------------------------------------------------------------------
diff --git a/solr/core/src/java/org/apache/solr/search/ExtendedDismaxQParser.java b/solr/core/src/java/org/apache/solr/search/ExtendedDismaxQParser.java
index d938151..f5c84f9 100644
--- a/solr/core/src/java/org/apache/solr/search/ExtendedDismaxQParser.java
+++ b/solr/core/src/java/org/apache/solr/search/ExtendedDismaxQParser.java
@@ -1065,7 +1065,7 @@ public class ExtendedDismaxQParser extends QParser {
this.val = null;
this.vals = queryTerms;
this.slop = getPhraseSlop();
- return getAliasedMultiTermQuery(queryTerms);
+ return getAliasedMultiTermQuery();
}
@Override
@@ -1192,11 +1192,11 @@ public class ExtendedDismaxQParser extends QParser {
* DisjunctionMaxQuery. (so yes: aliases which point at other
* aliases should work)
*/
- protected Query getAliasedMultiTermQuery(List<String> queryTerms) throws SyntaxError {
+ protected Query getAliasedMultiTermQuery() throws SyntaxError {
Alias a = aliases.get(field);
this.validateCyclicAliasing(field);
if (a != null) {
- List<Query> lst = getQueries(a);
+ List<Query> lst = getMultiTermQueries(a);
if (lst == null || lst.size() == 0) {
return getQuery();
}
@@ -1207,14 +1207,25 @@ public class ExtendedDismaxQParser extends QParser {
// DisMaxQuery.rewrite() removes itself if there is just a single clause anyway.
// if (lst.size()==1) return lst.get(0);
if (makeDismax) {
- if (lst.get(0) instanceof BooleanQuery && allSameQueryStructure(lst)) {
+ Query firstQuery = lst.get(0);
+ if ((firstQuery instanceof BooleanQuery
+ || (firstQuery instanceof BoostQuery && ((BoostQuery)firstQuery).getQuery() instanceof BooleanQuery))
+ && allSameQueryStructure(lst)) {
BooleanQuery.Builder q = new BooleanQuery.Builder();
List<Query> subs = new ArrayList<>(lst.size());
- for (int c = 0 ; c < ((BooleanQuery)lst.get(0)).clauses().size() ; ++c) {
+ BooleanQuery firstBooleanQuery = firstQuery instanceof BoostQuery
+ ? (BooleanQuery)((BoostQuery)firstQuery).getQuery() : (BooleanQuery)firstQuery;
+ for (int c = 0 ; c < firstBooleanQuery.clauses().size() ; ++c) {
subs.clear();
// Make a dismax query for each clause position in the boolean per-field queries.
for (int n = 0 ; n < lst.size() ; ++n) {
- subs.add(((BooleanQuery)lst.get(n)).clauses().get(c).getQuery());
+ if (lst.get(n) instanceof BoostQuery) {
+ BoostQuery boostQuery = (BoostQuery)lst.get(n);
+ BooleanQuery booleanQuery = (BooleanQuery)boostQuery.getQuery();
+ subs.add(new BoostQuery(booleanQuery.clauses().get(c).getQuery(), boostQuery.getBoost()));
+ } else {
+ subs.add(((BooleanQuery)lst.get(n)).clauses().get(c).getQuery());
+ }
}
q.add(newBooleanClause(new DisjunctionMaxQuery(subs, a.tie), BooleanClause.Occur.SHOULD));
}
@@ -1243,12 +1254,21 @@ public class ExtendedDismaxQParser extends QParser {
}
}
- /** Recursively examines the given query list for identical structure in all queries. */
+ /**
+ * Recursively examines the given query list for identical structure in all queries.
+ * Boosts on BoostQuery-s are ignored, and the contained queries are instead used as the basis for comparison.
+ **/
private boolean allSameQueryStructure(List<Query> lst) {
boolean allSame = true;
Query firstQuery = lst.get(0);
+ if (firstQuery instanceof BoostQuery) {
+ firstQuery = ((BoostQuery)firstQuery).getQuery(); // ignore boost; compare contained query
+ }
for (int n = 1 ; n < lst.size(); ++n) {
Query nthQuery = lst.get(n);
+ if (nthQuery instanceof BoostQuery) {
+ nthQuery = ((BoostQuery)nthQuery).getQuery();
+ }
if (nthQuery.getClass() != firstQuery.getClass()) {
allSame = false;
break;
@@ -1354,7 +1374,26 @@ public class ExtendedDismaxQParser extends QParser {
}
return lst;
}
-
+
+ protected List<Query> getMultiTermQueries(Alias a) throws SyntaxError {
+ if (a == null) return null;
+ if (a.fields.size()==0) return null;
+ List<Query> lst= new ArrayList<>(4);
+
+ for (String f : a.fields.keySet()) {
+ this.field = f;
+ Query sub = getAliasedMultiTermQuery();
+ if (sub != null) {
+ Float boost = a.fields.get(f);
+ if (boost != null && boost.floatValue() != 1f) {
+ sub = new BoostQuery(sub, boost);
+ }
+ lst.add(sub);
+ }
+ }
+ return lst;
+ }
+
private Query getQuery() {
try {
http://git-wip-us.apache.org/repos/asf/lucene-solr/blob/141961b0/solr/core/src/test/org/apache/solr/search/TestExtendedDismaxParser.java
----------------------------------------------------------------------
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 6c7b0cf..61c9a65 100644
--- a/solr/core/src/test/org/apache/solr/search/TestExtendedDismaxParser.java
+++ b/solr/core/src/test/org/apache/solr/search/TestExtendedDismaxParser.java
@@ -1820,6 +1820,29 @@ public class TestExtendedDismaxParser extends SolrTestCaseJ4 {
}
}
}
+
+ public void testSowFalseWithBoost() throws Exception {
+ try (SolrQueryRequest req = req("sow", "false", "qf", "subject title")) {
+ QParser qParser = QParser.getParser("one two", "edismax", req);
+ Query q = qParser.getQuery();
+ assertEquals("+((title:one | subject:on) (title:two | subject:two))", q.toString());
+ }
+ try (SolrQueryRequest req = req("sow", "false", "qf", "subject title^5")) {
+ QParser qParser = QParser.getParser("one two", "edismax", req);
+ Query q = qParser.getQuery();
+ assertEquals("+(((title:one)^5.0 | subject:on) ((title:two)^5.0 | subject:two))", q.toString());
+ }
+ try (SolrQueryRequest req = req("sow", "false", "qf", "subject^3 title")) {
+ QParser qParser = QParser.getParser("one two", "edismax", req);
+ Query q = qParser.getQuery();
+ assertEquals("+((title:one | (subject:on)^3.0) (title:two | (subject:two)^3.0))", q.toString());
+ }
+ try (SolrQueryRequest req = req("sow", "false", "qf", "subject^10 title^20")) {
+ QParser qParser = QParser.getParser("one two", "edismax", req);
+ Query q = qParser.getQuery();
+ assertEquals("+(((title:one)^20.0 | (subject:on)^10.0) ((title:two)^20.0 | (subject:two)^10.0))", q.toString());
+ }
+ }
private boolean containsClause(Query query, String field, String value,