lucene-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From a.@apache.org
Subject [08/35] lucene-solr:jira/solr-11779: SOLR-12375: Optimize Lucene ScoreMode use: * A non-cached filter query could be told incorrectly that scores were needed. * The /export (ExportQParserPlugin) would declare incorrectly that scores are needed. * Expande
Date Mon, 28 May 2018 15:39:51 GMT
SOLR-12375: Optimize Lucene ScoreMode use:
* A non-cached filter query could be told incorrectly that scores were needed.
* The /export (ExportQParserPlugin) would declare incorrectly that scores are needed.
* Expanded docs (expand component) could be told incorrectly that scores are needed.


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

Branch: refs/heads/jira/solr-11779
Commit: 53a3de3b98a5a06146a33251c176b7e4475270e4
Parents: d32ce81
Author: David Smiley <dsmiley@apache.org>
Authored: Wed May 23 15:37:33 2018 -0400
Committer: David Smiley <dsmiley@apache.org>
Committed: Wed May 23 15:37:33 2018 -0400

----------------------------------------------------------------------
 solr/CHANGES.txt                                |  5 ++++
 .../solr/handler/component/ExpandComponent.java | 23 ++++++++-------
 .../apache/solr/search/ExportQParserPlugin.java | 30 +++++++++++++-------
 .../org/apache/solr/search/ReRankCollector.java |  3 +-
 .../apache/solr/search/SolrIndexSearcher.java   |  4 +--
 5 files changed, 40 insertions(+), 25 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/lucene-solr/blob/53a3de3b/solr/CHANGES.txt
----------------------------------------------------------------------
diff --git a/solr/CHANGES.txt b/solr/CHANGES.txt
index 9ec2de3..761d06d 100644
--- a/solr/CHANGES.txt
+++ b/solr/CHANGES.txt
@@ -256,6 +256,11 @@ Optimizations
 * SOLR-11880: Avoid creating new exceptions for every request made to MDCAwareThreadPoolExecutor
by distributed
   search and update operations. (Varun Thacker, shalin)
 
+* SOLR-12375: Optimize Lucene ScoreMode use:
+  A non-cached filter query could be told incorrectly that scores were needed.
+  The /export (ExportQParserPlugin) would declare incorrectly that scores are needed.
+  Expanded docs (expand component) could be told incorrectly that scores are needed.  (David
Smiley)
+
 Other Changes
 ----------------------
 

http://git-wip-us.apache.org/repos/asf/lucene-solr/blob/53a3de3b/solr/core/src/java/org/apache/solr/handler/component/ExpandComponent.java
----------------------------------------------------------------------
diff --git a/solr/core/src/java/org/apache/solr/handler/component/ExpandComponent.java b/solr/core/src/java/org/apache/solr/handler/component/ExpandComponent.java
index 09b4b36..f6e29e4 100644
--- a/solr/core/src/java/org/apache/solr/handler/component/ExpandComponent.java
+++ b/solr/core/src/java/org/apache/solr/handler/component/ExpandComponent.java
@@ -551,11 +551,6 @@ public class ExpandComponent extends SearchComponent implements PluginInfoInitia
       }
     }
 
-    @Override
-    public ScoreMode scoreMode() {
-      return ScoreMode.COMPLETE; // TODO: is this always true?
-    }
-
     public LeafCollector getLeafCollector(LeafReaderContext context) throws IOException {
       final int docBase = context.docBase;
 
@@ -634,11 +629,6 @@ public class ExpandComponent extends SearchComponent implements PluginInfoInitia
       this.field = field;
       this.collapsedSet = collapsedSet;
     }
-    
-    @Override
-    public ScoreMode scoreMode() {
-      return ScoreMode.COMPLETE; // TODO: is this always true?
-    }
 
     public LeafCollector getLeafCollector(LeafReaderContext context) throws IOException {
       final int docBase = context.docBase;
@@ -683,8 +673,19 @@ public class ExpandComponent extends SearchComponent implements PluginInfoInitia
 
   }
 
-  private interface GroupCollector {
+  //TODO lets just do simple abstract base class -- a fine use of inheritance
+  private interface GroupCollector extends Collector {
     public LongObjectMap<Collector> getGroups();
+
+    @Override
+    default ScoreMode scoreMode() {
+      final LongObjectMap<Collector> groups = getGroups();
+      if (groups.isEmpty()) {
+        return ScoreMode.COMPLETE; // doesn't matter?
+      } else {
+        return groups.iterator().next().value.scoreMode(); // we assume all the collectors
should have the same nature
+      }
+    }
   }
 
   private Query getGroupQuery(String fname,

http://git-wip-us.apache.org/repos/asf/lucene-solr/blob/53a3de3b/solr/core/src/java/org/apache/solr/search/ExportQParserPlugin.java
----------------------------------------------------------------------
diff --git a/solr/core/src/java/org/apache/solr/search/ExportQParserPlugin.java b/solr/core/src/java/org/apache/solr/search/ExportQParserPlugin.java
index fd625af..dbaf3db 100644
--- a/solr/core/src/java/org/apache/solr/search/ExportQParserPlugin.java
+++ b/solr/core/src/java/org/apache/solr/search/ExportQParserPlugin.java
@@ -16,19 +16,27 @@
  */
 package org.apache.solr.search;
 
-import org.apache.lucene.util.FixedBitSet;
-import org.apache.solr.handler.component.MergeStrategy;
-import org.apache.solr.request.SolrRequestInfo;
-
-import org.apache.lucene.search.*;
-import org.apache.lucene.index.*;
-import org.apache.solr.request.SolrQueryRequest;
-import org.apache.solr.common.params.SolrParams;
-
 import java.io.IOException;
 import java.util.Map;
 import java.util.Objects;
 
+import org.apache.lucene.index.IndexReader;
+import org.apache.lucene.index.LeafReaderContext;
+import org.apache.lucene.search.IndexSearcher;
+import org.apache.lucene.search.LeafCollector;
+import org.apache.lucene.search.Query;
+import org.apache.lucene.search.ScoreDoc;
+import org.apache.lucene.search.ScoreMode;
+import org.apache.lucene.search.Scorer;
+import org.apache.lucene.search.TopDocs;
+import org.apache.lucene.search.TopDocsCollector;
+import org.apache.lucene.search.Weight;
+import org.apache.lucene.util.FixedBitSet;
+import org.apache.solr.common.params.SolrParams;
+import org.apache.solr.handler.component.MergeStrategy;
+import org.apache.solr.request.SolrQueryRequest;
+import org.apache.solr.request.SolrRequestInfo;
+
 public class ExportQParserPlugin extends QParserPlugin {
 
   public static final String NAME = "xport";
@@ -73,7 +81,7 @@ public class ExportQParserPlugin extends QParserPlugin {
 
     @Override
     public Weight createWeight(IndexSearcher searcher, ScoreMode scoreMode, float boost)
throws IOException{
-      return mainQuery.createWeight(searcher, ScoreMode.COMPLETE, boost);
+      return mainQuery.createWeight(searcher, scoreMode, boost);
     }
 
     public Query rewrite(IndexReader reader) throws IOException {
@@ -177,7 +185,7 @@ public class ExportQParserPlugin extends QParserPlugin {
 
     @Override
     public ScoreMode scoreMode() {
-      return ScoreMode.COMPLETE; // TODO: is this the case?
+      return ScoreMode.COMPLETE_NO_SCORES;
     }
   }
 

http://git-wip-us.apache.org/repos/asf/lucene-solr/blob/53a3de3b/solr/core/src/java/org/apache/solr/search/ReRankCollector.java
----------------------------------------------------------------------
diff --git a/solr/core/src/java/org/apache/solr/search/ReRankCollector.java b/solr/core/src/java/org/apache/solr/search/ReRankCollector.java
index 9b6ecb3..0447053 100644
--- a/solr/core/src/java/org/apache/solr/search/ReRankCollector.java
+++ b/solr/core/src/java/org/apache/solr/search/ReRankCollector.java
@@ -65,6 +65,7 @@ public class ReRankCollector extends TopDocsCollector {
       this.mainCollector = TopScoreDocCollector.create(Math.max(this.reRankDocs, length));
     } else {
       sort = sort.rewrite(searcher);
+      //scores are needed for Rescorer (regardless of whether sort needs it)
       this.mainCollector = TopFieldCollector.create(sort, Math.max(this.reRankDocs, length),
false, true, true, true);
     }
     this.searcher = searcher;
@@ -82,7 +83,7 @@ public class ReRankCollector extends TopDocsCollector {
 
   @Override
   public ScoreMode scoreMode() {
-    return ScoreMode.COMPLETE;
+    return ScoreMode.COMPLETE; // since the scores will be needed by Rescorer as input regardless
of mainCollector
   }
 
   public TopDocs topDocs(int start, int howMany) {

http://git-wip-us.apache.org/repos/asf/lucene-solr/blob/53a3de3b/solr/core/src/java/org/apache/solr/search/SolrIndexSearcher.java
----------------------------------------------------------------------
diff --git a/solr/core/src/java/org/apache/solr/search/SolrIndexSearcher.java b/solr/core/src/java/org/apache/solr/search/SolrIndexSearcher.java
index 2dbc2db..a8c168e 100644
--- a/solr/core/src/java/org/apache/solr/search/SolrIndexSearcher.java
+++ b/solr/core/src/java/org/apache/solr/search/SolrIndexSearcher.java
@@ -1061,7 +1061,7 @@ public class SolrIndexSearcher extends IndexSearcher implements Closeable,
SolrI
       List<Weight> weights = new ArrayList<>(notCached.size());
       for (Query q : notCached) {
         Query qq = QueryUtils.makeQueryable(q);
-        weights.add(createWeight(rewrite(qq), ScoreMode.COMPLETE, 1));
+        weights.add(createWeight(rewrite(qq), ScoreMode.COMPLETE_NO_SCORES, 1));
       }
       pf.filter = new FilterImpl(answer, weights);
       pf.hasDeletedDocs = (answer == null);  // if all clauses were uncached, the resulting
filter may match deleted docs
@@ -1672,7 +1672,7 @@ public class SolrIndexSearcher extends IndexSearcher implements Closeable,
SolrI
 
           @Override
           public ScoreMode scoreMode() {
-            return ScoreMode.COMPLETE;
+            return ScoreMode.TOP_SCORES;
           }
         };
 


Mime
View raw message