lucene-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From busc...@apache.org
Subject svn commit: r1058718 [16/18] - in /lucene/dev/branches/realtime_search: ./ lucene/ lucene/contrib/ lucene/contrib/ant/src/java/org/apache/lucene/ant/ lucene/contrib/ant/src/test/org/apache/lucene/ant/ lucene/contrib/benchmark/ lucene/contrib/demo/src/j...
Date Thu, 13 Jan 2011 19:53:39 GMT
Modified: lucene/dev/branches/realtime_search/solr/src/java/org/apache/solr/search/QParser.java
URL: http://svn.apache.org/viewvc/lucene/dev/branches/realtime_search/solr/src/java/org/apache/solr/search/QParser.java?rev=1058718&r1=1058717&r2=1058718&view=diff
==============================================================================
--- lucene/dev/branches/realtime_search/solr/src/java/org/apache/solr/search/QParser.java (original)
+++ lucene/dev/branches/realtime_search/solr/src/java/org/apache/solr/search/QParser.java Thu Jan 13 19:53:21 2011
@@ -63,10 +63,11 @@ public abstract class QParser {
     if (localParams != null) {
       String tagStr = localParams.get(CommonParams.TAG);
       if (tagStr != null) {
-        Map context = req.getContext();
-        Map<String,Collection<Object>> tagMap = (Map<String, Collection<Object>>)req.getContext().get("tags");
+        Map<Object,Object> context = req.getContext();
+        @SuppressWarnings("unchecked")
+        Map<Object,Collection<Object>> tagMap = (Map<Object, Collection<Object>>)req.getContext().get("tags");
         if (tagMap == null) {
-          tagMap = new HashMap<String,Collection<Object>>();
+          tagMap = new HashMap<Object,Collection<Object>>();
           context.put("tags", tagMap);          
         }
         if (tagStr.indexOf(',') >= 0) {
@@ -85,10 +86,10 @@ public abstract class QParser {
   }
 
 
-  private static void addTag(Map tagMap, Object key, Object val) {
-    Collection lst = (Collection)tagMap.get(key);
+  private static void addTag(Map<Object,Collection<Object>> tagMap, Object key, Object val) {
+    Collection<Object> lst = tagMap.get(key);
     if (lst == null) {
-      lst = new ArrayList(2);
+      lst = new ArrayList<Object>(2);
       tagMap.put(key, lst);
     }
     lst.add(val);

Modified: lucene/dev/branches/realtime_search/solr/src/java/org/apache/solr/search/SolrConstantScoreQuery.java
URL: http://svn.apache.org/viewvc/lucene/dev/branches/realtime_search/solr/src/java/org/apache/solr/search/SolrConstantScoreQuery.java?rev=1058718&r1=1058717&r2=1058718&view=diff
==============================================================================
--- lucene/dev/branches/realtime_search/solr/src/java/org/apache/solr/search/SolrConstantScoreQuery.java (original)
+++ lucene/dev/branches/realtime_search/solr/src/java/org/apache/solr/search/SolrConstantScoreQuery.java Thu Jan 13 19:53:21 2011
@@ -2,6 +2,7 @@ package org.apache.solr.search;
 
 import org.apache.lucene.search.*;
 import org.apache.lucene.index.IndexReader;
+import org.apache.lucene.index.IndexReader.AtomicReaderContext;
 import org.apache.solr.search.function.ValueSource;
 import org.apache.solr.common.SolrException;
 
@@ -59,9 +60,9 @@ public class SolrConstantScoreQuery exte
     private float queryWeight;
     private Map context;
 
-    public ConstantWeight(Searcher searcher) throws IOException {
+    public ConstantWeight(IndexSearcher searcher) throws IOException {
       this.similarity = getSimilarity(searcher);
-      this.context = ValueSource.newContext();
+      this.context = ValueSource.newContext(searcher);
       if (filter instanceof SolrFilter)
         ((SolrFilter)filter).createWeight(context, searcher);
     }
@@ -89,14 +90,14 @@ public class SolrConstantScoreQuery exte
     }
 
     @Override
-    public Scorer scorer(IndexReader reader, boolean scoreDocsInOrder, boolean topScorer) throws IOException {
-      return new ConstantScorer(similarity, reader, this);
+    public Scorer scorer(AtomicReaderContext context, ScorerContext scorerContext) throws IOException {
+      return new ConstantScorer(similarity, context, this);
     }
 
     @Override
-    public Explanation explain(IndexReader reader, int doc) throws IOException {
+    public Explanation explain(AtomicReaderContext context, int doc) throws IOException {
 
-      ConstantScorer cs = new ConstantScorer(similarity, reader, this);
+      ConstantScorer cs = new ConstantScorer(similarity, context, this);
       boolean exists = cs.docIdSetIterator.advance(doc) == doc;
 
       ComplexExplanation result = new ComplexExplanation();
@@ -123,10 +124,10 @@ public class SolrConstantScoreQuery exte
     final float theScore;
     int doc = -1;
 
-    public ConstantScorer(Similarity similarity, IndexReader reader, ConstantWeight w) throws IOException {
+    public ConstantScorer(Similarity similarity, AtomicReaderContext context, ConstantWeight w) throws IOException {
       super(similarity);
       theScore = w.getValue();
-      DocIdSet docIdSet = filter instanceof SolrFilter ? ((SolrFilter)filter).getDocIdSet(w.context, reader) : filter.getDocIdSet(reader);
+      DocIdSet docIdSet = filter instanceof SolrFilter ? ((SolrFilter)filter).getDocIdSet(w.context, context) : filter.getDocIdSet(context);
       if (docIdSet == null) {
         docIdSetIterator = DocIdSet.EMPTY_DOCIDSET.iterator();
       } else {
@@ -161,7 +162,7 @@ public class SolrConstantScoreQuery exte
   }
 
   @Override
-  public Weight createWeight(Searcher searcher) {
+  public Weight createWeight(IndexSearcher searcher) {
     try {
       return new SolrConstantScoreQuery.ConstantWeight(searcher);
     } catch (IOException e) {

Modified: lucene/dev/branches/realtime_search/solr/src/java/org/apache/solr/search/SolrFilter.java
URL: http://svn.apache.org/viewvc/lucene/dev/branches/realtime_search/solr/src/java/org/apache/solr/search/SolrFilter.java?rev=1058718&r1=1058717&r2=1058718&view=diff
==============================================================================
--- lucene/dev/branches/realtime_search/solr/src/java/org/apache/solr/search/SolrFilter.java (original)
+++ lucene/dev/branches/realtime_search/solr/src/java/org/apache/solr/search/SolrFilter.java Thu Jan 13 19:53:21 2011
@@ -18,9 +18,11 @@
 package org.apache.solr.search;
 
 import org.apache.lucene.search.Filter;
-import org.apache.lucene.search.Searcher;
+import org.apache.lucene.search.IndexSearcher;
 import org.apache.lucene.search.DocIdSet;
 import org.apache.lucene.index.IndexReader;
+import org.apache.lucene.index.IndexReader.AtomicReaderContext;
+import org.apache.lucene.index.IndexReader.AtomicReaderContext;
 
 import java.util.Map;
 import java.io.IOException;
@@ -35,12 +37,12 @@ public abstract class SolrFilter extends
 
   /** Implementations should propagate createWeight to sub-ValueSources which can store weight info in the context.
    * The context object will be passed to getDocIdSet() where this info can be retrieved. */
-  public abstract void createWeight(Map context, Searcher searcher) throws IOException;
+  public abstract void createWeight(Map context, IndexSearcher searcher) throws IOException;
   
-  public abstract DocIdSet getDocIdSet(Map context, IndexReader reader) throws IOException;
+  public abstract DocIdSet getDocIdSet(Map context, AtomicReaderContext readerContext) throws IOException;
 
   @Override
-  public DocIdSet getDocIdSet(IndexReader reader) throws IOException {
-    return getDocIdSet(null, reader);
+  public DocIdSet getDocIdSet(AtomicReaderContext context) throws IOException {
+    return getDocIdSet(null, context);
   }
 }

Modified: lucene/dev/branches/realtime_search/solr/src/java/org/apache/solr/search/SolrIndexSearcher.java
URL: http://svn.apache.org/viewvc/lucene/dev/branches/realtime_search/solr/src/java/org/apache/solr/search/SolrIndexSearcher.java?rev=1058718&r1=1058717&r2=1058718&view=diff
==============================================================================
--- lucene/dev/branches/realtime_search/solr/src/java/org/apache/solr/search/SolrIndexSearcher.java (original)
+++ lucene/dev/branches/realtime_search/solr/src/java/org/apache/solr/search/SolrIndexSearcher.java Thu Jan 13 19:53:21 2011
@@ -21,6 +21,7 @@ import org.apache.lucene.document.Docume
 import org.apache.lucene.document.FieldSelector;
 import org.apache.lucene.document.FieldSelectorResult;
 import org.apache.lucene.index.*;
+import org.apache.lucene.index.IndexReader.AtomicReaderContext;
 import org.apache.lucene.search.*;
 import org.apache.lucene.store.Directory;
 import org.apache.lucene.store.FSDirectory;
@@ -67,7 +68,7 @@ public class SolrIndexSearcher extends I
   private long openTime = System.currentTimeMillis();
   private long registerTime = 0;
   private long warmupTime = 0;
-  private final SolrIndexReader reader;
+  private final IndexReader reader;
   private final boolean closeReader;
 
   private final int queryResultWindowSize;
@@ -79,7 +80,7 @@ public class SolrIndexSearcher extends I
   private final SolrCache<Query,DocSet> filterCache;
   private final SolrCache<QueryResultKey,DocList> queryResultCache;
   private final SolrCache<Integer,Document> documentCache;
-  private final SolrCache<String,Object> fieldValueCache;
+  private final SolrCache<String,UnInvertedField> fieldValueCache;
 
   private final LuceneQueryOptimizer optimizer;
   
@@ -116,28 +117,15 @@ public class SolrIndexSearcher extends I
     this(core, schema,name,r, false, enableCache);
   }
 
-  private static SolrIndexReader wrap(IndexReader r) {
-    SolrIndexReader sir;
-    // wrap the reader
-    if (!(r instanceof SolrIndexReader)) {
-      sir = new SolrIndexReader(r, null, 0);
-      sir.associateInfo(null);
-    } else {
-      sir = (SolrIndexReader)r;
-    }
-    return sir;
-  }
 
   public SolrIndexSearcher(SolrCore core, IndexSchema schema, String name, IndexReader r, boolean closeReader, boolean enableCache) {
-    super(wrap(r));
-    this.reader = (SolrIndexReader)super.getIndexReader();
+    super(r);
+    this.reader = getIndexReader();
     this.core = core;
     this.schema = schema;
     this.name = "Searcher@" + Integer.toHexString(hashCode()) + (name!=null ? " "+name : "");
     log.info("Opening " + this.name);
 
-    SolrIndexReader.setSearcher(reader, this);
-
     if (r.directory() instanceof FSDirectory) {
       FSDirectory fsDirectory = (FSDirectory) r.directory();
       indexDir = fsDirectory.getDirectory().getAbsolutePath();
@@ -246,8 +234,6 @@ public class SolrIndexSearcher extends I
     numCloses.incrementAndGet();
   }
 
-  /** Direct access to the IndexReader used by this searcher */
-  public SolrIndexReader getReader() { return reader; }
   /** Direct access to the IndexSchema for use with this searcher */
   public IndexSchema getSchema() { return schema; }
   
@@ -470,7 +456,7 @@ public class SolrIndexSearcher extends I
   ////////////////////////////////////////////////////////////////////////////////
 
   /** expert: internal API, subject to change */
-  public SolrCache getFieldValueCache() {
+  public SolrCache<String,UnInvertedField> getFieldValueCache() {
     return fieldValueCache;
   }
 
@@ -826,19 +812,17 @@ public class SolrIndexSearcher extends I
     if (filter==null) {
       if (query instanceof TermQuery) {
         Term t = ((TermQuery)query).getTerm();
-        SolrIndexReader[] readers = reader.getLeafReaders();
-        int[] offsets = reader.getLeafOffsets();
+        final AtomicReaderContext[] leaves = leafContexts;
 
-        for (int i=0; i<readers.length; i++) {
-          SolrIndexReader sir = readers[i];
-          int offset = offsets[i];
-          collector.setNextReader(sir, offset);
-          
-          Fields fields = sir.fields();
+        for (int i=0; i<leaves.length; i++) {
+          final AtomicReaderContext leaf = leaves[i];
+          final IndexReader reader = leaf.reader;
+          collector.setNextReader(leaf);
+          Fields fields = reader.fields();
           Terms terms = fields.terms(t.field());
           BytesRef termBytes = t.bytes();
           
-          Bits skipDocs = sir.getDeletedDocs();
+          Bits skipDocs = reader.getDeletedDocs();
           DocsEnum docsEnum = terms==null ? null : terms.docs(skipDocs, termBytes, null);
 
           if (docsEnum != null) {
@@ -898,22 +882,6 @@ public class SolrIndexSearcher extends I
     return positive ? getDocSetNC(absQ,filter) : filter.andNot(getPositiveDocSet(absQ));
   }
 
-
-  /**
-  * Converts a filter into a DocSet.
-  * This method is not cache-aware and no caches are checked.
-  */
-  public DocSet convertFilter(Filter lfilter) throws IOException {
-    DocIdSet docSet = lfilter.getDocIdSet(this.reader);
-    OpenBitSet obs = new OpenBitSet();
-    DocIdSetIterator it = docSet.iterator();
-    int doc;
-    while((doc = it.nextDoc()) != DocIdSetIterator.NO_MORE_DOCS) {
-      obs.fastSet(doc);
-    }
-    return new BitDocSet(obs);
-  }
-
   /**
    * Returns documents matching both <code>query</code> and <code>filter</code>
    * and sorted by <code>sort</code>.
@@ -1142,7 +1110,7 @@ public class SolrIndexSearcher extends I
           public void collect(int doc) throws IOException {
             numHits[0]++;
           }
-          public void setNextReader(IndexReader reader, int docBase) throws IOException {
+          public void setNextReader(AtomicReaderContext context) throws IOException {
           }
           public boolean acceptsDocsOutOfOrder() {
             return true;
@@ -1159,7 +1127,7 @@ public class SolrIndexSearcher extends I
             float score = scorer.score();
             if (score > topscore[0]) topscore[0]=score;            
           }
-          public void setNextReader(IndexReader reader, int docBase) throws IOException {
+          public void setNextReader(AtomicReaderContext context) throws IOException {
           }
           public boolean acceptsDocsOutOfOrder() {
             return true;
@@ -1265,7 +1233,7 @@ public class SolrIndexSearcher extends I
              float score = scorer.score();
              if (score > topscore[0]) topscore[0]=score;
            }
-           public void setNextReader(IndexReader reader, int docBase) throws IOException {
+           public void setNextReader(AtomicReaderContext context) throws IOException {
            }
            public boolean acceptsDocsOutOfOrder() {
              return false;
@@ -1586,21 +1554,21 @@ public class SolrIndexSearcher extends I
     int base=0;
     int end=0;
     int readerIndex = -1;
-    SolrIndexReader r=null;
-
+    
+    AtomicReaderContext leaf = null;
 
-    while(iter.hasNext()) {
+    for (int i = 0; i < leafContexts.length; i++) {
       int doc = iter.nextDoc();
       while (doc>=end) {
-        r = reader.getLeafReaders()[++readerIndex];
-        base = reader.getLeafOffsets()[readerIndex];
-        end = base + r.maxDoc();
-        topCollector.setNextReader(r, base);
+        leaf = leafContexts[i++];
+        base = leaf.docBase;
+        end = base + leaf.reader.maxDoc();
+        topCollector.setNextReader(leaf);
         // we should never need to set the scorer given the settings for the collector
       }
       topCollector.collect(doc-base);
     }
-
+    
     TopDocs topDocs = topCollector.topDocs(0, nDocs);
 
     int nDocsReturned = topDocs.scoreDocs.length;
@@ -1767,8 +1735,8 @@ public class SolrIndexSearcher extends I
     return null;
   }
 
-  public NamedList getStatistics() {
-    NamedList lst = new SimpleOrderedMap();
+  public NamedList<Object> getStatistics() {
+    NamedList<Object> lst = new SimpleOrderedMap<Object>();
     lst.add("searcherName", name);
     lst.add("caching", cachingEnabled);
     lst.add("numDocs", reader.numDocs());

Modified: lucene/dev/branches/realtime_search/solr/src/java/org/apache/solr/search/SortedIntDocSet.java
URL: http://svn.apache.org/viewvc/lucene/dev/branches/realtime_search/solr/src/java/org/apache/solr/search/SortedIntDocSet.java?rev=1058718&r1=1058717&r2=1058718&view=diff
==============================================================================
--- lucene/dev/branches/realtime_search/solr/src/java/org/apache/solr/search/SortedIntDocSet.java (original)
+++ lucene/dev/branches/realtime_search/solr/src/java/org/apache/solr/search/SortedIntDocSet.java Thu Jan 13 19:53:21 2011
@@ -22,6 +22,7 @@ import org.apache.lucene.search.DocIdSet
 import org.apache.lucene.search.DocIdSetIterator;
 import org.apache.lucene.search.Filter;
 import org.apache.lucene.index.IndexReader;
+import org.apache.lucene.index.IndexReader.AtomicReaderContext;
 
 import java.io.IOException;
 
@@ -551,14 +552,11 @@ public class SortedIntDocSet extends Doc
       int lastEndIdx = 0;
 
       @Override
-      public DocIdSet getDocIdSet(IndexReader reader) throws IOException {
-        int offset = 0;
-        SolrIndexReader r = (SolrIndexReader)reader;
-        while (r.getParent() != null) {
-          offset += r.getBase();
-          r = r.getParent();
-        }
-        final int base = offset;
+      public DocIdSet getDocIdSet(AtomicReaderContext contextX) throws IOException {
+        AtomicReaderContext context = (AtomicReaderContext)contextX;  // TODO: remove after lucene migration
+        IndexReader reader = context.reader;
+
+        final int base = context.docBase;
         final int maxDoc = reader.maxDoc();
         final int max = base + maxDoc;   // one past the max doc in this segment.
         int sidx = Math.max(0,lastEndIdx);

Modified: lucene/dev/branches/realtime_search/solr/src/java/org/apache/solr/search/ValueSourceParser.java
URL: http://svn.apache.org/viewvc/lucene/dev/branches/realtime_search/solr/src/java/org/apache/solr/search/ValueSourceParser.java?rev=1058718&r1=1058717&r2=1058718&view=diff
==============================================================================
--- lucene/dev/branches/realtime_search/solr/src/java/org/apache/solr/search/ValueSourceParser.java (original)
+++ lucene/dev/branches/realtime_search/solr/src/java/org/apache/solr/search/ValueSourceParser.java Thu Jan 13 19:53:21 2011
@@ -16,11 +16,11 @@
  */
 package org.apache.solr.search;
 
-import org.apache.lucene.index.IndexReader;
+import org.apache.lucene.index.IndexReader.AtomicReaderContext;
 import org.apache.lucene.index.Term;
 import org.apache.lucene.queryParser.ParseException;
 import org.apache.lucene.search.Query;
-import org.apache.lucene.search.Searcher;
+import org.apache.lucene.search.IndexSearcher;
 import org.apache.lucene.search.TermQuery;
 import org.apache.lucene.search.spell.JaroWinklerDistance;
 import org.apache.lucene.search.spell.LevensteinDistance;
@@ -83,7 +83,7 @@ public abstract class ValueSourceParser 
     addParser("ord", new ValueSourceParser() {
       public ValueSource parse(FunctionQParser fp) throws ParseException {
         String field = fp.parseId();
-        return new TopValueSource(new OrdFieldSource(field));
+        return new OrdFieldSource(field);
       }
     });
     addParser("literal", new ValueSourceParser() {
@@ -94,15 +94,14 @@ public abstract class ValueSourceParser 
     addParser("rord", new ValueSourceParser() {
       public ValueSource parse(FunctionQParser fp) throws ParseException {
         String field = fp.parseId();
-        return new TopValueSource(new ReverseOrdFieldSource(field));
+        return new ReverseOrdFieldSource(field);
       }
     });
     addParser("top", new ValueSourceParser() {
       public ValueSource parse(FunctionQParser fp) throws ParseException {
+        // top(vs) is now a no-op
         ValueSource source = fp.parseValueSource();
-        // nested top is redundant, and ord and rord get automatically wrapped
-        if (source instanceof TopValueSource) return source;
-        return new TopValueSource(source);
+        return source;
       }
     });
     addParser("linear", new ValueSourceParser() {
@@ -134,7 +133,7 @@ public abstract class ValueSourceParser 
         ValueSource source = fp.parseValueSource();
         float min = fp.parseFloat();
         float max = fp.parseFloat();
-        return new TopValueSource(new ScaleFloatFunction(source, min, max));
+        return new ScaleFloatFunction(source, min, max);
       }
     });
     addParser("div", new ValueSourceParser() {
@@ -711,7 +710,7 @@ class LongConstValueSource extends Const
     return "const(" + constant + ")";
   }
 
-  public DocValues getValues(Map context, IndexReader reader) throws IOException {
+  public DocValues getValues(Map context, AtomicReaderContext readerContext) throws IOException {
     return new DocValues() {
       public float floatVal(int doc) {
         return fv;
@@ -808,8 +807,8 @@ abstract class DoubleParser extends Name
     }
 
     @Override
-    public DocValues getValues(Map context, IndexReader reader) throws IOException {
-      final DocValues vals =  source.getValues(context, reader);
+    public DocValues getValues(Map context, AtomicReaderContext readerContext) throws IOException {
+      final DocValues vals =  source.getValues(context, readerContext);
       return new DocValues() {
         public float floatVal(int doc) {
           return (float)doubleVal(doc);
@@ -863,9 +862,9 @@ abstract class Double2Parser extends Nam
       return name() + "(" + a.description() + "," + b.description() + ")";
     }
 
-    public DocValues getValues(Map context, IndexReader reader) throws IOException {
-      final DocValues aVals =  a.getValues(context, reader);
-      final DocValues bVals =  b.getValues(context, reader);
+    public DocValues getValues(Map context, AtomicReaderContext readerContext) throws IOException {
+      final DocValues aVals =  a.getValues(context, readerContext);
+      final DocValues bVals =  b.getValues(context, readerContext);
       return new DocValues() {
         public float floatVal(int doc) {
           return (float)doubleVal(doc);
@@ -889,9 +888,7 @@ abstract class Double2Parser extends Nam
     }
 
     @Override
-    public void createWeight(Map context, Searcher searcher) throws IOException {
-      a.createWeight(context,searcher);
-      b.createWeight(context,searcher);
+    public void createWeight(Map context, IndexSearcher searcher) throws IOException {
     }
 
     public int hashCode() {

Modified: lucene/dev/branches/realtime_search/solr/src/java/org/apache/solr/search/function/BoostedQuery.java
URL: http://svn.apache.org/viewvc/lucene/dev/branches/realtime_search/solr/src/java/org/apache/solr/search/function/BoostedQuery.java?rev=1058718&r1=1058717&r2=1058718&view=diff
==============================================================================
--- lucene/dev/branches/realtime_search/solr/src/java/org/apache/solr/search/function/BoostedQuery.java (original)
+++ lucene/dev/branches/realtime_search/solr/src/java/org/apache/solr/search/function/BoostedQuery.java Thu Jan 13 19:53:21 2011
@@ -19,8 +19,8 @@ package org.apache.solr.search.function;
 
 import org.apache.lucene.search.*;
 import org.apache.lucene.index.IndexReader;
+import org.apache.lucene.index.IndexReader.AtomicReaderContext;
 import org.apache.lucene.util.ToStringUtils;
-import org.apache.solr.search.SolrIndexReader;
 
 import java.io.IOException;
 import java.util.Set;
@@ -53,20 +53,20 @@ public class BoostedQuery extends Query 
     q.extractTerms(terms);
   }
 
-  public Weight createWeight(Searcher searcher) throws IOException {
+  public Weight createWeight(IndexSearcher searcher) throws IOException {
     return new BoostedQuery.BoostedWeight(searcher);
   }
 
   private class BoostedWeight extends Weight {
-    Searcher searcher;
+    IndexSearcher searcher;
     Weight qWeight;
-    Map context;
+    Map fcontext;
 
-    public BoostedWeight(Searcher searcher) throws IOException {
+    public BoostedWeight(IndexSearcher searcher) throws IOException {
       this.searcher = searcher;
       this.qWeight = q.weight(searcher);
-      this.context = boostVal.newContext();
-      boostVal.createWeight(context,searcher);
+      this.fcontext = boostVal.newContext(searcher);
+      boostVal.createWeight(fcontext,searcher);
     }
 
     public Query getQuery() {
@@ -91,33 +91,26 @@ public class BoostedQuery extends Query 
     }
 
     @Override
-    public Scorer scorer(IndexReader reader, boolean scoreDocsInOrder, boolean topScorer) throws IOException {
-      Scorer subQueryScorer = qWeight.scorer(reader, true, false);
+    public Scorer scorer(AtomicReaderContext context, ScorerContext scorerContext) throws IOException {
+      Scorer subQueryScorer = qWeight.scorer(context, ScorerContext.def());
       if(subQueryScorer == null) {
         return null;
       }
-      return new BoostedQuery.CustomScorer(getSimilarity(searcher), searcher, reader, this, subQueryScorer, boostVal);
+      return new BoostedQuery.CustomScorer(getSimilarity(searcher), context, this, subQueryScorer, boostVal);
     }
 
     @Override
-    public Explanation explain(IndexReader reader, int doc) throws IOException {
-      SolrIndexReader topReader = (SolrIndexReader)reader;
-      SolrIndexReader[] subReaders = topReader.getLeafReaders();
-      int[] offsets = topReader.getLeafOffsets();
-      int readerPos = SolrIndexReader.readerIndex(doc, offsets);
-      int readerBase = offsets[readerPos];
-
-      Explanation subQueryExpl = qWeight.explain(reader,doc);
+    public Explanation explain(AtomicReaderContext readerContext, int doc) throws IOException {
+      Explanation subQueryExpl = qWeight.explain(readerContext,doc);
       if (!subQueryExpl.isMatch()) {
         return subQueryExpl;
       }
-
-      DocValues vals = boostVal.getValues(context, subReaders[readerPos]);
-      float sc = subQueryExpl.getValue() * vals.floatVal(doc-readerBase);
+      DocValues vals = boostVal.getValues(fcontext, readerContext);
+      float sc = subQueryExpl.getValue() * vals.floatVal(doc);
       Explanation res = new ComplexExplanation(
         true, sc, BoostedQuery.this.toString() + ", product of:");
       res.addDetail(subQueryExpl);
-      res.addDetail(vals.explain(doc-readerBase));
+      res.addDetail(vals.explain(doc));
       return res;
     }
   }
@@ -128,18 +121,16 @@ public class BoostedQuery extends Query 
     private final float qWeight;
     private final Scorer scorer;
     private final DocValues vals;
-    private final IndexReader reader;
-    private final Searcher searcher;
+    private final AtomicReaderContext readerContext;
 
-    private CustomScorer(Similarity similarity, Searcher searcher, IndexReader reader, BoostedQuery.BoostedWeight w,
+    private CustomScorer(Similarity similarity, AtomicReaderContext readerContext, BoostedQuery.BoostedWeight w,
         Scorer scorer, ValueSource vs) throws IOException {
       super(similarity);
       this.weight = w;
       this.qWeight = w.getValue();
       this.scorer = scorer;
-      this.reader = reader;
-      this.searcher = searcher; // for explain
-      this.vals = vs.getValues(weight.context, reader);
+      this.readerContext = readerContext;
+      this.vals = vs.getValues(weight.fcontext, readerContext);
     }
 
     @Override
@@ -168,7 +159,7 @@ public class BoostedQuery extends Query 
     }
 
     public Explanation explain(int doc) throws IOException {
-      Explanation subQueryExpl = weight.qWeight.explain(reader,doc);
+      Explanation subQueryExpl = weight.qWeight.explain(readerContext ,doc);
       if (!subQueryExpl.isMatch()) {
         return subQueryExpl;
       }

Modified: lucene/dev/branches/realtime_search/solr/src/java/org/apache/solr/search/function/ByteFieldSource.java
URL: http://svn.apache.org/viewvc/lucene/dev/branches/realtime_search/solr/src/java/org/apache/solr/search/function/ByteFieldSource.java?rev=1058718&r1=1058717&r2=1058718&view=diff
==============================================================================
--- lucene/dev/branches/realtime_search/solr/src/java/org/apache/solr/search/function/ByteFieldSource.java (original)
+++ lucene/dev/branches/realtime_search/solr/src/java/org/apache/solr/search/function/ByteFieldSource.java Thu Jan 13 19:53:21 2011
@@ -16,7 +16,7 @@ package org.apache.solr.search.function;
  * limitations under the License.
  */
 
-import org.apache.lucene.index.IndexReader;
+import org.apache.lucene.index.IndexReader.AtomicReaderContext;
 import org.apache.lucene.search.cache.ByteValuesCreator;
 import org.apache.lucene.search.cache.CachedArray.ByteValues;
 
@@ -41,8 +41,8 @@ public class ByteFieldSource extends Num
     return "byte(" + field + ')';
   }
 
-  public DocValues getValues(Map context, IndexReader reader) throws IOException {
-    final ByteValues vals = cache.getBytes(reader, field, creator);
+  public DocValues getValues(Map context, AtomicReaderContext readerContext) throws IOException {
+    final ByteValues vals = cache.getBytes(readerContext.reader, field, creator);
     final byte[] arr = vals.values;
     
     return new DocValues() {

Modified: lucene/dev/branches/realtime_search/solr/src/java/org/apache/solr/search/function/ConstValueSource.java
URL: http://svn.apache.org/viewvc/lucene/dev/branches/realtime_search/solr/src/java/org/apache/solr/search/function/ConstValueSource.java?rev=1058718&r1=1058717&r2=1058718&view=diff
==============================================================================
--- lucene/dev/branches/realtime_search/solr/src/java/org/apache/solr/search/function/ConstValueSource.java (original)
+++ lucene/dev/branches/realtime_search/solr/src/java/org/apache/solr/search/function/ConstValueSource.java Thu Jan 13 19:53:21 2011
@@ -17,7 +17,7 @@
 
 package org.apache.solr.search.function;
 
-import org.apache.lucene.index.IndexReader;
+import org.apache.lucene.index.IndexReader.AtomicReaderContext;
 
 import java.io.IOException;
 import java.util.Map;
@@ -38,7 +38,7 @@ public class ConstValueSource extends Co
     return "const(" + constant + ")";
   }
 
-  public DocValues getValues(Map context, IndexReader reader) throws IOException {
+  public DocValues getValues(Map context, AtomicReaderContext readerContext) throws IOException {
     return new DocValues() {
       public float floatVal(int doc) {
         return constant;

Modified: lucene/dev/branches/realtime_search/solr/src/java/org/apache/solr/search/function/DocFreqValueSource.java
URL: http://svn.apache.org/viewvc/lucene/dev/branches/realtime_search/solr/src/java/org/apache/solr/search/function/DocFreqValueSource.java?rev=1058718&r1=1058717&r2=1058718&view=diff
==============================================================================
--- lucene/dev/branches/realtime_search/solr/src/java/org/apache/solr/search/function/DocFreqValueSource.java (original)
+++ lucene/dev/branches/realtime_search/solr/src/java/org/apache/solr/search/function/DocFreqValueSource.java Thu Jan 13 19:53:21 2011
@@ -17,9 +17,9 @@
 
 package org.apache.solr.search.function;
 
-import org.apache.lucene.index.IndexReader;
+import org.apache.lucene.index.IndexReader.AtomicReaderContext;
 import org.apache.lucene.index.Term;
-import org.apache.lucene.search.Searcher;
+import org.apache.lucene.search.IndexSearcher;
 import org.apache.lucene.util.BytesRef;
 import org.apache.solr.search.MutableValueInt;
 import org.apache.solr.search.MutableValue;
@@ -239,14 +239,14 @@ public class DocFreqValueSource extends 
   }
 
   @Override
-  public DocValues getValues(Map context, IndexReader reader) throws IOException {
-    Searcher searcher = (Searcher)context.get("searcher");
+  public DocValues getValues(Map context, AtomicReaderContext readerContext) throws IOException {
+    IndexSearcher searcher = (IndexSearcher)context.get("searcher");
     int docfreq = searcher.docFreq(new Term(indexedField, indexedBytes));
     return new ConstIntDocValues(docfreq, this);
   }
 
   @Override
-  public void createWeight(Map context, Searcher searcher) throws IOException {
+  public void createWeight(Map context, IndexSearcher searcher) throws IOException {
     context.put("searcher",searcher);
   }
 

Modified: lucene/dev/branches/realtime_search/solr/src/java/org/apache/solr/search/function/DoubleConstValueSource.java
URL: http://svn.apache.org/viewvc/lucene/dev/branches/realtime_search/solr/src/java/org/apache/solr/search/function/DoubleConstValueSource.java?rev=1058718&r1=1058717&r2=1058718&view=diff
==============================================================================
--- lucene/dev/branches/realtime_search/solr/src/java/org/apache/solr/search/function/DoubleConstValueSource.java (original)
+++ lucene/dev/branches/realtime_search/solr/src/java/org/apache/solr/search/function/DoubleConstValueSource.java Thu Jan 13 19:53:21 2011
@@ -17,7 +17,7 @@
 
 package org.apache.solr.search.function;
 
-import org.apache.lucene.index.IndexReader;
+import org.apache.lucene.index.IndexReader.AtomicReaderContext;
 
 import java.io.IOException;
 import java.util.Map;
@@ -37,7 +37,7 @@ public class DoubleConstValueSource exte
     return "const(" + constant + ")";
   }
 
-  public DocValues getValues(Map context, IndexReader reader) throws IOException {
+  public DocValues getValues(Map context, AtomicReaderContext readerContext) throws IOException {
     return new DocValues() {
       public float floatVal(int doc) {
         return fv;

Modified: lucene/dev/branches/realtime_search/solr/src/java/org/apache/solr/search/function/DoubleFieldSource.java
URL: http://svn.apache.org/viewvc/lucene/dev/branches/realtime_search/solr/src/java/org/apache/solr/search/function/DoubleFieldSource.java?rev=1058718&r1=1058717&r2=1058718&view=diff
==============================================================================
--- lucene/dev/branches/realtime_search/solr/src/java/org/apache/solr/search/function/DoubleFieldSource.java (original)
+++ lucene/dev/branches/realtime_search/solr/src/java/org/apache/solr/search/function/DoubleFieldSource.java Thu Jan 13 19:53:21 2011
@@ -18,6 +18,7 @@
 package org.apache.solr.search.function;
 
 import org.apache.lucene.index.IndexReader;
+import org.apache.lucene.index.IndexReader.AtomicReaderContext;
 import org.apache.lucene.util.Bits;
 import org.apache.lucene.search.cache.DoubleValuesCreator;
 import org.apache.lucene.search.cache.CachedArray.DoubleValues;
@@ -45,8 +46,8 @@ public class DoubleFieldSource extends N
     return "double(" + field + ')';
   }
 
-  public DocValues getValues(Map context, IndexReader reader) throws IOException {
-    final DoubleValues vals = cache.getDoubles(reader, field, creator);
+  public DocValues getValues(Map context, AtomicReaderContext readerContext) throws IOException {
+    final DoubleValues vals = cache.getDoubles(readerContext.reader, field, creator);
     final double[] arr = vals.values;
 	final Bits valid = vals.valid;
     

Modified: lucene/dev/branches/realtime_search/solr/src/java/org/apache/solr/search/function/DualFloatFunction.java
URL: http://svn.apache.org/viewvc/lucene/dev/branches/realtime_search/solr/src/java/org/apache/solr/search/function/DualFloatFunction.java?rev=1058718&r1=1058717&r2=1058718&view=diff
==============================================================================
--- lucene/dev/branches/realtime_search/solr/src/java/org/apache/solr/search/function/DualFloatFunction.java (original)
+++ lucene/dev/branches/realtime_search/solr/src/java/org/apache/solr/search/function/DualFloatFunction.java Thu Jan 13 19:53:21 2011
@@ -17,8 +17,8 @@
 
 package org.apache.solr.search.function;
 
-import org.apache.lucene.index.IndexReader;
-import org.apache.lucene.search.Searcher;
+import org.apache.lucene.index.IndexReader.AtomicReaderContext;
+import org.apache.lucene.search.IndexSearcher;
 
 import java.io.IOException;
 import java.util.Map;
@@ -43,9 +43,9 @@ public abstract class DualFloatFunction 
     return name() + "(" + a.description() + "," + b.description() + ")";
   }
 
-  public DocValues getValues(Map context, IndexReader reader) throws IOException {
-    final DocValues aVals =  a.getValues(context, reader);
-    final DocValues bVals =  b.getValues(context, reader);
+  public DocValues getValues(Map context, AtomicReaderContext readerContext) throws IOException {
+    final DocValues aVals =  a.getValues(context, readerContext);
+    final DocValues bVals =  b.getValues(context, readerContext);
     return new DocValues() {
       public float floatVal(int doc) {
 	return func(doc, aVals, bVals);
@@ -69,7 +69,7 @@ public abstract class DualFloatFunction 
   }
 
   @Override
-  public void createWeight(Map context, Searcher searcher) throws IOException {
+  public void createWeight(Map context, IndexSearcher searcher) throws IOException {
     a.createWeight(context,searcher);
     b.createWeight(context,searcher);
   }

Modified: lucene/dev/branches/realtime_search/solr/src/java/org/apache/solr/search/function/FileFloatSource.java
URL: http://svn.apache.org/viewvc/lucene/dev/branches/realtime_search/solr/src/java/org/apache/solr/search/function/FileFloatSource.java?rev=1058718&r1=1058717&r2=1058718&view=diff
==============================================================================
--- lucene/dev/branches/realtime_search/solr/src/java/org/apache/solr/search/function/FileFloatSource.java (original)
+++ lucene/dev/branches/realtime_search/solr/src/java/org/apache/solr/search/function/FileFloatSource.java Thu Jan 13 19:53:21 2011
@@ -18,15 +18,17 @@ package org.apache.solr.search.function;
 
 import org.apache.lucene.index.IndexReader;
 import org.apache.lucene.index.DocsEnum;
+import org.apache.lucene.index.IndexReader.AtomicReaderContext;
+import org.apache.lucene.index.IndexReader.ReaderContext;
 import org.apache.lucene.index.TermsEnum;
 import org.apache.lucene.index.MultiFields;
+import org.apache.lucene.util.ReaderUtil;
 import org.apache.lucene.util.StringHelper;
 import org.apache.lucene.util.BytesRef;
 import org.apache.solr.core.SolrCore;
 import org.apache.solr.schema.SchemaField;
 import org.apache.solr.schema.FieldType;
 import org.apache.solr.search.QParser;
-import org.apache.solr.search.SolrIndexReader;
 import org.apache.solr.util.VersionedFile;
 
 import java.io.*;
@@ -55,19 +57,12 @@ public class FileFloatSource extends Val
     return "float(" + field + ')';
   }
 
-  public DocValues getValues(Map context, IndexReader reader) throws IOException {
+  public DocValues getValues(Map context, AtomicReaderContext readerContext) throws IOException {
     int offset = 0;
-    if (reader instanceof SolrIndexReader) {
-      SolrIndexReader r = (SolrIndexReader)reader;
-      while (r.getParent() != null) {
-        offset += r.getBase();
-        r = r.getParent();
-      }
-      reader = r;
-    }
+    ReaderContext topLevelContext = ReaderUtil.getTopLevelContext(readerContext);
     final int off = offset;
 
-    final float[] arr = getCachedFloats(reader);
+    final float[] arr = getCachedFloats(topLevelContext.reader);
     return new DocValues() {
       public float floatVal(int doc) {
         return arr[doc + off];

Modified: lucene/dev/branches/realtime_search/solr/src/java/org/apache/solr/search/function/FloatFieldSource.java
URL: http://svn.apache.org/viewvc/lucene/dev/branches/realtime_search/solr/src/java/org/apache/solr/search/function/FloatFieldSource.java?rev=1058718&r1=1058717&r2=1058718&view=diff
==============================================================================
--- lucene/dev/branches/realtime_search/solr/src/java/org/apache/solr/search/function/FloatFieldSource.java (original)
+++ lucene/dev/branches/realtime_search/solr/src/java/org/apache/solr/search/function/FloatFieldSource.java Thu Jan 13 19:53:21 2011
@@ -20,7 +20,7 @@ package org.apache.solr.search.function;
 import java.io.IOException;
 import java.util.Map;
 
-import org.apache.lucene.index.IndexReader;
+import org.apache.lucene.index.IndexReader.AtomicReaderContext;
 import org.apache.lucene.util.Bits;
 import org.apache.lucene.search.cache.FloatValuesCreator;
 import org.apache.lucene.search.cache.CachedArray.FloatValues;
@@ -45,8 +45,8 @@ public class FloatFieldSource extends Nu
     return "float(" + field + ')';
   }
 
-  public DocValues getValues(Map context, IndexReader reader) throws IOException {
-    final FloatValues vals = cache.getFloats(reader, field, creator);
+  public DocValues getValues(Map context, AtomicReaderContext readerContext) throws IOException {
+    final FloatValues vals = cache.getFloats(readerContext.reader, field, creator);
     final float[] arr = vals.values;
 	final Bits valid = vals.valid;
     

Modified: lucene/dev/branches/realtime_search/solr/src/java/org/apache/solr/search/function/FunctionQuery.java
URL: http://svn.apache.org/viewvc/lucene/dev/branches/realtime_search/solr/src/java/org/apache/solr/search/function/FunctionQuery.java?rev=1058718&r1=1058717&r2=1058718&view=diff
==============================================================================
--- lucene/dev/branches/realtime_search/solr/src/java/org/apache/solr/search/function/FunctionQuery.java (original)
+++ lucene/dev/branches/realtime_search/solr/src/java/org/apache/solr/search/function/FunctionQuery.java Thu Jan 13 19:53:21 2011
@@ -18,10 +18,10 @@
 package org.apache.solr.search.function;
 
 import org.apache.lucene.index.IndexReader;
+import org.apache.lucene.index.IndexReader.AtomicReaderContext;
 import org.apache.lucene.search.*;
 import org.apache.lucene.index.MultiFields;
 import org.apache.lucene.util.Bits;
-import org.apache.solr.search.SolrIndexReader;
 
 import java.io.IOException;
 import java.util.Set;
@@ -60,14 +60,14 @@ public class FunctionQuery extends Query
   public void extractTerms(Set terms) {}
 
   protected class FunctionWeight extends Weight {
-    protected Searcher searcher;
+    protected IndexSearcher searcher;
     protected float queryNorm;
     protected float queryWeight;
     protected Map context;
 
-    public FunctionWeight(Searcher searcher) throws IOException {
+    public FunctionWeight(IndexSearcher searcher) throws IOException {
       this.searcher = searcher;
-      this.context = func.newContext();
+      this.context = func.newContext(searcher);
       func.createWeight(context, searcher);
     }
 
@@ -94,18 +94,13 @@ public class FunctionQuery extends Query
     }
 
     @Override
-    public Scorer scorer(IndexReader reader, boolean scoreDocsInOrder, boolean topScorer) throws IOException {
-      return new AllScorer(getSimilarity(searcher), reader, this);
+    public Scorer scorer(AtomicReaderContext context, ScorerContext scorerContext) throws IOException {
+      return new AllScorer(getSimilarity(searcher), context, this);
     }
 
     @Override
-    public Explanation explain(IndexReader reader, int doc) throws IOException {
-      SolrIndexReader topReader = (SolrIndexReader)reader;
-      SolrIndexReader[] subReaders = topReader.getLeafReaders();
-      int[] offsets = topReader.getLeafOffsets();
-      int readerPos = SolrIndexReader.readerIndex(doc, offsets);
-      int readerBase = offsets[readerPos];
-      return ((AllScorer)scorer(subReaders[readerPos], true, true)).explain(doc-readerBase);
+    public Explanation explain(AtomicReaderContext context, int doc) throws IOException {
+      return ((AllScorer)scorer(context, ScorerContext.def().scoreDocsInOrder(true).topScorer(true))).explain(doc);
     }
   }
 
@@ -119,16 +114,16 @@ public class FunctionQuery extends Query
     final boolean hasDeletions;
     final Bits delDocs;
 
-    public AllScorer(Similarity similarity, IndexReader reader, FunctionWeight w) throws IOException {
+    public AllScorer(Similarity similarity, AtomicReaderContext context, FunctionWeight w) throws IOException {
       super(similarity);
       this.weight = w;
       this.qWeight = w.getValue();
-      this.reader = reader;
+      this.reader = context.reader;
       this.maxDoc = reader.maxDoc();
       this.hasDeletions = reader.hasDeletions();
       this.delDocs = MultiFields.getDeletedDocs(reader);
       assert !hasDeletions || delDocs != null;
-      vals = func.getValues(weight.context, reader);
+      vals = func.getValues(weight.context, context);
     }
 
     @Override
@@ -184,7 +179,7 @@ public class FunctionQuery extends Query
 
 
   @Override
-  public Weight createWeight(Searcher searcher) throws IOException {
+  public Weight createWeight(IndexSearcher searcher) throws IOException {
     return new FunctionQuery.FunctionWeight(searcher);
   }
 

Modified: lucene/dev/branches/realtime_search/solr/src/java/org/apache/solr/search/function/IDFValueSource.java
URL: http://svn.apache.org/viewvc/lucene/dev/branches/realtime_search/solr/src/java/org/apache/solr/search/function/IDFValueSource.java?rev=1058718&r1=1058717&r2=1058718&view=diff
==============================================================================
--- lucene/dev/branches/realtime_search/solr/src/java/org/apache/solr/search/function/IDFValueSource.java (original)
+++ lucene/dev/branches/realtime_search/solr/src/java/org/apache/solr/search/function/IDFValueSource.java Thu Jan 13 19:53:21 2011
@@ -18,7 +18,8 @@
 package org.apache.solr.search.function;
 
 import org.apache.lucene.index.*;
-import org.apache.lucene.search.Searcher;
+import org.apache.lucene.index.IndexReader.AtomicReaderContext;
+import org.apache.lucene.search.IndexSearcher;
 import org.apache.lucene.search.Similarity;
 import org.apache.lucene.util.BytesRef;
 import org.apache.solr.util.ByteUtils;
@@ -38,8 +39,8 @@ public class IDFValueSource extends DocF
   }
 
   @Override
-  public DocValues getValues(Map context, IndexReader reader) throws IOException {
-    Searcher searcher = (Searcher)context.get("searcher");
+  public DocValues getValues(Map context, AtomicReaderContext readerContext) throws IOException {
+    IndexSearcher searcher = (IndexSearcher)context.get("searcher");
     Similarity sim = searcher.getSimilarity();
     // todo: we need docFreq that takes a BytesRef
     String strVal = ByteUtils.UTF8toUTF16(indexedBytes);

Modified: lucene/dev/branches/realtime_search/solr/src/java/org/apache/solr/search/function/IntFieldSource.java
URL: http://svn.apache.org/viewvc/lucene/dev/branches/realtime_search/solr/src/java/org/apache/solr/search/function/IntFieldSource.java?rev=1058718&r1=1058717&r2=1058718&view=diff
==============================================================================
--- lucene/dev/branches/realtime_search/solr/src/java/org/apache/solr/search/function/IntFieldSource.java (original)
+++ lucene/dev/branches/realtime_search/solr/src/java/org/apache/solr/search/function/IntFieldSource.java Thu Jan 13 19:53:21 2011
@@ -18,6 +18,7 @@
 package org.apache.solr.search.function;
 
 import org.apache.lucene.index.IndexReader;
+import org.apache.lucene.index.IndexReader.AtomicReaderContext;
 import org.apache.lucene.util.Bits;
 import org.apache.solr.search.MutableValueInt;
 import org.apache.solr.search.MutableValue;
@@ -45,8 +46,8 @@ public class IntFieldSource extends Nume
   }
 
 
-  public DocValues getValues(Map context, IndexReader reader) throws IOException {
-    final IntValues vals = cache.getInts(reader, field, creator);
+  public DocValues getValues(Map context, AtomicReaderContext readerContext) throws IOException {
+    final IntValues vals = cache.getInts(readerContext.reader, field, creator);
     final int[] arr = vals.values;
 	final Bits valid = vals.valid;
     

Modified: lucene/dev/branches/realtime_search/solr/src/java/org/apache/solr/search/function/JoinDocFreqValueSource.java
URL: http://svn.apache.org/viewvc/lucene/dev/branches/realtime_search/solr/src/java/org/apache/solr/search/function/JoinDocFreqValueSource.java?rev=1058718&r1=1058717&r2=1058718&view=diff
==============================================================================
--- lucene/dev/branches/realtime_search/solr/src/java/org/apache/solr/search/function/JoinDocFreqValueSource.java (original)
+++ lucene/dev/branches/realtime_search/solr/src/java/org/apache/solr/search/function/JoinDocFreqValueSource.java Thu Jan 13 19:53:21 2011
@@ -21,10 +21,11 @@ import java.io.IOException;
 import java.util.Map;
 
 import org.apache.lucene.index.IndexReader;
+import org.apache.lucene.index.IndexReader.AtomicReaderContext;
 import org.apache.lucene.search.FieldCache.DocTerms;
 import org.apache.lucene.util.BytesRef;
+import org.apache.lucene.util.ReaderUtil;
 import org.apache.solr.common.SolrException;
-import org.apache.solr.search.SolrIndexReader;
 
 /**
  * Use a field value and find the Document Frequency within another field.
@@ -46,21 +47,10 @@ public class JoinDocFreqValueSource exte
     return NAME + "(" + field +":("+qfield+"))";
   }
 
-  public DocValues getValues(Map context, IndexReader reader) throws IOException 
+  public DocValues getValues(Map context, AtomicReaderContext readerContext) throws IOException 
   {
-    final DocTerms terms = cache.getTerms(reader, field, true );
-    
-    int offset = 0;
-    IndexReader topReader = reader;
-    if (topReader instanceof SolrIndexReader) {
-      SolrIndexReader r = (SolrIndexReader)topReader;
-      while (r.getParent() != null) {
-        offset += r.getBase();
-        r = r.getParent();
-      }
-      topReader = r;
-    }
-    final IndexReader top = topReader;
+    final DocTerms terms = cache.getTerms(readerContext.reader, field, true );
+    final IndexReader top = ReaderUtil.getTopLevelContext(readerContext).reader;
     
     return new DocValues() {
       BytesRef ref = new BytesRef();

Modified: lucene/dev/branches/realtime_search/solr/src/java/org/apache/solr/search/function/LinearFloatFunction.java
URL: http://svn.apache.org/viewvc/lucene/dev/branches/realtime_search/solr/src/java/org/apache/solr/search/function/LinearFloatFunction.java?rev=1058718&r1=1058717&r2=1058718&view=diff
==============================================================================
--- lucene/dev/branches/realtime_search/solr/src/java/org/apache/solr/search/function/LinearFloatFunction.java (original)
+++ lucene/dev/branches/realtime_search/solr/src/java/org/apache/solr/search/function/LinearFloatFunction.java Thu Jan 13 19:53:21 2011
@@ -17,8 +17,8 @@
 
 package org.apache.solr.search.function;
 
-import org.apache.lucene.index.IndexReader;
-import org.apache.lucene.search.Searcher;
+import org.apache.lucene.index.IndexReader.AtomicReaderContext;
+import org.apache.lucene.search.IndexSearcher;
 
 import java.io.IOException;
 import java.util.Map;
@@ -46,8 +46,8 @@ public class LinearFloatFunction extends
     return slope + "*float(" + source.description() + ")+" + intercept;
   }
 
-  public DocValues getValues(Map context, IndexReader reader) throws IOException {
-    final DocValues vals =  source.getValues(context, reader);
+  public DocValues getValues(Map context, AtomicReaderContext readerContext) throws IOException {
+    final DocValues vals =  source.getValues(context, readerContext);
     return new DocValues() {
       public float floatVal(int doc) {
         return vals.floatVal(doc) * slope + intercept;
@@ -71,7 +71,7 @@ public class LinearFloatFunction extends
   }
 
   @Override
-  public void createWeight(Map context, Searcher searcher) throws IOException {
+  public void createWeight(Map context, IndexSearcher searcher) throws IOException {
     source.createWeight(context, searcher);
   }
 

Modified: lucene/dev/branches/realtime_search/solr/src/java/org/apache/solr/search/function/LiteralValueSource.java
URL: http://svn.apache.org/viewvc/lucene/dev/branches/realtime_search/solr/src/java/org/apache/solr/search/function/LiteralValueSource.java?rev=1058718&r1=1058717&r2=1058718&view=diff
==============================================================================
--- lucene/dev/branches/realtime_search/solr/src/java/org/apache/solr/search/function/LiteralValueSource.java (original)
+++ lucene/dev/branches/realtime_search/solr/src/java/org/apache/solr/search/function/LiteralValueSource.java Thu Jan 13 19:53:21 2011
@@ -16,7 +16,7 @@ package org.apache.solr.search.function;
  * limitations under the License.
  */
 
-import org.apache.lucene.index.IndexReader;
+import org.apache.lucene.index.IndexReader.AtomicReaderContext;
 
 import java.util.Map;
 import java.io.IOException;
@@ -38,7 +38,7 @@ public class LiteralValueSource extends 
   }
 
   @Override
-  public DocValues getValues(Map context, IndexReader reader) throws IOException {
+  public DocValues getValues(Map context, AtomicReaderContext readerContext) throws IOException {
 
     return new DocValues() {
       @Override

Modified: lucene/dev/branches/realtime_search/solr/src/java/org/apache/solr/search/function/LongFieldSource.java
URL: http://svn.apache.org/viewvc/lucene/dev/branches/realtime_search/solr/src/java/org/apache/solr/search/function/LongFieldSource.java?rev=1058718&r1=1058717&r2=1058718&view=diff
==============================================================================
--- lucene/dev/branches/realtime_search/solr/src/java/org/apache/solr/search/function/LongFieldSource.java (original)
+++ lucene/dev/branches/realtime_search/solr/src/java/org/apache/solr/search/function/LongFieldSource.java Thu Jan 13 19:53:21 2011
@@ -18,6 +18,7 @@
 package org.apache.solr.search.function;
 
 import org.apache.lucene.index.IndexReader;
+import org.apache.lucene.index.IndexReader.AtomicReaderContext;
 import org.apache.lucene.util.Bits;
 import org.apache.lucene.search.cache.LongValuesCreator;
 import org.apache.lucene.search.cache.CachedArray.LongValues;
@@ -50,8 +51,8 @@ public class LongFieldSource extends Num
     return Long.parseLong(extVal);
   }
 
-  public DocValues getValues(Map context, IndexReader reader) throws IOException {
-    final LongValues vals = cache.getLongs(reader, field, creator);
+  public DocValues getValues(Map context, AtomicReaderContext readerContext) throws IOException {
+    final LongValues vals = cache.getLongs(readerContext.reader, field, creator);
     final long[] arr = vals.values;
 	final Bits valid = vals.valid;
     

Modified: lucene/dev/branches/realtime_search/solr/src/java/org/apache/solr/search/function/MaxDocValueSource.java
URL: http://svn.apache.org/viewvc/lucene/dev/branches/realtime_search/solr/src/java/org/apache/solr/search/function/MaxDocValueSource.java?rev=1058718&r1=1058717&r2=1058718&view=diff
==============================================================================
--- lucene/dev/branches/realtime_search/solr/src/java/org/apache/solr/search/function/MaxDocValueSource.java (original)
+++ lucene/dev/branches/realtime_search/solr/src/java/org/apache/solr/search/function/MaxDocValueSource.java Thu Jan 13 19:53:21 2011
@@ -16,8 +16,8 @@
  */
 package org.apache.solr.search.function;
 
-import org.apache.lucene.index.IndexReader;
-import org.apache.lucene.search.Searcher;
+import org.apache.lucene.index.IndexReader.AtomicReaderContext;
+import org.apache.lucene.search.IndexSearcher;
 
 import java.io.IOException;
 import java.util.Map;
@@ -33,13 +33,13 @@ public class MaxDocValueSource extends V
   }
 
   @Override
-  public void createWeight(Map context, Searcher searcher) throws IOException {
+  public void createWeight(Map context, IndexSearcher searcher) throws IOException {
     context.put("searcher",searcher);
   }
 
   @Override
-  public DocValues getValues(Map context, IndexReader reader) throws IOException {
-    Searcher searcher = (Searcher)context.get("searcher");
+  public DocValues getValues(Map context, AtomicReaderContext readerContext) throws IOException {
+    IndexSearcher searcher = (IndexSearcher)context.get("searcher");
     return new ConstIntDocValues(searcher.maxDoc(), this);
   }
 

Modified: lucene/dev/branches/realtime_search/solr/src/java/org/apache/solr/search/function/MaxFloatFunction.java
URL: http://svn.apache.org/viewvc/lucene/dev/branches/realtime_search/solr/src/java/org/apache/solr/search/function/MaxFloatFunction.java?rev=1058718&r1=1058717&r2=1058718&view=diff
==============================================================================
--- lucene/dev/branches/realtime_search/solr/src/java/org/apache/solr/search/function/MaxFloatFunction.java (original)
+++ lucene/dev/branches/realtime_search/solr/src/java/org/apache/solr/search/function/MaxFloatFunction.java Thu Jan 13 19:53:21 2011
@@ -17,8 +17,8 @@
 
 package org.apache.solr.search.function;
 
-import org.apache.lucene.index.IndexReader;
-import org.apache.lucene.search.Searcher;
+import org.apache.lucene.index.IndexReader.AtomicReaderContext;
+import org.apache.lucene.search.IndexSearcher;
 
 import java.io.IOException;
 import java.util.Map;
@@ -45,8 +45,8 @@ public class MaxFloatFunction extends Va
     return "max(" + source.description() + "," + fval + ")";
   }
 
-  public DocValues getValues(Map context, IndexReader reader) throws IOException {
-    final DocValues vals =  source.getValues(context, reader);
+  public DocValues getValues(Map context, AtomicReaderContext readerContext) throws IOException {
+    final DocValues vals =  source.getValues(context, readerContext);
     return new DocValues() {
       public float floatVal(int doc) {
 	float v = vals.floatVal(doc);
@@ -71,7 +71,7 @@ public class MaxFloatFunction extends Va
   }
 
   @Override
-  public void createWeight(Map context, Searcher searcher) throws IOException {
+  public void createWeight(Map context, IndexSearcher searcher) throws IOException {
     source.createWeight(context, searcher);
   }
 

Modified: lucene/dev/branches/realtime_search/solr/src/java/org/apache/solr/search/function/MultiFloatFunction.java
URL: http://svn.apache.org/viewvc/lucene/dev/branches/realtime_search/solr/src/java/org/apache/solr/search/function/MultiFloatFunction.java?rev=1058718&r1=1058717&r2=1058718&view=diff
==============================================================================
--- lucene/dev/branches/realtime_search/solr/src/java/org/apache/solr/search/function/MultiFloatFunction.java (original)
+++ lucene/dev/branches/realtime_search/solr/src/java/org/apache/solr/search/function/MultiFloatFunction.java Thu Jan 13 19:53:21 2011
@@ -16,8 +16,8 @@ package org.apache.solr.search.function;
  * limitations under the License.
  */
 
-import org.apache.lucene.index.IndexReader;
-import org.apache.lucene.search.Searcher;
+import org.apache.lucene.index.IndexReader.AtomicReaderContext;
+import org.apache.lucene.search.IndexSearcher;
 
 import java.util.Map;
 import java.util.Arrays;
@@ -54,10 +54,10 @@ public abstract class MultiFloatFunction
     return sb.toString();
   }
 
-  public DocValues getValues(Map context, IndexReader reader) throws IOException {
+  public DocValues getValues(Map context, AtomicReaderContext readerContext) throws IOException {
     final DocValues[] valsArr = new DocValues[sources.length];
     for (int i=0; i<sources.length; i++) {
-      valsArr[i] = sources[i].getValues(context, reader);
+      valsArr[i] = sources[i].getValues(context, readerContext);
     }
 
     return new DocValues() {
@@ -95,7 +95,7 @@ public abstract class MultiFloatFunction
   }
 
   @Override
-  public void createWeight(Map context, Searcher searcher) throws IOException {
+  public void createWeight(Map context, IndexSearcher searcher) throws IOException {
     for (ValueSource source : sources)
       source.createWeight(context, searcher);
   }

Modified: lucene/dev/branches/realtime_search/solr/src/java/org/apache/solr/search/function/NormValueSource.java
URL: http://svn.apache.org/viewvc/lucene/dev/branches/realtime_search/solr/src/java/org/apache/solr/search/function/NormValueSource.java?rev=1058718&r1=1058717&r2=1058718&view=diff
==============================================================================
--- lucene/dev/branches/realtime_search/solr/src/java/org/apache/solr/search/function/NormValueSource.java (original)
+++ lucene/dev/branches/realtime_search/solr/src/java/org/apache/solr/search/function/NormValueSource.java Thu Jan 13 19:53:21 2011
@@ -17,8 +17,8 @@
 
 package org.apache.solr.search.function;
 
-import org.apache.lucene.index.IndexReader;
-import org.apache.lucene.search.Searcher;
+import org.apache.lucene.index.IndexReader.AtomicReaderContext;
+import org.apache.lucene.search.IndexSearcher;
 import org.apache.lucene.search.Similarity;
 import java.io.IOException;
 import java.util.Map;
@@ -39,15 +39,15 @@ public class NormValueSource extends Val
   }
 
   @Override
-  public void createWeight(Map context, Searcher searcher) throws IOException {
+  public void createWeight(Map context, IndexSearcher searcher) throws IOException {
     context.put("searcher",searcher);
   }
 
   @Override
-  public DocValues getValues(Map context, IndexReader reader) throws IOException {
-    Searcher searcher = (Searcher)context.get("searcher");
+  public DocValues getValues(Map context, AtomicReaderContext readerContext) throws IOException {
+    IndexSearcher searcher = (IndexSearcher)context.get("searcher");
     final Similarity similarity = searcher.getSimilarity();
-    final byte[] norms = reader.norms(field);
+    final byte[] norms = readerContext.reader.norms(field);
     if (norms == null) {
       return new ConstDoubleDocValues(0.0, this);
     }

Modified: lucene/dev/branches/realtime_search/solr/src/java/org/apache/solr/search/function/NumDocsValueSource.java
URL: http://svn.apache.org/viewvc/lucene/dev/branches/realtime_search/solr/src/java/org/apache/solr/search/function/NumDocsValueSource.java?rev=1058718&r1=1058717&r2=1058718&view=diff
==============================================================================
--- lucene/dev/branches/realtime_search/solr/src/java/org/apache/solr/search/function/NumDocsValueSource.java (original)
+++ lucene/dev/branches/realtime_search/solr/src/java/org/apache/solr/search/function/NumDocsValueSource.java Thu Jan 13 19:53:21 2011
@@ -16,8 +16,8 @@
  */
 package org.apache.solr.search.function;
 
-import org.apache.lucene.index.IndexReader;
-import org.apache.solr.search.SolrIndexReader;
+import org.apache.lucene.index.IndexReader.AtomicReaderContext;
+import org.apache.lucene.util.ReaderUtil;
 
 import java.io.IOException;
 import java.util.Map;
@@ -33,11 +33,9 @@ public class NumDocsValueSource extends 
   }
 
   @Override
-  public DocValues getValues(Map context, IndexReader reader) throws IOException {
+  public DocValues getValues(Map context, AtomicReaderContext readerContext) throws IOException {
     // Searcher has no numdocs so we must use the reader instead
-    SolrIndexReader topReader = (SolrIndexReader)reader;
-    while (topReader.getParent() != null) topReader = topReader.getParent();
-    return new ConstIntDocValues(topReader.numDocs(), this);
+    return new ConstIntDocValues(ReaderUtil.getTopLevelContext(readerContext).reader.numDocs(), this);
   }
 
   @Override

Modified: lucene/dev/branches/realtime_search/solr/src/java/org/apache/solr/search/function/OrdFieldSource.java
URL: http://svn.apache.org/viewvc/lucene/dev/branches/realtime_search/solr/src/java/org/apache/solr/search/function/OrdFieldSource.java?rev=1058718&r1=1058717&r2=1058718&view=diff
==============================================================================
--- lucene/dev/branches/realtime_search/solr/src/java/org/apache/solr/search/function/OrdFieldSource.java (original)
+++ lucene/dev/branches/realtime_search/solr/src/java/org/apache/solr/search/function/OrdFieldSource.java Thu Jan 13 19:53:21 2011
@@ -18,6 +18,9 @@
 package org.apache.solr.search.function;
 
 import org.apache.lucene.index.IndexReader;
+import org.apache.lucene.index.IndexReader.AtomicReaderContext;
+import org.apache.lucene.search.FieldCache;
+import org.apache.lucene.util.ReaderUtil;
 import org.apache.solr.search.MutableValue;
 import org.apache.solr.search.MutableValueInt;
 
@@ -54,39 +57,42 @@ public class OrdFieldSource extends Valu
   }
 
 
-  public DocValues getValues(Map context, IndexReader reader) throws IOException {
-    return new StringIndexDocValues(this, reader, field) {
+  public DocValues getValues(Map context, AtomicReaderContext readerContext) throws IOException {
+    final int off = readerContext.docBase;
+    final IndexReader topReader = ReaderUtil.getTopLevelContext(readerContext).reader;
+    final FieldCache.DocTermsIndex sindex = FieldCache.DEFAULT.getTermsIndex(topReader, field);
+    return new DocValues() {
       protected String toTerm(String readableValue) {
         return readableValue;
       }
       
       public float floatVal(int doc) {
-        return (float)termsIndex.getOrd(doc);
+        return (float)sindex.getOrd(doc+off);
       }
 
       public int intVal(int doc) {
-        return termsIndex.getOrd(doc);
+        return sindex.getOrd(doc+off);
       }
 
       public long longVal(int doc) {
-        return (long)termsIndex.getOrd(doc);
+        return (long)sindex.getOrd(doc+off);
       }
 
       public double doubleVal(int doc) {
-        return (double)termsIndex.getOrd(doc);
+        return (double)sindex.getOrd(doc+off);
       }
 
       public int ordVal(int doc) {
-        return termsIndex.getOrd(doc);
+        return sindex.getOrd(doc+off);
       }
 
       public int numOrd() {
-        return termsIndex.numOrd();
+        return sindex.numOrd();
       }
 
       public String strVal(int doc) {
         // the string value of the ordinal, not the string itself
-        return Integer.toString(termsIndex.getOrd(doc));
+        return Integer.toString(sindex.getOrd(doc+off));
       }
 
       public String toString(int doc) {
@@ -105,7 +111,7 @@ public class OrdFieldSource extends Valu
 
           @Override
           public void fillValue(int doc) {
-            mval.value = termsIndex.getOrd(doc);
+            mval.value = sindex.getOrd(doc);
             mval.exists = mval.value!=0;
           }
         };

Modified: lucene/dev/branches/realtime_search/solr/src/java/org/apache/solr/search/function/QueryValueSource.java
URL: http://svn.apache.org/viewvc/lucene/dev/branches/realtime_search/solr/src/java/org/apache/solr/search/function/QueryValueSource.java?rev=1058718&r1=1058717&r2=1058718&view=diff
==============================================================================
--- lucene/dev/branches/realtime_search/solr/src/java/org/apache/solr/search/function/QueryValueSource.java (original)
+++ lucene/dev/branches/realtime_search/solr/src/java/org/apache/solr/search/function/QueryValueSource.java Thu Jan 13 19:53:21 2011
@@ -18,7 +18,10 @@
 package org.apache.solr.search.function;
 
 import org.apache.lucene.index.IndexReader;
+import org.apache.lucene.index.IndexReader.AtomicReaderContext;
 import org.apache.lucene.search.*;
+import org.apache.lucene.search.Weight.ScorerContext;
+import org.apache.lucene.util.ReaderUtil;
 import org.apache.solr.common.SolrException;
 
 import java.io.IOException;
@@ -44,8 +47,8 @@ public class QueryValueSource extends Va
   }
 
   @Override
-  public DocValues getValues(Map context, IndexReader reader) throws IOException {
-    return new QueryDocValues(reader, q, defVal, context==null ? null : (Weight)context.get(this));
+  public DocValues getValues(Map fcontext, AtomicReaderContext readerContext) throws IOException {
+    return new QueryDocValues(readerContext, q, defVal, fcontext);
   }
 
   public int hashCode() {
@@ -59,7 +62,7 @@ public class QueryValueSource extends Va
   }
 
   @Override
-  public void createWeight(Map context, Searcher searcher) throws IOException {
+  public void createWeight(Map context, IndexSearcher searcher) throws IOException {
     Weight w = q.weight(searcher);
     context.put(this, w);
   }
@@ -68,9 +71,11 @@ public class QueryValueSource extends Va
 
 class QueryDocValues extends DocValues {
   final Query q;
-  final IndexReader reader;
+//  final IndexReader reader;
+  final AtomicReaderContext readerContext;
   final Weight weight;
   final float defVal;
+  final Map fcontext;
 
   Scorer scorer;
   int scorerDoc; // the document the scorer is on
@@ -78,19 +83,36 @@ class QueryDocValues extends DocValues {
   // the last document requested... start off with high value
   // to trigger a scorer reset on first access.
   int lastDocRequested=Integer.MAX_VALUE;
+  
 
-  public QueryDocValues(IndexReader reader, Query q, float defVal, Weight w) throws IOException {
-    this.reader = reader;
+  public QueryDocValues(AtomicReaderContext readerContext, Query q, float defVal, Map fcontext) throws IOException {
+    IndexReader reader = readerContext.reader;
+    this.readerContext = readerContext;
     this.q = q;
     this.defVal = defVal;
-    weight = w!=null ? w : q.weight(new IndexSearcher(reader));
+    this.fcontext = fcontext;
+
+    Weight w = fcontext==null ? null : (Weight)fcontext.get(q);
+    // TODO: sort by function doesn't weight (SOLR-1297 is open because of this bug)... so weightSearcher will currently be null
+    if (w == null) {
+      IndexSearcher weightSearcher;
+      if(fcontext == null) {
+        weightSearcher = new IndexSearcher(ReaderUtil.getTopLevelContext(readerContext), readerContext);
+      } else {
+        weightSearcher = (IndexSearcher)fcontext.get("searcher");
+        if (weightSearcher == null) {
+          weightSearcher = new IndexSearcher(ReaderUtil.getTopLevelContext(readerContext), readerContext);
+        }
+      }
+      w = q.weight(weightSearcher);
+    }
+    weight = w;
   }
 
   public float floatVal(int doc) {
     try {
       if (doc < lastDocRequested) {
-        // out-of-order access.... reset scorer.
-        scorer = weight.scorer(reader, true, false);
+        scorer = weight.scorer(readerContext, ScorerContext.def());
         if (scorer==null) return defVal;
         scorerDoc = -1;
       }

Modified: lucene/dev/branches/realtime_search/solr/src/java/org/apache/solr/search/function/RangeMapFloatFunction.java
URL: http://svn.apache.org/viewvc/lucene/dev/branches/realtime_search/solr/src/java/org/apache/solr/search/function/RangeMapFloatFunction.java?rev=1058718&r1=1058717&r2=1058718&view=diff
==============================================================================
--- lucene/dev/branches/realtime_search/solr/src/java/org/apache/solr/search/function/RangeMapFloatFunction.java (original)
+++ lucene/dev/branches/realtime_search/solr/src/java/org/apache/solr/search/function/RangeMapFloatFunction.java Thu Jan 13 19:53:21 2011
@@ -17,8 +17,8 @@
 
 package org.apache.solr.search.function;
 
-import org.apache.lucene.index.IndexReader;
-import org.apache.lucene.search.Searcher;
+import org.apache.lucene.index.IndexReader.AtomicReaderContext;
+import org.apache.lucene.search.IndexSearcher;
 
 import java.io.IOException;
 import java.util.Map;
@@ -50,8 +50,8 @@ public class RangeMapFloatFunction exten
     return "map(" + source.description() + "," + min + "," + max + "," + target + ")";
   }
 
-  public DocValues getValues(Map context, IndexReader reader) throws IOException {
-    final DocValues vals =  source.getValues(context, reader);
+  public DocValues getValues(Map context, AtomicReaderContext readerContext) throws IOException {
+    final DocValues vals =  source.getValues(context, readerContext);
     return new DocValues() {
       public float floatVal(int doc) {
         float val = vals.floatVal(doc);
@@ -76,7 +76,7 @@ public class RangeMapFloatFunction exten
   }
 
   @Override
-  public void createWeight(Map context, Searcher searcher) throws IOException {
+  public void createWeight(Map context, IndexSearcher searcher) throws IOException {
     source.createWeight(context, searcher);
   }
 

Modified: lucene/dev/branches/realtime_search/solr/src/java/org/apache/solr/search/function/ReciprocalFloatFunction.java
URL: http://svn.apache.org/viewvc/lucene/dev/branches/realtime_search/solr/src/java/org/apache/solr/search/function/ReciprocalFloatFunction.java?rev=1058718&r1=1058717&r2=1058718&view=diff
==============================================================================
--- lucene/dev/branches/realtime_search/solr/src/java/org/apache/solr/search/function/ReciprocalFloatFunction.java (original)
+++ lucene/dev/branches/realtime_search/solr/src/java/org/apache/solr/search/function/ReciprocalFloatFunction.java Thu Jan 13 19:53:21 2011
@@ -17,8 +17,8 @@
 
 package org.apache.solr.search.function;
 
-import org.apache.lucene.index.IndexReader;
-import org.apache.lucene.search.Searcher;
+import org.apache.lucene.index.IndexReader.AtomicReaderContext;
+import org.apache.lucene.search.IndexSearcher;
 
 import java.io.IOException;
 import java.util.Map;
@@ -57,8 +57,8 @@ public class ReciprocalFloatFunction ext
     this.b=b;
   }
 
-  public DocValues getValues(Map context, IndexReader reader) throws IOException {
-    final DocValues vals = source.getValues(context, reader);
+  public DocValues getValues(Map context, AtomicReaderContext readerContext) throws IOException {
+    final DocValues vals = source.getValues(context, readerContext);
     return new DocValues() {
       public float floatVal(int doc) {
         return a/(m*vals.floatVal(doc) + b);
@@ -84,7 +84,7 @@ public class ReciprocalFloatFunction ext
   }
 
   @Override
-  public void createWeight(Map context, Searcher searcher) throws IOException {
+  public void createWeight(Map context, IndexSearcher searcher) throws IOException {
     source.createWeight(context, searcher);
   }
 

Modified: lucene/dev/branches/realtime_search/solr/src/java/org/apache/solr/search/function/ReverseOrdFieldSource.java
URL: http://svn.apache.org/viewvc/lucene/dev/branches/realtime_search/solr/src/java/org/apache/solr/search/function/ReverseOrdFieldSource.java?rev=1058718&r1=1058717&r2=1058718&view=diff
==============================================================================
--- lucene/dev/branches/realtime_search/solr/src/java/org/apache/solr/search/function/ReverseOrdFieldSource.java (original)
+++ lucene/dev/branches/realtime_search/solr/src/java/org/apache/solr/search/function/ReverseOrdFieldSource.java Thu Jan 13 19:53:21 2011
@@ -18,7 +18,9 @@
 package org.apache.solr.search.function;
 
 import org.apache.lucene.index.IndexReader;
+import org.apache.lucene.index.IndexReader.AtomicReaderContext;
 import org.apache.lucene.search.FieldCache;
+import org.apache.lucene.util.ReaderUtil;
 
 import java.io.IOException;
 import java.util.Map;
@@ -55,26 +57,28 @@ public class ReverseOrdFieldSource exten
     return "rord("+field+')';
   }
 
-  public DocValues getValues(Map context, IndexReader reader) throws IOException {
-    final FieldCache.DocTermsIndex sindex = FieldCache.DEFAULT.getTermsIndex(reader, field);
+  public DocValues getValues(Map context, AtomicReaderContext readerContext) throws IOException {
+    final IndexReader topReader = ReaderUtil.getTopLevelContext(readerContext).reader;
+    final int off = readerContext.docBase;
 
+    final FieldCache.DocTermsIndex sindex = FieldCache.DEFAULT.getTermsIndex(topReader, field);
     final int end = sindex.numOrd();
 
     return new DocValues() {
       public float floatVal(int doc) {
-        return (float)(end - sindex.getOrd(doc));
+        return (float)(end - sindex.getOrd(doc+off));
       }
 
       public int intVal(int doc) {
-        return (end - sindex.getOrd(doc));
+        return (end - sindex.getOrd(doc+off));
       }
 
       public long longVal(int doc) {
-        return (long)(end - sindex.getOrd(doc));
+        return (long)(end - sindex.getOrd(doc+off));
       }
 
       public int ordVal(int doc) {
-        return (end - sindex.getOrd(doc));
+        return (end - sindex.getOrd(doc+off));
       }
 
       public int numOrd() {
@@ -82,12 +86,12 @@ public class ReverseOrdFieldSource exten
       }
 
       public double doubleVal(int doc) {
-        return (double)(end - sindex.getOrd(doc));
+        return (double)(end - sindex.getOrd(doc+off));
       }
 
       public String strVal(int doc) {
         // the string value of the ordinal, not the string itself
-        return Integer.toString((end - sindex.getOrd(doc)));
+        return Integer.toString((end - sindex.getOrd(doc+off)));
       }
 
       public String toString(int doc) {

Modified: lucene/dev/branches/realtime_search/solr/src/java/org/apache/solr/search/function/ScaleFloatFunction.java
URL: http://svn.apache.org/viewvc/lucene/dev/branches/realtime_search/solr/src/java/org/apache/solr/search/function/ScaleFloatFunction.java?rev=1058718&r1=1058717&r2=1058718&view=diff
==============================================================================
--- lucene/dev/branches/realtime_search/solr/src/java/org/apache/solr/search/function/ScaleFloatFunction.java (original)
+++ lucene/dev/branches/realtime_search/solr/src/java/org/apache/solr/search/function/ScaleFloatFunction.java Thu Jan 13 19:53:21 2011
@@ -17,8 +17,9 @@
 
 package org.apache.solr.search.function;
 
-import org.apache.lucene.index.IndexReader;
-import org.apache.lucene.search.Searcher;
+import org.apache.lucene.index.IndexReader.AtomicReaderContext;
+import org.apache.lucene.search.IndexSearcher;
+import org.apache.lucene.util.ReaderUtil;
 
 import java.io.IOException;
 import java.util.Map;
@@ -49,24 +50,22 @@ public class ScaleFloatFunction extends 
     return "scale(" + source.description() + "," + min + "," + max + ")";
   }
 
-  public DocValues getValues(Map context, IndexReader reader) throws IOException {
-    final DocValues vals =  source.getValues(context, reader);
-    int maxDoc = reader.maxDoc();
-
-    // this doesn't take into account deleted docs!
-    float minVal=0.0f;
-    float maxVal=0.0f;
+  private static class ScaleInfo {
+    float minVal;
+    float maxVal;
+  }
 
-    if (maxDoc>0) {
-      minVal = maxVal = vals.floatVal(0);      
-    }
+  private ScaleInfo createScaleInfo(Map context, AtomicReaderContext readerContext) throws IOException {
+    final AtomicReaderContext[] leaves = ReaderUtil.leaves(ReaderUtil.getTopLevelContext(readerContext));
+
+    float minVal = Float.POSITIVE_INFINITY;
+    float maxVal = Float.NEGATIVE_INFINITY;
 
-    // Traverse the complete set of values to get the min and the max.
-    // Future alternatives include being able to ask a DocValues for min/max
-    // Another memory-intensive option is to cache the values in
-    // a float[] on this first pass.
+    for (AtomicReaderContext leaf : leaves) {
+      int maxDoc = leaf.reader.maxDoc();
+      DocValues vals =  source.getValues(context, leaf);
+      for (int i=0; i<maxDoc; i++) {
 
-    for (int i=0; i<maxDoc; i++) {
       float val = vals.floatVal(i);
       if ((Float.floatToRawIntBits(val) & (0xff<<23)) == 0xff<<23) {
         // if the exponent in the float is all ones, then this is +Inf, -Inf or NaN
@@ -75,14 +74,37 @@ public class ScaleFloatFunction extends 
       }
       if (val < minVal) {
         minVal = val;
-      } else if (val > maxVal) {
+      }
+      if (val > maxVal) {
         maxVal = val;
       }
     }
+    }
+
+    if (minVal == Float.POSITIVE_INFINITY) {
+    // must have been an empty index
+      minVal = maxVal = 0;
+    }
+
+    ScaleInfo scaleInfo = new ScaleInfo();
+    scaleInfo.minVal = minVal;
+    scaleInfo.maxVal = maxVal;
+    context.put(this.source, scaleInfo);
+    return scaleInfo;
+  }
+
+  public DocValues getValues(Map context, AtomicReaderContext readerContext) throws IOException {
+
+    ScaleInfo scaleInfo = (ScaleInfo)context.get(source);
+    if (scaleInfo == null) {
+      scaleInfo = createScaleInfo(context, readerContext);
+    }
+
+    final float scale = (scaleInfo.maxVal-scaleInfo.minVal==0) ? 0 : (max-min)/(scaleInfo.maxVal-scaleInfo.minVal);
+    final float minSource = scaleInfo.minVal;
+    final float maxSource = scaleInfo.maxVal;
 
-    final float scale = (maxVal-minVal==0) ? 0 : (max-min)/(maxVal-minVal);
-    final float minSource = minVal;
-    final float maxSource = maxVal;
+    final DocValues vals =  source.getValues(context, readerContext);
 
     return new DocValues() {
       public float floatVal(int doc) {
@@ -110,7 +132,7 @@ public class ScaleFloatFunction extends 
   }
 
   @Override
-  public void createWeight(Map context, Searcher searcher) throws IOException {
+  public void createWeight(Map context, IndexSearcher searcher) throws IOException {
     source.createWeight(context, searcher);
   }
 

Modified: lucene/dev/branches/realtime_search/solr/src/java/org/apache/solr/search/function/ShortFieldSource.java
URL: http://svn.apache.org/viewvc/lucene/dev/branches/realtime_search/solr/src/java/org/apache/solr/search/function/ShortFieldSource.java?rev=1058718&r1=1058717&r2=1058718&view=diff
==============================================================================
--- lucene/dev/branches/realtime_search/solr/src/java/org/apache/solr/search/function/ShortFieldSource.java (original)
+++ lucene/dev/branches/realtime_search/solr/src/java/org/apache/solr/search/function/ShortFieldSource.java Thu Jan 13 19:53:21 2011
@@ -18,7 +18,7 @@ package org.apache.solr.search.function;
 
 import org.apache.lucene.search.cache.ShortValuesCreator;
 import org.apache.lucene.search.cache.CachedArray.ShortValues;
-import org.apache.lucene.index.IndexReader;
+import org.apache.lucene.index.IndexReader.AtomicReaderContext;
 
 import java.io.IOException;
 import java.util.Map;
@@ -39,8 +39,8 @@ public class ShortFieldSource extends Nu
     return "short(" + field + ')';
   }
 
-  public DocValues getValues(Map context, IndexReader reader) throws IOException {
-    final ShortValues vals = cache.getShorts(reader, field, creator);
+  public DocValues getValues(Map context, AtomicReaderContext readerContext) throws IOException {
+    final ShortValues vals = cache.getShorts(readerContext.reader, field, creator);
     final short[] arr = vals.values;
     
     return new DocValues() {

Modified: lucene/dev/branches/realtime_search/solr/src/java/org/apache/solr/search/function/SimpleFloatFunction.java
URL: http://svn.apache.org/viewvc/lucene/dev/branches/realtime_search/solr/src/java/org/apache/solr/search/function/SimpleFloatFunction.java?rev=1058718&r1=1058717&r2=1058718&view=diff
==============================================================================
--- lucene/dev/branches/realtime_search/solr/src/java/org/apache/solr/search/function/SimpleFloatFunction.java (original)
+++ lucene/dev/branches/realtime_search/solr/src/java/org/apache/solr/search/function/SimpleFloatFunction.java Thu Jan 13 19:53:21 2011
@@ -17,7 +17,7 @@
 
 package org.apache.solr.search.function;
 
-import org.apache.lucene.index.IndexReader;
+import org.apache.lucene.index.IndexReader.AtomicReaderContext;
 
 import java.io.IOException;
 import java.util.Map;
@@ -32,8 +32,8 @@ import java.util.Map;
   protected abstract float func(int doc, DocValues vals);
 
   @Override
-  public DocValues getValues(Map context, IndexReader reader) throws IOException {
-    final DocValues vals =  source.getValues(context, reader);
+  public DocValues getValues(Map context, AtomicReaderContext readerContext) throws IOException {
+    final DocValues vals =  source.getValues(context, readerContext);
     return new DocValues() {
       public float floatVal(int doc) {
 	return func(doc, vals);

Modified: lucene/dev/branches/realtime_search/solr/src/java/org/apache/solr/search/function/SingleFunction.java
URL: http://svn.apache.org/viewvc/lucene/dev/branches/realtime_search/solr/src/java/org/apache/solr/search/function/SingleFunction.java?rev=1058718&r1=1058717&r2=1058718&view=diff
==============================================================================
--- lucene/dev/branches/realtime_search/solr/src/java/org/apache/solr/search/function/SingleFunction.java (original)
+++ lucene/dev/branches/realtime_search/solr/src/java/org/apache/solr/search/function/SingleFunction.java Thu Jan 13 19:53:21 2011
@@ -17,7 +17,7 @@
 
 package org.apache.solr.search.function;
 
-import org.apache.lucene.search.Searcher;
+import org.apache.lucene.search.IndexSearcher;
 
 import java.io.IOException;
 import java.util.Map;
@@ -49,7 +49,7 @@ import java.util.Map;
   }
 
   @Override
-  public void createWeight(Map context, Searcher searcher) throws IOException {
+  public void createWeight(Map context, IndexSearcher searcher) throws IOException {
     source.createWeight(context, searcher);
   }
 }
\ No newline at end of file

Modified: lucene/dev/branches/realtime_search/solr/src/java/org/apache/solr/search/function/StringIndexDocValues.java
URL: http://svn.apache.org/viewvc/lucene/dev/branches/realtime_search/solr/src/java/org/apache/solr/search/function/StringIndexDocValues.java?rev=1058718&r1=1058717&r2=1058718&view=diff
==============================================================================
--- lucene/dev/branches/realtime_search/solr/src/java/org/apache/solr/search/function/StringIndexDocValues.java (original)
+++ lucene/dev/branches/realtime_search/solr/src/java/org/apache/solr/search/function/StringIndexDocValues.java Thu Jan 13 19:53:21 2011
@@ -19,6 +19,7 @@ package org.apache.solr.search.function;
 
 import org.apache.lucene.search.FieldCache;
 import org.apache.lucene.index.IndexReader;
+import org.apache.lucene.index.IndexReader.AtomicReaderContext;
 import org.apache.lucene.util.BytesRef;
 import org.apache.solr.search.MutableValue;
 import org.apache.solr.search.MutableValueStr;
@@ -33,9 +34,9 @@ public abstract class StringIndexDocValu
     protected final ValueSource vs;
     protected final MutableValueStr val = new MutableValueStr();
 
-    public StringIndexDocValues(ValueSource vs, IndexReader reader, String field) throws IOException {
+    public StringIndexDocValues(ValueSource vs, AtomicReaderContext context, String field) throws IOException {
       try {
-        termsIndex = FieldCache.DEFAULT.getTermsIndex(reader, field);
+        termsIndex = FieldCache.DEFAULT.getTermsIndex(context.reader, field);
       } catch (RuntimeException e) {
         throw new StringIndexException(field, e);
       }

Modified: lucene/dev/branches/realtime_search/solr/src/java/org/apache/solr/search/function/TFValueSource.java
URL: http://svn.apache.org/viewvc/lucene/dev/branches/realtime_search/solr/src/java/org/apache/solr/search/function/TFValueSource.java?rev=1058718&r1=1058717&r2=1058718&view=diff
==============================================================================
--- lucene/dev/branches/realtime_search/solr/src/java/org/apache/solr/search/function/TFValueSource.java (original)
+++ lucene/dev/branches/realtime_search/solr/src/java/org/apache/solr/search/function/TFValueSource.java Thu Jan 13 19:53:21 2011
@@ -1,8 +1,9 @@
 package org.apache.solr.search.function;
 
 import org.apache.lucene.index.*;
+import org.apache.lucene.index.IndexReader.AtomicReaderContext;
 import org.apache.lucene.search.DocIdSetIterator;
-import org.apache.lucene.search.Searcher;
+import org.apache.lucene.search.IndexSearcher;
 import org.apache.lucene.search.Similarity;
 import org.apache.lucene.util.BytesRef;
 import org.apache.solr.common.SolrException;
@@ -21,11 +22,10 @@ public class TFValueSource extends TermF
   }
 
   @Override
-  public DocValues getValues(Map context, IndexReader reader) throws IOException {
-    // use MultiFields, just in case someone did a top() function
-    Fields fields = MultiFields.getFields(reader);
+  public DocValues getValues(Map context, AtomicReaderContext readerContext) throws IOException {
+    Fields fields = readerContext.reader.fields();
     final Terms terms = fields.terms(field);
-    final Similarity similarity = ((Searcher)context.get("searcher")).getSimilarity();
+    final Similarity similarity = ((IndexSearcher)context.get("searcher")).getSimilarity();
 
     return new FloatDocValues(this) {
       DocsEnum docs ;

Modified: lucene/dev/branches/realtime_search/solr/src/java/org/apache/solr/search/function/TermFreqValueSource.java
URL: http://svn.apache.org/viewvc/lucene/dev/branches/realtime_search/solr/src/java/org/apache/solr/search/function/TermFreqValueSource.java?rev=1058718&r1=1058717&r2=1058718&view=diff
==============================================================================
--- lucene/dev/branches/realtime_search/solr/src/java/org/apache/solr/search/function/TermFreqValueSource.java (original)
+++ lucene/dev/branches/realtime_search/solr/src/java/org/apache/solr/search/function/TermFreqValueSource.java Thu Jan 13 19:53:21 2011
@@ -18,6 +18,7 @@
 package org.apache.solr.search.function;
 
 import org.apache.lucene.index.*;
+import org.apache.lucene.index.IndexReader.AtomicReaderContext;
 import org.apache.lucene.search.DocIdSetIterator;
 import org.apache.lucene.util.BytesRef;
 import org.apache.solr.common.SolrException;
@@ -36,9 +37,8 @@ public class TermFreqValueSource extends
   }
 
   @Override
-  public DocValues getValues(Map context, IndexReader reader) throws IOException {
-    // use MultiFields, just in case someone did a top() function
-    Fields fields = MultiFields.getFields(reader);
+  public DocValues getValues(Map context, AtomicReaderContext readerContext) throws IOException {
+    Fields fields = readerContext.reader.fields();
     final Terms terms = fields.terms(field);
 
     return new IntDocValues(this) {



Mime
View raw message