lucene-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From cpoersc...@apache.org
Subject [1/4] lucene-solr:master: SOLR-9574: Factor out AbstractReRankQuery from ReRankQParserPlugin's private ReRankQuery.
Date Fri, 30 Sep 2016 14:06:51 GMT
Repository: lucene-solr
Updated Branches:
  refs/heads/master f13b72721 -> 08a5951ad


SOLR-9574: Factor out AbstractReRankQuery from ReRankQParserPlugin's private ReRankQuery.


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

Branch: refs/heads/master
Commit: dbc29c0adc232636d442c6726ae27f07bdbf75e3
Parents: ff35924
Author: Christine Poerschke <cpoerschke@apache.org>
Authored: Wed Sep 28 18:49:37 2016 +0100
Committer: Christine Poerschke <cpoerschke@apache.org>
Committed: Fri Sep 30 13:47:27 2016 +0100

----------------------------------------------------------------------
 solr/CHANGES.txt                                |  2 +
 .../apache/solr/search/AbstractReRankQuery.java | 83 ++++++++++++++++++++
 .../apache/solr/search/ReRankQParserPlugin.java | 56 +------------
 3 files changed, 89 insertions(+), 52 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/lucene-solr/blob/dbc29c0a/solr/CHANGES.txt
----------------------------------------------------------------------
diff --git a/solr/CHANGES.txt b/solr/CHANGES.txt
index d9a14de..bd2f07e 100644
--- a/solr/CHANGES.txt
+++ b/solr/CHANGES.txt
@@ -226,6 +226,8 @@ Other Changes
 * SOLR-9576: Make FieldAnalysisRequestHandler, DocumentAnalysisRequestHandler & DumpRequestHandler
   implicit (noble)
 
+* SOLR-9574: Factor out AbstractReRankQuery from ReRankQParserPlugin's private ReRankQuery.
(Christine Poerschke)
+
 ==================  6.2.1 ==================
 
 Bug Fixes

http://git-wip-us.apache.org/repos/asf/lucene-solr/blob/dbc29c0a/solr/core/src/java/org/apache/solr/search/AbstractReRankQuery.java
----------------------------------------------------------------------
diff --git a/solr/core/src/java/org/apache/solr/search/AbstractReRankQuery.java b/solr/core/src/java/org/apache/solr/search/AbstractReRankQuery.java
new file mode 100644
index 0000000..cc32761
--- /dev/null
+++ b/solr/core/src/java/org/apache/solr/search/AbstractReRankQuery.java
@@ -0,0 +1,83 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License.  You may obtain a copy of the License at
+ *
+ *     http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.apache.solr.search;
+
+import java.io.IOException;
+import java.util.Map;
+
+import org.apache.lucene.index.IndexReader;
+import org.apache.lucene.search.IndexSearcher;
+import org.apache.lucene.search.Query;
+import org.apache.lucene.search.Rescorer;
+import org.apache.lucene.search.TopDocsCollector;
+import org.apache.lucene.search.Weight;
+import org.apache.lucene.util.BytesRef;
+import org.apache.solr.handler.component.MergeStrategy;
+import org.apache.solr.handler.component.QueryElevationComponent;
+import org.apache.solr.request.SolrRequestInfo;
+
+public abstract class AbstractReRankQuery extends RankQuery {
+  protected Query mainQuery;
+  final protected int reRankDocs;
+  final protected Rescorer reRankQueryRescorer;
+  protected Map<BytesRef, Integer> boostedPriority;
+
+  public AbstractReRankQuery(Query mainQuery, int reRankDocs, Rescorer reRankQueryRescorer)
{
+    this.mainQuery = mainQuery;
+    this.reRankDocs = reRankDocs;
+    this.reRankQueryRescorer = reRankQueryRescorer;
+  }
+
+  public RankQuery wrap(Query _mainQuery) {
+    if(_mainQuery != null){
+      this.mainQuery = _mainQuery;
+    }
+    return  this;
+  }
+
+  public MergeStrategy getMergeStrategy() {
+    return null;
+  }
+
+  public TopDocsCollector getTopDocsCollector(int len, QueryCommand cmd, IndexSearcher searcher)
throws IOException {
+
+    if(this.boostedPriority == null) {
+      SolrRequestInfo info = SolrRequestInfo.getRequestInfo();
+      if(info != null) {
+        Map context = info.getReq().getContext();
+        this.boostedPriority = (Map<BytesRef, Integer>)context.get(QueryElevationComponent.BOOSTED_PRIORITY);
+      }
+    }
+
+    return new ReRankCollector(reRankDocs, len, reRankQueryRescorer, cmd, searcher, boostedPriority);
+  }
+
+  public Query rewrite(IndexReader reader) throws IOException {
+    Query q = mainQuery.rewrite(reader);
+    if (q != mainQuery) {
+      return rewrite(q);
+    }
+    return super.rewrite(reader);
+  }
+
+  protected abstract Query rewrite(Query rewrittenMainQuery) throws IOException;
+
+  public Weight createWeight(IndexSearcher searcher, boolean needsScores, float boost) throws
IOException{
+    final Weight mainWeight = mainQuery.createWeight(searcher, needsScores, boost);
+    return new ReRankWeight(mainQuery, reRankQueryRescorer, searcher, mainWeight);
+  }
+}

http://git-wip-us.apache.org/repos/asf/lucene-solr/blob/dbc29c0a/solr/core/src/java/org/apache/solr/search/ReRankQParserPlugin.java
----------------------------------------------------------------------
diff --git a/solr/core/src/java/org/apache/solr/search/ReRankQParserPlugin.java b/solr/core/src/java/org/apache/solr/search/ReRankQParserPlugin.java
index fab39d6..3e8bf86 100644
--- a/solr/core/src/java/org/apache/solr/search/ReRankQParserPlugin.java
+++ b/solr/core/src/java/org/apache/solr/search/ReRankQParserPlugin.java
@@ -17,23 +17,13 @@
 package org.apache.solr.search;
 
 import java.io.IOException;
-import java.util.Map;
 
-import org.apache.lucene.index.IndexReader;
-import org.apache.lucene.search.IndexSearcher;
 import org.apache.lucene.search.MatchAllDocsQuery;
 import org.apache.lucene.search.Query;
 import org.apache.lucene.search.QueryRescorer;
-import org.apache.lucene.search.Rescorer;
-import org.apache.lucene.search.TopDocsCollector;
-import org.apache.lucene.search.Weight;
-import org.apache.lucene.util.BytesRef;
 import org.apache.solr.common.SolrException;
 import org.apache.solr.common.params.SolrParams;
-import org.apache.solr.handler.component.MergeStrategy;
-import org.apache.solr.handler.component.QueryElevationComponent;
 import org.apache.solr.request.SolrQueryRequest;
-import org.apache.solr.request.SolrRequestInfo;
 
 /*
 *
@@ -100,13 +90,9 @@ public class ReRankQParserPlugin extends QParserPlugin {
     }
   }
 
-  private final class ReRankQuery extends RankQuery {
-    private Query mainQuery = defaultQuery;
+  private final class ReRankQuery extends AbstractReRankQuery {
     final private Query reRankQuery;
-    final private int reRankDocs;
     final private double reRankWeight;
-    final private Rescorer reRankQueryRescorer;
-    private Map<BytesRef, Integer> boostedPriority;
 
     public int hashCode() {
       return 31 * classHash() + mainQuery.hashCode()+reRankQuery.hashCode()+(int)reRankWeight+reRankDocs;
@@ -125,34 +111,9 @@ public class ReRankQParserPlugin extends QParserPlugin {
     }
 
     public ReRankQuery(Query reRankQuery, int reRankDocs, double reRankWeight) {
+      super(defaultQuery, reRankDocs, new ReRankQueryRescorer(reRankQuery, reRankWeight));
       this.reRankQuery = reRankQuery;
-      this.reRankDocs = reRankDocs;
       this.reRankWeight = reRankWeight;
-      this.reRankQueryRescorer = new ReRankQueryRescorer(reRankQuery, reRankWeight);
-    }
-
-    public RankQuery wrap(Query _mainQuery) {
-      if(_mainQuery != null){
-        this.mainQuery = _mainQuery;
-      }
-      return  this;
-    }
-
-    public MergeStrategy getMergeStrategy() {
-      return null;
-    }
-
-    public TopDocsCollector getTopDocsCollector(int len, QueryCommand cmd, IndexSearcher
searcher) throws IOException {
-
-      if(this.boostedPriority == null) {
-        SolrRequestInfo info = SolrRequestInfo.getRequestInfo();
-        if(info != null) {
-          Map context = info.getReq().getContext();
-          this.boostedPriority = (Map<BytesRef, Integer>)context.get(QueryElevationComponent.BOOSTED_PRIORITY);
-        }
-      }
-
-      return new ReRankCollector(reRankDocs, len, reRankQueryRescorer, cmd, searcher, boostedPriority);
     }
 
     @Override
@@ -166,17 +127,8 @@ public class ReRankQParserPlugin extends QParserPlugin {
       return sb.toString();
     }
 
-    public Query rewrite(IndexReader reader) throws IOException {
-      Query q = mainQuery.rewrite(reader);
-      if (q != mainQuery) {
-        return new ReRankQuery(reRankQuery, reRankDocs, reRankWeight).wrap(q);
-      }
-      return super.rewrite(reader);
-    }
-
-    public Weight createWeight(IndexSearcher searcher, boolean needsScores, float boost)
throws IOException{
-      final Weight mainWeight = mainQuery.createWeight(searcher, needsScores, boost);
-      return new ReRankWeight(mainQuery, reRankQueryRescorer, searcher, mainWeight);
+    protected Query rewrite(Query rewrittenMainQuery) throws IOException {
+      return new ReRankQuery(reRankQuery, reRankDocs, reRankWeight).wrap(rewrittenMainQuery);
     }
   }
 }


Mime
View raw message