From 10acaf02f82f4fc9c08884a7d249658ca6a590c1 Mon Sep 17 00:00:00 2001 From: Alan Woodward Date: Fri, 15 Feb 2019 10:09:11 +0000 Subject: [PATCH] SOLR-13126: Correctly combine multiplicative query boosts --- .../lucene/queries/function/ValueSource.java | 5 ++++- solr/CHANGES.txt | 3 +++ .../org/apache/solr/search/TestQueryTypes.java | 16 ++++++++++++++++ 3 files changed, 23 insertions(+), 1 deletion(-) diff --git a/lucene/queries/src/java/org/apache/lucene/queries/function/ValueSource.java b/lucene/queries/src/java/org/apache/lucene/queries/function/ValueSource.java index 209fb15962d..221e822d1f1 100644 --- a/lucene/queries/src/java/org/apache/lucene/queries/function/ValueSource.java +++ b/lucene/queries/src/java/org/apache/lucene/queries/function/ValueSource.java @@ -216,7 +216,10 @@ public abstract class ValueSource { } else scorer.score = 0; - return fv.exists(doc); + // ValueSource will return values even if exists() is false, generally a default + // of some kind. To preserve this behaviour with the iterator, we need to always + // return 'true' here. + return true; } }; } diff --git a/solr/CHANGES.txt b/solr/CHANGES.txt index b0e4a3f24c8..112d70fa0b4 100644 --- a/solr/CHANGES.txt +++ b/solr/CHANGES.txt @@ -213,6 +213,9 @@ Bug Fixes * SOLR-11774: langid.map.individual now works together with langid.map.keepOrig. Also the detectLanguage() API is changed to accept a Reader allowing for more memory efficient implementations (janhoy) +* SOLR-13126: Query boosts were not being combined correctly for documents where not all boost queries + matched (Alan Woodward, Mikhail Khludnev) + Improvements ---------------------- diff --git a/solr/core/src/test/org/apache/solr/search/TestQueryTypes.java b/solr/core/src/test/org/apache/solr/search/TestQueryTypes.java index ff05e1a22f8..7f9abb5d3d8 100644 --- a/solr/core/src/test/org/apache/solr/search/TestQueryTypes.java +++ b/solr/core/src/test/org/apache/solr/search/TestQueryTypes.java @@ -44,6 +44,11 @@ public class TestQueryTypes extends SolrTestCaseJ4 { assertU(adoc("id","9", "v_s","internal\"quote")); assertU(adoc("id","10","text_no_analyzer","should just work")); + + assertU(adoc("id", "200", "subject_t", "Sony Netzteil")); + assertU(adoc("id", "201", "subject_t", "Other Netzteil")); + assertU(adoc("id", "202", "subject_t", "Other Product")); + Object[] arr = new Object[] { "id",999 ,"v_s","wow dude" @@ -347,6 +352,17 @@ public class TestQueryTypes extends SolrTestCaseJ4 { ,"//doc[./float[@name='v_f']='1.5' and ./float[@name='score']='2.25']" ); + // multiplicative boosts combine correctly + assertQ( + req("q", "{!boost b=$ymb}(+{!lucene v=$yq})", + "ymb", "product(query({!v=subject_t:Netzteil^=2.0},1),query({!v=subject_t:Sony^=3.0},1))", + "yq", "subject_t:*", + "fl", "*,score", "indent", "on"), + "//doc[str[@name='id'][.='200'] and float[@name='score'][.=6.0]]", + "//doc[str[@name='id'][.='202'] and float[@name='score'][.=1.0]]", + "//doc[str[@name='id'][.='201'] and float[@name='score'][.=2.0]]" + ); + // switch queries assertQ("test matching switch query", req("df", "v_t",