mirror of https://github.com/apache/lucene.git
LUCENE-8099: Replace BoostQParserPlugin.boostQuery() with FunctionScoreQuery.boostByValue()
This commit is contained in:
parent
3d8ef981cb
commit
0744fea821
|
@ -16,18 +16,11 @@
|
||||||
*/
|
*/
|
||||||
package org.apache.solr.search;
|
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.FunctionQuery;
|
||||||
import org.apache.lucene.queries.function.FunctionScoreQuery;
|
import org.apache.lucene.queries.function.FunctionScoreQuery;
|
||||||
import org.apache.lucene.queries.function.ValueSource;
|
import org.apache.lucene.queries.function.ValueSource;
|
||||||
import org.apache.lucene.queries.function.valuesource.QueryValueSource;
|
import org.apache.lucene.queries.function.valuesource.QueryValueSource;
|
||||||
import org.apache.lucene.search.DoubleValuesSource;
|
|
||||||
import org.apache.lucene.search.Query;
|
import org.apache.lucene.search.Query;
|
||||||
import org.apache.solr.common.SolrException;
|
|
||||||
import org.apache.solr.common.params.SolrParams;
|
import org.apache.solr.common.params.SolrParams;
|
||||||
import org.apache.solr.common.util.NamedList;
|
import org.apache.solr.common.util.NamedList;
|
||||||
import org.apache.solr.request.SolrQueryRequest;
|
import org.apache.solr.request.SolrQueryRequest;
|
||||||
|
@ -67,7 +60,7 @@ public class BoostQParserPlugin extends QParserPlugin {
|
||||||
} else {
|
} else {
|
||||||
vs = new QueryValueSource(bq, 0.0f);
|
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!
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -34,6 +34,7 @@ import org.apache.lucene.analysis.core.StopFilterFactory;
|
||||||
import org.apache.lucene.analysis.util.TokenFilterFactory;
|
import org.apache.lucene.analysis.util.TokenFilterFactory;
|
||||||
import org.apache.lucene.index.Term;
|
import org.apache.lucene.index.Term;
|
||||||
import org.apache.lucene.queries.function.FunctionQuery;
|
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;
|
||||||
import org.apache.lucene.queries.function.valuesource.ProductFloatFunction;
|
import org.apache.lucene.queries.function.valuesource.ProductFloatFunction;
|
||||||
import org.apache.lucene.queries.function.valuesource.QueryValueSource;
|
import org.apache.lucene.queries.function.valuesource.QueryValueSource;
|
||||||
|
@ -196,9 +197,9 @@ public class ExtendedDismaxQParser extends QParser {
|
||||||
List<ValueSource> boosts = getMultiplicativeBoosts();
|
List<ValueSource> boosts = getMultiplicativeBoosts();
|
||||||
if (boosts.size()>1) {
|
if (boosts.size()>1) {
|
||||||
ValueSource prod = new ProductFloatFunction(boosts.toArray(new ValueSource[boosts.size()]));
|
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) {
|
} else if (boosts.size() == 1) {
|
||||||
topQuery = BoostQParserPlugin.boostQuery(topQuery, boosts.get(0));
|
topQuery = FunctionScoreQuery.boostByValue(topQuery, boosts.get(0).asDoubleValuesSource());
|
||||||
}
|
}
|
||||||
|
|
||||||
return topQuery;
|
return topQuery;
|
||||||
|
|
|
@ -27,6 +27,7 @@ import java.util.Map;
|
||||||
|
|
||||||
import org.apache.lucene.index.LeafReaderContext;
|
import org.apache.lucene.index.LeafReaderContext;
|
||||||
import org.apache.lucene.index.Term;
|
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.FunctionValues;
|
||||||
import org.apache.lucene.queries.function.ValueSource;
|
import org.apache.lucene.queries.function.ValueSource;
|
||||||
import org.apache.lucene.queries.function.docvalues.BoolDocValues;
|
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 {
|
public ValueSource parse(FunctionQParser fp) throws SyntaxError {
|
||||||
Query q = fp.parseNestedQuery();
|
Query q = fp.parseNestedQuery();
|
||||||
ValueSource vs = fp.parseValueSource();
|
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() {
|
addParser("joindf", new ValueSourceParser() {
|
||||||
|
|
Loading…
Reference in New Issue