lucene-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From da...@apache.org
Subject [22/50] [abbrv] lucene-solr:jira/solr-11702: LUCENE-8099: Replace BoostQParserPlugin.boostQuery() with FunctionScoreQuery.boostByValue()
Date Thu, 11 Jan 2018 08:00:58 GMT
LUCENE-8099: Replace BoostQParserPlugin.boostQuery() with FunctionScoreQuery.boostByValue()


Project: http://git-wip-us.apache.org/repos/asf/lucene-solr/repo
Commit: http://git-wip-us.apache.org/repos/asf/lucene-solr/commit/0744fea8
Tree: http://git-wip-us.apache.org/repos/asf/lucene-solr/tree/0744fea8
Diff: http://git-wip-us.apache.org/repos/asf/lucene-solr/diff/0744fea8

Branch: refs/heads/jira/solr-11702
Commit: 0744fea821366a853b8e239e766b9786ef96cb27
Parents: 3d8ef98
Author: Alan Woodward <romseygeek@apache.org>
Authored: Mon Jan 8 09:51:53 2018 +0000
Committer: Alan Woodward <romseygeek@apache.org>
Committed: Mon Jan 8 10:01:06 2018 +0000

----------------------------------------------------------------------
 .../apache/solr/search/BoostQParserPlugin.java  | 21 +-------------------
 .../solr/search/ExtendedDismaxQParser.java      |  5 +++--
 .../apache/solr/search/ValueSourceParser.java   |  3 ++-
 3 files changed, 6 insertions(+), 23 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/lucene-solr/blob/0744fea8/solr/core/src/java/org/apache/solr/search/BoostQParserPlugin.java
----------------------------------------------------------------------
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 7391f66..70e08a6 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!
-    }
-  }
-
 }

http://git-wip-us.apache.org/repos/asf/lucene-solr/blob/0744fea8/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 5e74f4a..004d1c0 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<ValueSource> 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;

http://git-wip-us.apache.org/repos/asf/lucene-solr/blob/0744fea8/solr/core/src/java/org/apache/solr/search/ValueSourceParser.java
----------------------------------------------------------------------
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 367eb64..450d95a 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() {


Mime
View raw message