From 0744fea821366a853b8e239e766b9786ef96cb27 Mon Sep 17 00:00:00 2001 From: Alan Woodward Date: Mon, 8 Jan 2018 09:51:53 +0000 Subject: [PATCH] LUCENE-8099: Replace BoostQParserPlugin.boostQuery() with FunctionScoreQuery.boostByValue() --- .../solr/search/BoostQParserPlugin.java | 21 +------------------ .../solr/search/ExtendedDismaxQParser.java | 5 +++-- .../apache/solr/search/ValueSourceParser.java | 3 ++- 3 files changed, 6 insertions(+), 23 deletions(-) diff --git a/solr/core/src/java/org/apache/solr/search/BoostQParserPlugin.java b/solr/core/src/java/org/apache/solr/search/BoostQParserPlugin.java index 7391f660ede..70e08a6728c 100644 --- a/solr/core/src/java/org/apache/solr/search/BoostQParserPlugin.java +++ b/solr/core/src/java/org/apache/solr/search/BoostQParserPlugin.java @@ -16,18 +16,11 @@ */ package org.apache.solr.search; -import java.text.ParseException; - -import org.apache.lucene.expressions.Expression; -import org.apache.lucene.expressions.SimpleBindings; -import org.apache.lucene.expressions.js.JavascriptCompiler; import org.apache.lucene.queries.function.FunctionQuery; import org.apache.lucene.queries.function.FunctionScoreQuery; import org.apache.lucene.queries.function.ValueSource; import org.apache.lucene.queries.function.valuesource.QueryValueSource; -import org.apache.lucene.search.DoubleValuesSource; import org.apache.lucene.search.Query; -import org.apache.solr.common.SolrException; import org.apache.solr.common.params.SolrParams; import org.apache.solr.common.util.NamedList; import org.apache.solr.request.SolrQueryRequest; @@ -67,7 +60,7 @@ public class BoostQParserPlugin extends QParserPlugin { } else { vs = new QueryValueSource(bq, 0.0f); } - return boostQuery(q, vs); + return FunctionScoreQuery.boostByValue(q, vs.asDoubleValuesSource()); } @@ -91,16 +84,4 @@ public class BoostQParserPlugin extends QParserPlugin { }; } - public static Query boostQuery(Query input, ValueSource vs) { - try { - SimpleBindings bindings = new SimpleBindings(); - bindings.add("score", DoubleValuesSource.SCORES); - bindings.add("vs", vs.asDoubleValuesSource()); - Expression expr = JavascriptCompiler.compile("score * vs"); - return new FunctionScoreQuery(input, expr.getDoubleValuesSource(bindings)); - } catch (ParseException e) { - throw new SolrException(SolrException.ErrorCode.SERVER_ERROR, e); // should never happen! - } - } - } 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 5e74f4a5dc4..004d1c042af 100644 --- a/solr/core/src/java/org/apache/solr/search/ExtendedDismaxQParser.java +++ b/solr/core/src/java/org/apache/solr/search/ExtendedDismaxQParser.java @@ -34,6 +34,7 @@ import org.apache.lucene.analysis.core.StopFilterFactory; import org.apache.lucene.analysis.util.TokenFilterFactory; import org.apache.lucene.index.Term; import org.apache.lucene.queries.function.FunctionQuery; +import org.apache.lucene.queries.function.FunctionScoreQuery; import org.apache.lucene.queries.function.ValueSource; import org.apache.lucene.queries.function.valuesource.ProductFloatFunction; import org.apache.lucene.queries.function.valuesource.QueryValueSource; @@ -196,9 +197,9 @@ public class ExtendedDismaxQParser extends QParser { List boosts = getMultiplicativeBoosts(); if (boosts.size()>1) { ValueSource prod = new ProductFloatFunction(boosts.toArray(new ValueSource[boosts.size()])); - topQuery = BoostQParserPlugin.boostQuery(topQuery, prod); + topQuery = FunctionScoreQuery.boostByValue(topQuery, prod.asDoubleValuesSource()); } else if (boosts.size() == 1) { - topQuery = BoostQParserPlugin.boostQuery(topQuery, boosts.get(0)); + topQuery = FunctionScoreQuery.boostByValue(topQuery, boosts.get(0).asDoubleValuesSource()); } return topQuery; diff --git a/solr/core/src/java/org/apache/solr/search/ValueSourceParser.java b/solr/core/src/java/org/apache/solr/search/ValueSourceParser.java index 367eb641ba0..450d95a7aff 100644 --- a/solr/core/src/java/org/apache/solr/search/ValueSourceParser.java +++ b/solr/core/src/java/org/apache/solr/search/ValueSourceParser.java @@ -27,6 +27,7 @@ import java.util.Map; import org.apache.lucene.index.LeafReaderContext; import org.apache.lucene.index.Term; +import org.apache.lucene.queries.function.FunctionScoreQuery; import org.apache.lucene.queries.function.FunctionValues; import org.apache.lucene.queries.function.ValueSource; import org.apache.lucene.queries.function.docvalues.BoolDocValues; @@ -325,7 +326,7 @@ public abstract class ValueSourceParser implements NamedListInitializedPlugin { public ValueSource parse(FunctionQParser fp) throws SyntaxError { Query q = fp.parseNestedQuery(); ValueSource vs = fp.parseValueSource(); - return new QueryValueSource(BoostQParserPlugin.boostQuery(q, vs), 0.0f); + return new QueryValueSource(FunctionScoreQuery.boostByValue(q, vs.asDoubleValuesSource()), 0.0f); } }); addParser("joindf", new ValueSourceParser() {