Index: src/java/org/apache/lucene/search/ConstantScoreQuery.java
===================================================================
--- src/java/org/apache/lucene/search/ConstantScoreQuery.java	(revision 800113)
+++ src/java/org/apache/lucene/search/ConstantScoreQuery.java	(working copy)
@@ -18,6 +18,7 @@
  */
 
 import org.apache.lucene.index.IndexReader;
+import org.apache.lucene.util.ReaderUtil;
 
 import java.io.IOException;
 import java.util.Set;
@@ -82,8 +83,8 @@
     }
 
     public Explanation explain(IndexReader reader, int doc) throws IOException {
-
-      ConstantScorer cs = (ConstantScorer) scorer(reader, true, false);
+      
+      ConstantScorer cs = new ConstantScorer(similarity, ReaderUtil.subReader(doc, reader), this);
       boolean exists = cs.docIdSetIterator.advance(doc) == doc;
 
       ComplexExplanation result = new ComplexExplanation();
Index: src/java/org/apache/lucene/search/IndexSearcher.java
===================================================================
--- src/java/org/apache/lucene/search/IndexSearcher.java	(revision 800113)
+++ src/java/org/apache/lucene/search/IndexSearcher.java	(working copy)
@@ -27,6 +27,7 @@
 import org.apache.lucene.index.IndexReader;
 import org.apache.lucene.index.Term;
 import org.apache.lucene.store.Directory;
+import org.apache.lucene.util.ReaderUtil;
 
 /** Implements search over a single IndexReader.
  *
@@ -121,15 +122,7 @@
   }
 
   protected void gatherSubReaders(List allSubReaders, IndexReader r) {
-    IndexReader[] subReaders = r.getSequentialSubReaders();
-    if (subReaders == null) {
-      // Add the reader itself, and do not recurse
-      allSubReaders.add(r);
-    } else {
-      for (int i = 0; i < subReaders.length; i++) {
-        gatherSubReaders(allSubReaders, subReaders[i]);
-      }
-    }
+    ReaderUtil.gatherSubReaders(allSubReaders, r);
   }
 
   /** Return the {@link IndexReader} this searches. */
Index: src/java/org/apache/lucene/search/MultiSearcher.java
===================================================================
--- src/java/org/apache/lucene/search/MultiSearcher.java	(revision 800113)
+++ src/java/org/apache/lucene/search/MultiSearcher.java	(working copy)
@@ -22,6 +22,7 @@
 import org.apache.lucene.index.CorruptIndexException;
 import org.apache.lucene.index.Term;
 import org.apache.lucene.index.IndexReader;
+import org.apache.lucene.util.ReaderUtil;
 
 import java.io.IOException;
 import java.util.HashMap;
@@ -164,25 +165,7 @@
   /** Returns index of the searcher for document <code>n</code> in the array
    * used to construct this searcher. */
   public int subSearcher(int n) {                 // find searcher for doc n:
-    // replace w/ call to Arrays.binarySearch in Java 1.2
-    int lo = 0;					  // search starts array
-    int hi = searchables.length - 1;		  // for first element less
-						  // than n, return its index
-    while (hi >= lo) {
-      int mid = (lo + hi) >>> 1;
-      int midValue = starts[mid];
-      if (n < midValue)
-	hi = mid - 1;
-      else if (n > midValue)
-	lo = mid + 1;
-      else {                                      // found a match
-        while (mid+1 < searchables.length && starts[mid+1] == midValue) {
-          mid++;                                  // scan to last match
-        }
-	return mid;
-      }
-    }
-    return hi;
+    return ReaderUtil.subIndex(n, searchables.length, starts);
   }
 
   /** Returns the document number of document <code>n</code> within its
Index: src/java/org/apache/lucene/search/QueryWeight.java
===================================================================
--- src/java/org/apache/lucene/search/QueryWeight.java	(revision 800113)
+++ src/java/org/apache/lucene/search/QueryWeight.java	(working copy)
@@ -48,7 +48,13 @@
  */
 public abstract class QueryWeight implements Weight, Serializable {
 
-  /** An explanation of the score computation for the named document. */
+  /** 
+   * An explanation of the score computation for the named document. 
+   * 
+   * When implementing new QueryWeights, be sure not to use the top level
+   * reader passed here to create FieldCache's and Filter doc sets - instead,
+   * you should create and access these structures by sub-reader.
+   */
   public abstract Explanation explain(IndexReader reader, int doc) throws IOException;
 
   /** The query that this concerns. */
Index: src/java/org/apache/lucene/search/function/CustomScoreQuery.java
===================================================================
--- src/java/org/apache/lucene/search/function/CustomScoreQuery.java	(revision 800113)
+++ src/java/org/apache/lucene/search/function/CustomScoreQuery.java	(working copy)
@@ -28,6 +28,7 @@
 import org.apache.lucene.search.Scorer;
 import org.apache.lucene.search.Searcher;
 import org.apache.lucene.search.Similarity;
+import org.apache.lucene.util.ReaderUtil;
 import org.apache.lucene.util.ToStringUtils;
 
 /**
@@ -336,13 +337,13 @@
       }
       Scorer[] valSrcScorers = new Scorer[valSrcWeights.length];
       for(int i = 0; i < valSrcScorers.length; i++) {
-         valSrcScorers[i] = valSrcWeights[i].scorer(reader, true, false);
+         valSrcScorers[i] = valSrcWeights[i].scorer(reader, true, topScorer);
       }
       return new CustomScorer(similarity, reader, this, subQueryScorer, valSrcScorers);
     }
 
     public Explanation explain(IndexReader reader, int doc) throws IOException {
-      Scorer scorer = scorer(reader, true, false);
+      Scorer scorer = scorer(ReaderUtil.subReader(doc, reader), true, false);
       return scorer == null ? new Explanation(0.0f, "no matching docs") : scorer.explain(doc);
     }
     
Index: src/java/org/apache/lucene/search/function/ValueSourceQuery.java
===================================================================
--- src/java/org/apache/lucene/search/function/ValueSourceQuery.java	(revision 800113)
+++ src/java/org/apache/lucene/search/function/ValueSourceQuery.java	(working copy)
@@ -20,6 +20,7 @@
 import org.apache.lucene.index.IndexReader;
 import org.apache.lucene.index.TermDocs;
 import org.apache.lucene.search.*;
+import org.apache.lucene.util.ReaderUtil;
 import org.apache.lucene.util.ToStringUtils;
 
 import java.io.IOException;
@@ -62,7 +63,7 @@
     // no terms involved here
   }
 
-  private class ValueSourceWeight extends QueryWeight {
+  class ValueSourceWeight extends QueryWeight {
     Similarity similarity;
     float queryNorm;
     float queryWeight;
@@ -92,14 +93,14 @@
       this.queryNorm = norm;
       queryWeight *= this.queryNorm;
     }
-
+    
     public Scorer scorer(IndexReader reader, boolean scoreDocsInOrder, boolean topScorer) throws IOException {
       return new ValueSourceScorer(similarity, reader, this);
     }
 
     /*(non-Javadoc) @see org.apache.lucene.search.Weight#explain(org.apache.lucene.index.IndexReader, int) */
     public Explanation explain(IndexReader reader, int doc) throws IOException {
-      return scorer(reader, true, false).explain(doc);
+      return new ValueSourceScorer(similarity, ReaderUtil.subReader(doc, reader), this).explain(doc);
     }
   }
 
Index: src/java/org/apache/lucene/util/ReaderUtil.java
===================================================================
--- src/java/org/apache/lucene/util/ReaderUtil.java	(revision 0)
+++ src/java/org/apache/lucene/util/ReaderUtil.java	(revision 0)
@@ -0,0 +1,89 @@
+package org.apache.lucene.util;
+
+/**
+ * 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.
+ */
+
+import java.util.ArrayList;
+import java.util.List;
+
+import org.apache.lucene.index.IndexReader;
+
+public class ReaderUtil {
+
+  /**
+   * Gathers sub-readers from reader into a List.
+   * 
+   * @param allSubReaders
+   * @param reader
+   */
+  public static void gatherSubReaders(List allSubReaders, IndexReader reader) {
+    IndexReader[] subReaders = reader.getSequentialSubReaders();
+    if (subReaders == null) {
+      // Add the reader itself, and do not recurse
+      allSubReaders.add(reader);
+    } else {
+      for (int i = 0; i < subReaders.length; i++) {
+        gatherSubReaders(allSubReaders, subReaders[i]);
+      }
+    }
+  }
+
+  /**
+   * Returns sub IndexReader that contains the given document id.
+   */
+  public static IndexReader subReader(int doc, IndexReader reader) {
+    List subReadersList = new ArrayList();
+    ReaderUtil.gatherSubReaders(subReadersList, reader);
+    IndexReader[] subReaders = (IndexReader[]) subReadersList
+        .toArray(new IndexReader[subReadersList.size()]);
+    int[] docStarts = new int[subReaders.length];
+    int maxDoc = 0;
+    for (int i = 0; i < subReaders.length; i++) {
+      docStarts[i] = maxDoc;
+      maxDoc += subReaders[i].maxDoc();
+    }
+    return subReaders[ReaderUtil.subIndex(doc, subReaders.length, docStarts)];
+  }
+
+  /**
+   * Returns index of the searcher/reader for document <code>n</code> in the
+   * array used to construct this searcher/reader.
+   */
+  public static int subIndex(int n, int size, int[] docStarts) { // find
+    // searcher for
+    // doc n:
+    // replace w/ call to Arrays.binarySearch in Java 1.2
+    int lo = 0; // search starts array
+    int hi = size - 1; // for first element less
+    // than n, return its index
+    while (hi >= lo) {
+      int mid = (lo + hi) >>> 1;
+      int midValue = docStarts[mid];
+      if (n < midValue)
+        hi = mid - 1;
+      else if (n > midValue)
+        lo = mid + 1;
+      else { // found a match
+        while (mid + 1 < size && docStarts[mid + 1] == midValue) {
+          mid++; // scan to last match
+        }
+        return mid;
+      }
+    }
+    return hi;
+  }
+}

