diff --git a/lucene/analysis/smartcn/src/java/org/apache/lucene/analysis/cn/smart/hhmm/WordDictionary.java b/lucene/analysis/smartcn/src/java/org/apache/lucene/analysis/cn/smart/hhmm/WordDictionary.java
index 5d28a7b..c6ba30f 100644
--- a/lucene/analysis/smartcn/src/java/org/apache/lucene/analysis/cn/smart/hhmm/WordDictionary.java
+++ b/lucene/analysis/smartcn/src/java/org/apache/lucene/analysis/cn/smart/hhmm/WordDictionary.java
@@ -163,7 +163,6 @@ class WordDictionary extends AbstractDictionary {
       output.writeObject(charIndexTable);
       output.writeObject(wordItem_charArrayTable);
       output.writeObject(wordItem_frequencyTable);
-      output.close();
       // log.info("serialize core dict.");
     } catch (Exception e) {
       // log.warn(e.getMessage());
diff --git a/lucene/classification/src/java/org/apache/lucene/classification/utils/DatasetSplitter.java b/lucene/classification/src/java/org/apache/lucene/classification/utils/DatasetSplitter.java
index 7ab674e..765afbc 100644
--- a/lucene/classification/src/java/org/apache/lucene/classification/utils/DatasetSplitter.java
+++ b/lucene/classification/src/java/org/apache/lucene/classification/utils/DatasetSplitter.java
@@ -121,7 +121,7 @@ public class DatasetSplitter {
       int b = 0;
 
       // iterate over existing documents
-      for (GroupDocs group : topGroups.groups) {
+      for (GroupDocs<?> group : topGroups.groups) {
         int totalHits = group.totalHits;
         double testSize = totalHits * testRatio;
         int tc = 0;
diff --git a/lucene/classification/src/test/org/apache/lucene/classification/document/DocumentClassificationTestBase.java b/lucene/classification/src/test/org/apache/lucene/classification/document/DocumentClassificationTestBase.java
index 3848151..41a4969 100644
--- a/lucene/classification/src/test/org/apache/lucene/classification/document/DocumentClassificationTestBase.java
+++ b/lucene/classification/src/test/org/apache/lucene/classification/document/DocumentClassificationTestBase.java
@@ -36,7 +36,7 @@ import org.junit.Before;
 /**
  * Base class for testing {@link org.apache.lucene.classification.Classifier}s
  */
-public abstract class DocumentClassificationTestBase<T> extends ClassificationTestBase {
+public abstract class DocumentClassificationTestBase<T> extends ClassificationTestBase<T> {
 
   protected static final BytesRef VIDEOGAME_RESULT = new BytesRef("videogames");
   protected static final BytesRef VIDEOGAME_ANALYZED_RESULT = new BytesRef("videogam");
diff --git a/lucene/expressions/src/java/org/apache/lucene/expressions/ExpressionComparator.java b/lucene/expressions/src/java/org/apache/lucene/expressions/ExpressionComparator.java
index eabf6dd..0c4b8a1 100644
--- a/lucene/expressions/src/java/org/apache/lucene/expressions/ExpressionComparator.java
+++ b/lucene/expressions/src/java/org/apache/lucene/expressions/ExpressionComparator.java
@@ -17,12 +17,11 @@
 package org.apache.lucene.expressions;
 
 import java.io.IOException;
-import java.util.HashMap;
-import java.util.Map;
 
 import org.apache.lucene.index.LeafReaderContext;
 import org.apache.lucene.queries.function.FunctionValues;
 import org.apache.lucene.queries.function.ValueSource;
+import org.apache.lucene.queries.function.ContextMap;
 import org.apache.lucene.search.FieldComparator;
 import org.apache.lucene.search.LeafFieldComparator;
 import org.apache.lucene.search.Scorer;
@@ -48,7 +47,7 @@ class ExpressionComparator extends FieldComparator<Double> implements LeafFieldC
     // TODO: might be cleaner to lazy-init 'source' and set scorer after?
     assert readerContext != null;
     try {
-      Map<String,Object> context = new HashMap<>();
+      ContextMap context = new ContextMap();
       assert scorer != null;
       context.put("scorer", scorer);
       scores = source.getValues(context, readerContext);
diff --git a/lucene/expressions/src/java/org/apache/lucene/expressions/ExpressionRescorer.java b/lucene/expressions/src/java/org/apache/lucene/expressions/ExpressionRescorer.java
index 33e8428..cc9a6cc 100644
--- a/lucene/expressions/src/java/org/apache/lucene/expressions/ExpressionRescorer.java
+++ b/lucene/expressions/src/java/org/apache/lucene/expressions/ExpressionRescorer.java
@@ -20,13 +20,12 @@ package org.apache.lucene.expressions;
 import java.io.IOException;
 import java.util.ArrayList;
 import java.util.Arrays;
-import java.util.HashMap;
 import java.util.List;
-import java.util.Map;
 
 import org.apache.lucene.index.LeafReaderContext;
 import org.apache.lucene.index.ReaderUtil;
 import org.apache.lucene.queries.function.ValueSource;
+import org.apache.lucene.queries.function.ContextMap;
 import org.apache.lucene.search.Explanation;
 import org.apache.lucene.search.IndexSearcher;
 import org.apache.lucene.search.Rescorer;
@@ -65,7 +64,7 @@ class ExpressionRescorer extends SortRescorer {
     int subReader = ReaderUtil.subIndex(docID, leaves);
     LeafReaderContext readerContext = leaves.get(subReader);
     int docIDInSegment = docID - readerContext.docBase;
-    Map<String,Object> context = new HashMap<>();
+    ContextMap context = new ContextMap();
 
     FakeScorer fakeScorer = new FakeScorer();
     fakeScorer.score = firstPassExplanation.getValue();
diff --git a/lucene/expressions/src/java/org/apache/lucene/expressions/ExpressionValueSource.java b/lucene/expressions/src/java/org/apache/lucene/expressions/ExpressionValueSource.java
index fcba455..e4741a8 100644
--- a/lucene/expressions/src/java/org/apache/lucene/expressions/ExpressionValueSource.java
+++ b/lucene/expressions/src/java/org/apache/lucene/expressions/ExpressionValueSource.java
@@ -24,12 +24,12 @@ import java.util.Map;
 import org.apache.lucene.index.LeafReaderContext;
 import org.apache.lucene.queries.function.FunctionValues;
 import org.apache.lucene.queries.function.ValueSource;
+import org.apache.lucene.queries.function.ContextMap;
 import org.apache.lucene.search.SortField;
 
 /**
  * A {@link ValueSource} which evaluates a {@link Expression} given the context of an {@link Bindings}.
  */
-@SuppressWarnings({"rawtypes", "unchecked"})
 final class ExpressionValueSource extends ValueSource {
   final ValueSource variables[];
   final Expression expression;
@@ -58,11 +58,12 @@ final class ExpressionValueSource extends ValueSource {
   }
 
   @Override
-  public FunctionValues getValues(Map context, LeafReaderContext readerContext) throws IOException {
+  public FunctionValues getValues(ContextMap context, LeafReaderContext readerContext) throws IOException {
+    @SuppressWarnings({"unchecked"})
     Map<String, FunctionValues> valuesCache = (Map<String, FunctionValues>) context.get("valuesCache");
     if (valuesCache == null) {
       valuesCache = new HashMap<>();
-      context = new HashMap(context);
+      context = new ContextMap(context); // make a copy
       context.put("valuesCache", valuesCache);
     }
     FunctionValues[] externalValues = new FunctionValues[expression.variables.length];
diff --git a/lucene/expressions/src/java/org/apache/lucene/expressions/ScoreValueSource.java b/lucene/expressions/src/java/org/apache/lucene/expressions/ScoreValueSource.java
index ea1669c..0cb1c7a 100644
--- a/lucene/expressions/src/java/org/apache/lucene/expressions/ScoreValueSource.java
+++ b/lucene/expressions/src/java/org/apache/lucene/expressions/ScoreValueSource.java
@@ -20,23 +20,22 @@ package org.apache.lucene.expressions;
 import org.apache.lucene.index.LeafReaderContext;
 import org.apache.lucene.queries.function.FunctionValues;
 import org.apache.lucene.queries.function.ValueSource;
+import org.apache.lucene.queries.function.ContextMap;
 import org.apache.lucene.search.Scorer;
 
 import java.io.IOException;
-import java.util.Map;
 
 /**
  * A {@link ValueSource} which uses the {@link Scorer} passed through
  * the context map by {@link ExpressionComparator}.
  */
-@SuppressWarnings({"rawtypes"})
 class ScoreValueSource extends ValueSource {
 
   /**
    * <code>context</code> must contain a key "scorer" which is a {@link Scorer}.
    */
   @Override
-  public FunctionValues getValues(Map context, LeafReaderContext readerContext) throws IOException {
+  public FunctionValues getValues(ContextMap context, LeafReaderContext readerContext) throws IOException {
     Scorer v = (Scorer) context.get("scorer");
     if (v == null) {
       throw new IllegalStateException("Expressions referencing the score can only be used for sorting");
diff --git a/lucene/expressions/src/test/org/apache/lucene/expressions/TestExpressionValueSource.java b/lucene/expressions/src/test/org/apache/lucene/expressions/TestExpressionValueSource.java
index eeb3c9c..fc3ad75 100644
--- a/lucene/expressions/src/test/org/apache/lucene/expressions/TestExpressionValueSource.java
+++ b/lucene/expressions/src/test/org/apache/lucene/expressions/TestExpressionValueSource.java
@@ -16,9 +16,6 @@
  */
 package org.apache.lucene.expressions;
 
-
-import java.util.HashMap;
-
 import org.apache.lucene.analysis.MockAnalyzer;
 import org.apache.lucene.document.Document;
 import org.apache.lucene.document.Field;
@@ -30,6 +27,7 @@ import org.apache.lucene.index.IndexWriterConfig;
 import org.apache.lucene.index.RandomIndexWriter;
 import org.apache.lucene.queries.function.FunctionValues;
 import org.apache.lucene.queries.function.ValueSource;
+import org.apache.lucene.queries.function.ContextMap;
 import org.apache.lucene.queries.function.ValueSourceScorer;
 import org.apache.lucene.search.DocIdSetIterator;
 import org.apache.lucene.search.SortField;
@@ -86,7 +84,7 @@ public class TestExpressionValueSource extends LuceneTestCase {
     
     assertEquals(1, reader.leaves().size());
     LeafReaderContext leaf = reader.leaves().get(0);
-    FunctionValues values = vs.getValues(new HashMap<String,Object>(), leaf);
+    FunctionValues values = vs.getValues(new ContextMap(), leaf);
     
     assertEquals(10, values.doubleVal(0), 0);
     assertEquals(10, values.floatVal(0), 0);
@@ -124,7 +122,7 @@ public class TestExpressionValueSource extends LuceneTestCase {
     
     assertEquals(1, reader.leaves().size());
     LeafReaderContext leaf = reader.leaves().get(0);
-    FunctionValues values = vs.getValues(new HashMap<String,Object>(), leaf);
+    FunctionValues values = vs.getValues(new ContextMap(), leaf);
     
     // everything
     ValueSourceScorer scorer = values.getRangeScorer(leaf, "4", "40", true, true);
@@ -136,7 +134,7 @@ public class TestExpressionValueSource extends LuceneTestCase {
     assertEquals(DocIdSetIterator.NO_MORE_DOCS, iter.nextDoc());
 
     // just the first doc
-    values = vs.getValues(new HashMap<String,Object>(), leaf);
+    values = vs.getValues(new ContextMap(), leaf);
     scorer = values.getRangeScorer(leaf, "4", "40", false, false);
     iter = scorer.iterator();
     assertEquals(-1, scorer.docID());
diff --git a/lucene/facet/src/java/org/apache/lucene/facet/range/DoubleRange.java b/lucene/facet/src/java/org/apache/lucene/facet/range/DoubleRange.java
index 2203be3..26b2a6d 100644
--- a/lucene/facet/src/java/org/apache/lucene/facet/range/DoubleRange.java
+++ b/lucene/facet/src/java/org/apache/lucene/facet/range/DoubleRange.java
@@ -17,12 +17,12 @@
 package org.apache.lucene.facet.range;
 
 import java.io.IOException;
-import java.util.Collections;
 import java.util.Objects;
 
 import org.apache.lucene.index.IndexReader;
 import org.apache.lucene.index.LeafReaderContext;
 import org.apache.lucene.queries.function.FunctionValues;
+import org.apache.lucene.queries.function.ContextMap;
 import org.apache.lucene.queries.function.ValueSource;
 import org.apache.lucene.search.ConstantScoreScorer;
 import org.apache.lucene.search.ConstantScoreWeight;
@@ -158,7 +158,7 @@ public final class DoubleRange extends Range {
             approximation = s.iterator();
           }
 
-          final FunctionValues values = valueSource.getValues(Collections.emptyMap(), context);
+          final FunctionValues values = valueSource.getValues(new ContextMap(), context);
           final TwoPhaseIterator twoPhase = new TwoPhaseIterator(approximation) {
             @Override
             public boolean matches() throws IOException {
diff --git a/lucene/facet/src/java/org/apache/lucene/facet/range/DoubleRangeFacetCounts.java b/lucene/facet/src/java/org/apache/lucene/facet/range/DoubleRangeFacetCounts.java
index 2d0ba5c..62c2a5a 100644
--- a/lucene/facet/src/java/org/apache/lucene/facet/range/DoubleRangeFacetCounts.java
+++ b/lucene/facet/src/java/org/apache/lucene/facet/range/DoubleRangeFacetCounts.java
@@ -17,7 +17,6 @@
 package org.apache.lucene.facet.range;
 
 import java.io.IOException;
-import java.util.Collections;
 import java.util.List;
 
 import org.apache.lucene.document.DoubleDocValuesField; // javadocs
@@ -28,6 +27,7 @@ import org.apache.lucene.facet.FacetsCollector;
 import org.apache.lucene.index.IndexReaderContext;
 import org.apache.lucene.index.ReaderUtil;
 import org.apache.lucene.queries.function.FunctionValues;
+import org.apache.lucene.queries.function.ContextMap;
 import org.apache.lucene.queries.function.ValueSource;
 import org.apache.lucene.queries.function.valuesource.DoubleFieldSource;
 import org.apache.lucene.queries.function.valuesource.FloatFieldSource; // javadocs
@@ -96,7 +96,7 @@ public class DoubleRangeFacetCounts extends RangeFacetCounts {
 
     int missingCount = 0;
     for (MatchingDocs hits : matchingDocs) {
-      FunctionValues fv = valueSource.getValues(Collections.emptyMap(), hits.context);
+      FunctionValues fv = valueSource.getValues(new ContextMap(), hits.context);
       
       totCount += hits.totalHits;
       final DocIdSetIterator fastMatchDocs;
diff --git a/lucene/facet/src/java/org/apache/lucene/facet/range/LongRange.java b/lucene/facet/src/java/org/apache/lucene/facet/range/LongRange.java
index 9c12ecd..d171826 100644
--- a/lucene/facet/src/java/org/apache/lucene/facet/range/LongRange.java
+++ b/lucene/facet/src/java/org/apache/lucene/facet/range/LongRange.java
@@ -17,12 +17,12 @@
 package org.apache.lucene.facet.range;
 
 import java.io.IOException;
-import java.util.Collections;
 import java.util.Objects;
 
 import org.apache.lucene.index.IndexReader;
 import org.apache.lucene.index.LeafReaderContext;
 import org.apache.lucene.queries.function.FunctionValues;
+import org.apache.lucene.queries.function.ContextMap;
 import org.apache.lucene.queries.function.ValueSource;
 import org.apache.lucene.search.ConstantScoreScorer;
 import org.apache.lucene.search.ConstantScoreWeight;
@@ -150,7 +150,7 @@ public final class LongRange extends Range {
             approximation = s.iterator();
           }
 
-          final FunctionValues values = valueSource.getValues(Collections.emptyMap(), context);
+          final FunctionValues values = valueSource.getValues(new ContextMap(), context);
           final TwoPhaseIterator twoPhase = new TwoPhaseIterator(approximation) {
             @Override
             public boolean matches() throws IOException {
diff --git a/lucene/facet/src/java/org/apache/lucene/facet/range/LongRangeFacetCounts.java b/lucene/facet/src/java/org/apache/lucene/facet/range/LongRangeFacetCounts.java
index 0512ab3..5e771e0 100644
--- a/lucene/facet/src/java/org/apache/lucene/facet/range/LongRangeFacetCounts.java
+++ b/lucene/facet/src/java/org/apache/lucene/facet/range/LongRangeFacetCounts.java
@@ -17,7 +17,6 @@
 package org.apache.lucene.facet.range;
 
 import java.io.IOException;
-import java.util.Collections;
 import java.util.List;
 
 import org.apache.lucene.facet.Facets;
@@ -26,6 +25,7 @@ import org.apache.lucene.facet.FacetsCollector;
 import org.apache.lucene.index.IndexReaderContext;
 import org.apache.lucene.index.ReaderUtil;
 import org.apache.lucene.queries.function.FunctionValues;
+import org.apache.lucene.queries.function.ContextMap;
 import org.apache.lucene.queries.function.ValueSource;
 import org.apache.lucene.queries.function.valuesource.LongFieldSource;
 import org.apache.lucene.search.DocIdSet;
@@ -77,7 +77,7 @@ public class LongRangeFacetCounts extends RangeFacetCounts {
 
     int missingCount = 0;
     for (MatchingDocs hits : matchingDocs) {
-      FunctionValues fv = valueSource.getValues(Collections.emptyMap(), hits.context);
+      FunctionValues fv = valueSource.getValues(new ContextMap(), hits.context);
       
       totCount += hits.totalHits;
       final DocIdSetIterator fastMatchDocs;
diff --git a/lucene/facet/src/java/org/apache/lucene/facet/taxonomy/TaxonomyFacetSumValueSource.java b/lucene/facet/src/java/org/apache/lucene/facet/taxonomy/TaxonomyFacetSumValueSource.java
index 4010c81..436c419 100644
--- a/lucene/facet/src/java/org/apache/lucene/facet/taxonomy/TaxonomyFacetSumValueSource.java
+++ b/lucene/facet/src/java/org/apache/lucene/facet/taxonomy/TaxonomyFacetSumValueSource.java
@@ -17,15 +17,14 @@
 package org.apache.lucene.facet.taxonomy;
 
 import java.io.IOException;
-import java.util.HashMap;
 import java.util.List;
-import java.util.Map;
 
 import org.apache.lucene.facet.FacetsCollector;
 import org.apache.lucene.facet.FacetsCollector.MatchingDocs;
 import org.apache.lucene.facet.FacetsConfig;
 import org.apache.lucene.index.LeafReaderContext;
 import org.apache.lucene.queries.function.FunctionValues;
+import org.apache.lucene.queries.function.ContextMap;
 import org.apache.lucene.queries.function.ValueSource;
 import org.apache.lucene.queries.function.docvalues.DoubleDocValues;
 import org.apache.lucene.search.DocIdSetIterator;
@@ -61,7 +60,7 @@ public class TaxonomyFacetSumValueSource extends FloatTaxonomyFacets {
 
   private final void sumValues(List<MatchingDocs> matchingDocs, boolean keepScores, ValueSource valueSource) throws IOException {
     final FakeScorer scorer = new FakeScorer();
-    Map<String, Scorer> context = new HashMap<>();
+    ContextMap context = new ContextMap();
     if (keepScores) {
       context.put("scorer", scorer);
     }
@@ -102,7 +101,7 @@ public class TaxonomyFacetSumValueSource extends FloatTaxonomyFacets {
     }
 
     @Override
-    public FunctionValues getValues(@SuppressWarnings("rawtypes") Map context, LeafReaderContext readerContext) throws IOException {
+    public FunctionValues getValues(ContextMap context, LeafReaderContext readerContext) throws IOException {
       final Scorer scorer = (Scorer) context.get("scorer");
       if (scorer == null) {
         throw new IllegalStateException("scores are missing; be sure to pass keepScores=true to FacetsCollector");
diff --git a/lucene/facet/src/test/org/apache/lucene/facet/range/TestRangeFacetCounts.java b/lucene/facet/src/test/org/apache/lucene/facet/range/TestRangeFacetCounts.java
index 7250ef4..70c4e1e 100644
--- a/lucene/facet/src/test/org/apache/lucene/facet/range/TestRangeFacetCounts.java
+++ b/lucene/facet/src/test/org/apache/lucene/facet/range/TestRangeFacetCounts.java
@@ -48,6 +48,7 @@ import org.apache.lucene.index.RandomIndexWriter;
 import org.apache.lucene.index.Term;
 import org.apache.lucene.queries.function.FunctionValues;
 import org.apache.lucene.queries.function.ValueSource;
+import org.apache.lucene.queries.function.ContextMap;
 import org.apache.lucene.queries.function.docvalues.DoubleDocValues;
 import org.apache.lucene.queries.function.valuesource.DoubleFieldSource;
 import org.apache.lucene.queries.function.valuesource.LongFieldSource;
@@ -721,9 +722,8 @@ public class TestRangeFacetCounts extends FacetTestCase {
     writer.forceMerge(1);
 
     final ValueSource vs = new ValueSource() {
-        @SuppressWarnings("rawtypes")
         @Override
-        public FunctionValues getValues(Map ignored, LeafReaderContext ignored2) {
+        public FunctionValues getValues(ContextMap ignored, LeafReaderContext ignored2) {
           return new DoubleDocValues(null) {
             @Override
             public double doubleVal(int doc) {
diff --git a/lucene/facet/src/test/org/apache/lucene/facet/taxonomy/TestTaxonomyFacetSumValueSource.java b/lucene/facet/src/test/org/apache/lucene/facet/taxonomy/TestTaxonomyFacetSumValueSource.java
index 0ad90ba..1ddd65b 100644
--- a/lucene/facet/src/test/org/apache/lucene/facet/taxonomy/TestTaxonomyFacetSumValueSource.java
+++ b/lucene/facet/src/test/org/apache/lucene/facet/taxonomy/TestTaxonomyFacetSumValueSource.java
@@ -46,6 +46,7 @@ import org.apache.lucene.index.Term;
 import org.apache.lucene.queries.function.FunctionQuery;
 import org.apache.lucene.queries.function.FunctionValues;
 import org.apache.lucene.queries.function.ValueSource;
+import org.apache.lucene.queries.function.ContextMap;
 import org.apache.lucene.queries.function.docvalues.DoubleDocValues;
 import org.apache.lucene.queries.function.valuesource.FloatFieldSource;
 import org.apache.lucene.queries.function.valuesource.IntFieldSource;
@@ -320,8 +321,7 @@ public class TestTaxonomyFacetSumValueSource extends FacetTestCase {
     DirectoryTaxonomyReader taxoReader = new DirectoryTaxonomyReader(taxoWriter);
 
     ValueSource valueSource = new ValueSource() {
-      @Override
-      public FunctionValues getValues(@SuppressWarnings("rawtypes") Map context, LeafReaderContext readerContext) throws IOException {
+      public FunctionValues getValues(ContextMap context, LeafReaderContext readerContext) throws IOException {
         final Scorer scorer = (Scorer) context.get("scorer");
         assert scorer != null;
         return new DoubleDocValues(this) {
diff --git a/lucene/grouping/src/java/org/apache/lucene/search/grouping/GroupingSearch.java b/lucene/grouping/src/java/org/apache/lucene/search/grouping/GroupingSearch.java
index d0bab09..eba22f0 100644
--- a/lucene/grouping/src/java/org/apache/lucene/search/grouping/GroupingSearch.java
+++ b/lucene/grouping/src/java/org/apache/lucene/search/grouping/GroupingSearch.java
@@ -17,6 +17,7 @@
 package org.apache.lucene.search.grouping;
 
 import org.apache.lucene.queries.function.ValueSource;
+import org.apache.lucene.queries.function.ContextMap;
 import org.apache.lucene.search.CachingCollector;
 import org.apache.lucene.search.Collector;
 import org.apache.lucene.search.IndexSearcher;
@@ -42,7 +43,6 @@ import java.util.ArrayList;
 import java.util.Collection;
 import java.util.Collections;
 import java.util.List;
-import java.util.Map;
 
 /**
  * Convenience class to perform grouping in a non distributed environment.
@@ -53,7 +53,7 @@ public class GroupingSearch {
 
   private final String groupField;
   private final ValueSource groupFunction;
-  private final Map<?, ?> valueSourceContext;
+  private final ContextMap valueSourceContext;
   private final Query groupEndDocs;
 
   private Sort groupSort = Sort.RELEVANCE;
@@ -92,7 +92,7 @@ public class GroupingSearch {
    * @param groupFunction      The function to group by specified as {@link ValueSource}
    * @param valueSourceContext The context of the specified groupFunction
    */
-  public GroupingSearch(ValueSource groupFunction, Map<?, ?> valueSourceContext) {
+  public GroupingSearch(ValueSource groupFunction, ContextMap valueSourceContext) {
     this(null, groupFunction, valueSourceContext, null);
   }
 
@@ -106,7 +106,7 @@ public class GroupingSearch {
     this(null, null, null, groupEndDocs);
   }
 
-  private GroupingSearch(String groupField, ValueSource groupFunction, Map<?, ?> valueSourceContext, Query groupEndDocs) {
+  private GroupingSearch(String groupField, ValueSource groupFunction, ContextMap valueSourceContext, Query groupEndDocs) {
     this.groupField = groupField;
     this.groupFunction = groupFunction;
     this.valueSourceContext = valueSourceContext;
diff --git a/lucene/grouping/src/java/org/apache/lucene/search/grouping/function/FunctionAllGroupHeadsCollector.java b/lucene/grouping/src/java/org/apache/lucene/search/grouping/function/FunctionAllGroupHeadsCollector.java
index 4c6071c..e60195e 100644
--- a/lucene/grouping/src/java/org/apache/lucene/search/grouping/function/FunctionAllGroupHeadsCollector.java
+++ b/lucene/grouping/src/java/org/apache/lucene/search/grouping/function/FunctionAllGroupHeadsCollector.java
@@ -18,6 +18,7 @@ package org.apache.lucene.search.grouping.function;
 
 import org.apache.lucene.index.LeafReaderContext;
 import org.apache.lucene.queries.function.FunctionValues;
+import org.apache.lucene.queries.function.ContextMap;
 import org.apache.lucene.queries.function.ValueSource;
 import org.apache.lucene.search.FieldComparator;
 import org.apache.lucene.search.LeafFieldComparator;
@@ -41,7 +42,7 @@ import java.util.Map;
 public class FunctionAllGroupHeadsCollector extends AbstractAllGroupHeadsCollector<FunctionAllGroupHeadsCollector.GroupHead> {
 
   private final ValueSource groupBy;
-  private final Map<?, ?> vsContext;
+  private final ContextMap vsContext;
   private final Map<MutableValue, GroupHead> groups;
   private final Sort sortWithinGroup;
 
@@ -57,7 +58,7 @@ public class FunctionAllGroupHeadsCollector extends AbstractAllGroupHeadsCollect
    * @param vsContext The ValueSource context
    * @param sortWithinGroup The sort within a group
    */
-  public FunctionAllGroupHeadsCollector(ValueSource groupBy, Map<?, ?> vsContext, Sort sortWithinGroup) {
+  public FunctionAllGroupHeadsCollector(ValueSource groupBy, ContextMap vsContext, Sort sortWithinGroup) {
     super(sortWithinGroup.getSort().length);
     groups = new HashMap<>();
     this.sortWithinGroup = sortWithinGroup;
diff --git a/lucene/grouping/src/java/org/apache/lucene/search/grouping/function/FunctionAllGroupsCollector.java b/lucene/grouping/src/java/org/apache/lucene/search/grouping/function/FunctionAllGroupsCollector.java
index 58418ed..55d547e 100644
--- a/lucene/grouping/src/java/org/apache/lucene/search/grouping/function/FunctionAllGroupsCollector.java
+++ b/lucene/grouping/src/java/org/apache/lucene/search/grouping/function/FunctionAllGroupsCollector.java
@@ -18,13 +18,13 @@ package org.apache.lucene.search.grouping.function;
 
 import org.apache.lucene.index.LeafReaderContext;
 import org.apache.lucene.queries.function.FunctionValues;
+import org.apache.lucene.queries.function.ContextMap;
 import org.apache.lucene.queries.function.ValueSource;
 import org.apache.lucene.search.grouping.AbstractAllGroupsCollector;
 import org.apache.lucene.util.mutable.MutableValue;
 
 import java.io.IOException;
 import java.util.Collection;
-import java.util.Map;
 import java.util.SortedSet;
 import java.util.TreeSet;
 
@@ -41,7 +41,7 @@ import java.util.TreeSet;
  */
 public class FunctionAllGroupsCollector extends AbstractAllGroupsCollector<MutableValue> {
 
-  private final Map<?, ?> vsContext;
+  private final ContextMap vsContext;
   private final ValueSource groupBy;
   private final SortedSet<MutableValue> groups = new TreeSet<>();
 
@@ -54,7 +54,7 @@ public class FunctionAllGroupsCollector extends AbstractAllGroupsCollector<Mutab
    * @param groupBy The {@link ValueSource} to group by
    * @param vsContext The ValueSource context
    */
-  public FunctionAllGroupsCollector(ValueSource groupBy, Map<?, ?> vsContext) {
+  public FunctionAllGroupsCollector(ValueSource groupBy, ContextMap vsContext) {
     this.vsContext = vsContext;
     this.groupBy = groupBy;
   }
diff --git a/lucene/grouping/src/java/org/apache/lucene/search/grouping/function/FunctionDistinctValuesCollector.java b/lucene/grouping/src/java/org/apache/lucene/search/grouping/function/FunctionDistinctValuesCollector.java
index 32e9324..98d1109 100644
--- a/lucene/grouping/src/java/org/apache/lucene/search/grouping/function/FunctionDistinctValuesCollector.java
+++ b/lucene/grouping/src/java/org/apache/lucene/search/grouping/function/FunctionDistinctValuesCollector.java
@@ -18,6 +18,7 @@ package org.apache.lucene.search.grouping.function;
 
 import org.apache.lucene.index.LeafReaderContext;
 import org.apache.lucene.queries.function.FunctionValues;
+import org.apache.lucene.queries.function.ContextMap;
 import org.apache.lucene.queries.function.ValueSource;
 import org.apache.lucene.search.grouping.AbstractDistinctValuesCollector;
 import org.apache.lucene.search.grouping.SearchGroup;
@@ -33,7 +34,7 @@ import java.util.*;
  */
 public class FunctionDistinctValuesCollector extends AbstractDistinctValuesCollector<FunctionDistinctValuesCollector.GroupCount> {
 
-  private final Map<?, ?> vsContext;
+  private final ContextMap vsContext;
   private final ValueSource groupSource;
   private final ValueSource countSource;
   private final Map<MutableValue, GroupCount> groupMap;
@@ -43,7 +44,7 @@ public class FunctionDistinctValuesCollector extends AbstractDistinctValuesColle
   private MutableValue groupMval;
   private MutableValue countMval;
 
-  public FunctionDistinctValuesCollector(Map<?, ?> vsContext, ValueSource groupSource, ValueSource countSource, Collection<SearchGroup<MutableValue>> groups) {
+  public FunctionDistinctValuesCollector(ContextMap vsContext, ValueSource groupSource, ValueSource countSource, Collection<SearchGroup<MutableValue>> groups) {
     this.vsContext = vsContext;
     this.groupSource = groupSource;
     this.countSource = countSource;
diff --git a/lucene/grouping/src/java/org/apache/lucene/search/grouping/function/FunctionFirstPassGroupingCollector.java b/lucene/grouping/src/java/org/apache/lucene/search/grouping/function/FunctionFirstPassGroupingCollector.java
index 0237e21..4e4eda1 100644
--- a/lucene/grouping/src/java/org/apache/lucene/search/grouping/function/FunctionFirstPassGroupingCollector.java
+++ b/lucene/grouping/src/java/org/apache/lucene/search/grouping/function/FunctionFirstPassGroupingCollector.java
@@ -18,13 +18,13 @@ package org.apache.lucene.search.grouping.function;
 
 import org.apache.lucene.index.LeafReaderContext;
 import org.apache.lucene.queries.function.FunctionValues;
+import org.apache.lucene.queries.function.ContextMap;
 import org.apache.lucene.queries.function.ValueSource;
 import org.apache.lucene.search.Sort;
 import org.apache.lucene.search.grouping.AbstractFirstPassGroupingCollector;
 import org.apache.lucene.util.mutable.MutableValue;
 
 import java.io.IOException;
-import java.util.Map;
 
 /**
  * Concrete implementation of {@link AbstractFirstPassGroupingCollector} that groups based on
@@ -35,7 +35,7 @@ import java.util.Map;
 public class FunctionFirstPassGroupingCollector extends AbstractFirstPassGroupingCollector<MutableValue> {
 
   private final ValueSource groupByVS;
-  private final Map<?, ?> vsContext;
+  private final ContextMap vsContext;
 
   private FunctionValues.ValueFiller filler;
   private MutableValue mval;
@@ -54,7 +54,7 @@ public class FunctionFirstPassGroupingCollector extends AbstractFirstPassGroupin
    * @param topNGroups How many top groups to keep.
    * @throws IOException When I/O related errors occur
    */
-  public FunctionFirstPassGroupingCollector(ValueSource groupByVS, Map<?, ?> vsContext, Sort groupSort, int topNGroups) throws IOException {
+  public FunctionFirstPassGroupingCollector(ValueSource groupByVS, ContextMap vsContext, Sort groupSort, int topNGroups) throws IOException {
     super(groupSort, topNGroups);
     this.groupByVS = groupByVS;
     this.vsContext = vsContext;
diff --git a/lucene/grouping/src/java/org/apache/lucene/search/grouping/function/FunctionSecondPassGroupingCollector.java b/lucene/grouping/src/java/org/apache/lucene/search/grouping/function/FunctionSecondPassGroupingCollector.java
index d363267..a1f2d95 100644
--- a/lucene/grouping/src/java/org/apache/lucene/search/grouping/function/FunctionSecondPassGroupingCollector.java
+++ b/lucene/grouping/src/java/org/apache/lucene/search/grouping/function/FunctionSecondPassGroupingCollector.java
@@ -18,6 +18,7 @@ package org.apache.lucene.search.grouping.function;
 
 import org.apache.lucene.index.LeafReaderContext;
 import org.apache.lucene.queries.function.FunctionValues;
+import org.apache.lucene.queries.function.ContextMap;
 import org.apache.lucene.queries.function.ValueSource;
 import org.apache.lucene.search.Sort;
 import org.apache.lucene.search.grouping.AbstractSecondPassGroupingCollector;
@@ -27,7 +28,6 @@ import org.apache.lucene.search.grouping.TopGroups; //javadoc
 
 import java.io.IOException;
 import java.util.Collection;
-import java.util.Map;
 
 /**
  * Concrete implementation of {@link AbstractSecondPassGroupingCollector} that groups based on
@@ -38,7 +38,7 @@ import java.util.Map;
 public class FunctionSecondPassGroupingCollector extends AbstractSecondPassGroupingCollector<MutableValue> {
 
   private final ValueSource groupByVS;
-  private final Map<?, ?> vsContext;
+  private final ContextMap vsContext;
 
   private FunctionValues.ValueFiller filler;
   private MutableValue mval;
@@ -57,7 +57,16 @@ public class FunctionSecondPassGroupingCollector extends AbstractSecondPassGroup
    * @param vsContext The value source context
    * @throws IOException IOException When I/O related errors occur
    */
-  public FunctionSecondPassGroupingCollector(Collection<SearchGroup<MutableValue>> searchGroups, Sort groupSort, Sort withinGroupSort, int maxDocsPerGroup, boolean getScores, boolean getMaxScores, boolean fillSortFields, ValueSource groupByVS, Map<?, ?> vsContext) throws IOException {
+  public FunctionSecondPassGroupingCollector(
+            Collection<SearchGroup<MutableValue>> searchGroups,
+            Sort groupSort,
+            Sort withinGroupSort,
+            int maxDocsPerGroup,
+            boolean getScores,
+            boolean getMaxScores,
+            boolean fillSortFields,
+            ValueSource groupByVS,
+            ContextMap vsContext) throws IOException {
     super(searchGroups, groupSort, withinGroupSort, maxDocsPerGroup, getScores, getMaxScores, fillSortFields);
     this.groupByVS = groupByVS;
     this.vsContext = vsContext;
diff --git a/lucene/grouping/src/test/org/apache/lucene/search/grouping/AllGroupHeadsCollectorTest.java b/lucene/grouping/src/test/org/apache/lucene/search/grouping/AllGroupHeadsCollectorTest.java
index 316676b..5cde0ee 100644
--- a/lucene/grouping/src/test/org/apache/lucene/search/grouping/AllGroupHeadsCollectorTest.java
+++ b/lucene/grouping/src/test/org/apache/lucene/search/grouping/AllGroupHeadsCollectorTest.java
@@ -42,6 +42,7 @@ import org.apache.lucene.index.NumericDocValues;
 import org.apache.lucene.index.RandomIndexWriter;
 import org.apache.lucene.index.Term;
 import org.apache.lucene.queries.function.ValueSource;
+import org.apache.lucene.queries.function.ContextMap;
 import org.apache.lucene.queries.function.valuesource.BytesRefFieldSource;
 import org.apache.lucene.search.DocIdSetIterator;
 import org.apache.lucene.search.IndexSearcher;
@@ -514,7 +515,7 @@ public class AllGroupHeadsCollectorTest extends LuceneTestCase {
     AbstractAllGroupHeadsCollector<? extends AbstractAllGroupHeadsCollector.GroupHead> collector;
     if (random().nextBoolean()) {
       ValueSource vs = new BytesRefFieldSource(groupField);
-      collector =  new FunctionAllGroupHeadsCollector(vs, new HashMap<>(), sortWithinGroup);
+      collector =  new FunctionAllGroupHeadsCollector(vs, new ContextMap(), sortWithinGroup);
     } else {
       collector =  TermAllGroupHeadsCollector.create(groupField, sortWithinGroup);
     }
diff --git a/lucene/grouping/src/test/org/apache/lucene/search/grouping/AllGroupsCollectorTest.java b/lucene/grouping/src/test/org/apache/lucene/search/grouping/AllGroupsCollectorTest.java
index 30a147e..378ef99 100644
--- a/lucene/grouping/src/test/org/apache/lucene/search/grouping/AllGroupsCollectorTest.java
+++ b/lucene/grouping/src/test/org/apache/lucene/search/grouping/AllGroupsCollectorTest.java
@@ -25,6 +25,7 @@ import org.apache.lucene.document.TextField;
 import org.apache.lucene.index.RandomIndexWriter;
 import org.apache.lucene.index.Term;
 import org.apache.lucene.queries.function.ValueSource;
+import org.apache.lucene.queries.function.ContextMap;
 import org.apache.lucene.queries.function.valuesource.BytesRefFieldSource;
 import org.apache.lucene.search.IndexSearcher;
 import org.apache.lucene.search.TermQuery;
@@ -34,7 +35,6 @@ import org.apache.lucene.store.Directory;
 import org.apache.lucene.util.BytesRef;
 import org.apache.lucene.util.LuceneTestCase;
 
-import java.util.HashMap;
 
 public class AllGroupsCollectorTest extends LuceneTestCase {
 
@@ -129,7 +129,7 @@ public class AllGroupsCollectorTest extends LuceneTestCase {
       selected = new TermAllGroupsCollector(groupField);
     } else {
       ValueSource vs = new BytesRefFieldSource(groupField);
-      selected = new FunctionAllGroupsCollector(vs, new HashMap<>());
+      selected = new FunctionAllGroupsCollector(vs, new ContextMap());
     }
 
     if (VERBOSE) {
diff --git a/lucene/grouping/src/test/org/apache/lucene/search/grouping/DistinctValuesCollectorTest.java b/lucene/grouping/src/test/org/apache/lucene/search/grouping/DistinctValuesCollectorTest.java
index 313e92f..40b4a7b 100644
--- a/lucene/grouping/src/test/org/apache/lucene/search/grouping/DistinctValuesCollectorTest.java
+++ b/lucene/grouping/src/test/org/apache/lucene/search/grouping/DistinctValuesCollectorTest.java
@@ -40,6 +40,7 @@ import org.apache.lucene.index.DirectoryReader;
 import org.apache.lucene.index.RandomIndexWriter;
 import org.apache.lucene.index.Term;
 import org.apache.lucene.queries.function.valuesource.BytesRefFieldSource;
+import org.apache.lucene.queries.function.ContextMap;
 import org.apache.lucene.search.IndexSearcher;
 import org.apache.lucene.search.Sort;
 import org.apache.lucene.search.SortField;
@@ -356,7 +357,7 @@ public class DistinctValuesCollectorTest extends AbstractGroupingTestCase {
     Random random = random();
     Collection<SearchGroup<T>> searchGroups = firstPassGroupingCollector.getTopGroups(0, false);
     if (FunctionFirstPassGroupingCollector.class.isAssignableFrom(firstPassGroupingCollector.getClass())) {
-      return (AbstractDistinctValuesCollector) new FunctionDistinctValuesCollector(new HashMap<>(), new BytesRefFieldSource(groupField), new BytesRefFieldSource(countField), (Collection) searchGroups);
+      return (AbstractDistinctValuesCollector) new FunctionDistinctValuesCollector(new ContextMap(), new BytesRefFieldSource(groupField), new BytesRefFieldSource(countField), (Collection) searchGroups);
     } else {
       return (AbstractDistinctValuesCollector) new TermDistinctValuesCollector(groupField, countField, (Collection) searchGroups);
     }
@@ -366,7 +367,7 @@ public class DistinctValuesCollectorTest extends AbstractGroupingTestCase {
   private <T> AbstractFirstPassGroupingCollector<T> createRandomFirstPassCollector(Sort groupSort, String groupField, int topNGroups) throws IOException {
     Random random = random();
     if (random.nextBoolean()) {
-      return (AbstractFirstPassGroupingCollector<T>) new FunctionFirstPassGroupingCollector(new BytesRefFieldSource(groupField), new HashMap<>(), groupSort, topNGroups);
+      return (AbstractFirstPassGroupingCollector<T>) new FunctionFirstPassGroupingCollector(new BytesRefFieldSource(groupField), new ContextMap(), groupSort, topNGroups);
     } else {
       return (AbstractFirstPassGroupingCollector<T>) new TermFirstPassGroupingCollector(groupField, groupSort, topNGroups);
     }
diff --git a/lucene/grouping/src/test/org/apache/lucene/search/grouping/GroupingSearchTest.java b/lucene/grouping/src/test/org/apache/lucene/search/grouping/GroupingSearchTest.java
index d13bfd7..91d2bc5 100644
--- a/lucene/grouping/src/test/org/apache/lucene/search/grouping/GroupingSearchTest.java
+++ b/lucene/grouping/src/test/org/apache/lucene/search/grouping/GroupingSearchTest.java
@@ -25,6 +25,7 @@ import org.apache.lucene.document.StringField;
 import org.apache.lucene.document.TextField;
 import org.apache.lucene.index.RandomIndexWriter;
 import org.apache.lucene.index.Term;
+import org.apache.lucene.queries.function.ContextMap;
 import org.apache.lucene.queries.function.ValueSource;
 import org.apache.lucene.queries.function.valuesource.BytesRefFieldSource;
 import org.apache.lucene.search.IndexSearcher;
@@ -37,7 +38,6 @@ import org.apache.lucene.util.LuceneTestCase;
 import org.apache.lucene.util.mutable.MutableValueStr;
 
 import java.util.ArrayList;
-import java.util.HashMap;
 import java.util.List;
 
 public class GroupingSearchTest extends LuceneTestCase {
@@ -203,7 +203,7 @@ public class GroupingSearchTest extends LuceneTestCase {
     GroupingSearch groupingSearch;
     if (random().nextBoolean()) {
       ValueSource vs = new BytesRefFieldSource(groupField);
-      groupingSearch = new GroupingSearch(vs, new HashMap<>());
+      groupingSearch = new GroupingSearch(vs, new ContextMap());
     } else {
       groupingSearch = new GroupingSearch(groupField);
     }
diff --git a/lucene/grouping/src/test/org/apache/lucene/search/grouping/TestGrouping.java b/lucene/grouping/src/test/org/apache/lucene/search/grouping/TestGrouping.java
index 72c858f..bb641a2 100644
--- a/lucene/grouping/src/test/org/apache/lucene/search/grouping/TestGrouping.java
+++ b/lucene/grouping/src/test/org/apache/lucene/search/grouping/TestGrouping.java
@@ -45,6 +45,7 @@ import org.apache.lucene.index.NumericDocValues;
 import org.apache.lucene.index.RandomIndexWriter;
 import org.apache.lucene.index.ReaderUtil;
 import org.apache.lucene.index.Term;
+import org.apache.lucene.queries.function.ContextMap;
 import org.apache.lucene.queries.function.ValueSource;
 import org.apache.lucene.queries.function.valuesource.BytesRefFieldSource;
 import org.apache.lucene.search.CachingCollector;
@@ -199,7 +200,7 @@ public class TestGrouping extends LuceneTestCase {
     AbstractFirstPassGroupingCollector<?> selected;
     if (random().nextBoolean()) {
       ValueSource vs = new BytesRefFieldSource(groupField);
-      selected = new FunctionFirstPassGroupingCollector(vs, new HashMap<>(), groupSort, topDocs);
+      selected = new FunctionFirstPassGroupingCollector(vs, new ContextMap(), groupSort, topDocs);
     } else {
       selected = new TermFirstPassGroupingCollector(groupField, groupSort, topDocs);
     }
@@ -212,13 +213,13 @@ public class TestGrouping extends LuceneTestCase {
   private AbstractFirstPassGroupingCollector<?> createFirstPassCollector(String groupField, Sort groupSort, int topDocs, AbstractFirstPassGroupingCollector<?> firstPassGroupingCollector) throws IOException {
     if (TermFirstPassGroupingCollector.class.isAssignableFrom(firstPassGroupingCollector.getClass())) {
       ValueSource vs = new BytesRefFieldSource(groupField);
-      return new FunctionFirstPassGroupingCollector(vs, new HashMap<>(), groupSort, topDocs);
+      return new FunctionFirstPassGroupingCollector(vs, new ContextMap(), groupSort, topDocs);
     } else {
       return new TermFirstPassGroupingCollector(groupField, groupSort, topDocs);
     }
   }
 
-  @SuppressWarnings({"unchecked","rawtypes"})
+  @SuppressWarnings({"rawtypes","unchecked"})
   private <T> AbstractSecondPassGroupingCollector<T> createSecondPassCollector(AbstractFirstPassGroupingCollector firstPassGroupingCollector,
                                                                         String groupField,
                                                                         Sort groupSort,
@@ -235,12 +236,11 @@ public class TestGrouping extends LuceneTestCase {
     } else {
       ValueSource vs = new BytesRefFieldSource(groupField);
       Collection<SearchGroup<MutableValue>> searchGroups = firstPassGroupingCollector.getTopGroups(groupOffset, fillSortFields);
-      return (AbstractSecondPassGroupingCollector) new FunctionSecondPassGroupingCollector(searchGroups, groupSort, sortWithinGroup, maxDocsPerGroup, getScores, getMaxScores, fillSortFields, vs, new HashMap());
+      return (AbstractSecondPassGroupingCollector) new FunctionSecondPassGroupingCollector(searchGroups, groupSort, sortWithinGroup, maxDocsPerGroup, getScores, getMaxScores, fillSortFields, vs, new ContextMap());
     }
   }
 
   // Basically converts searchGroups from MutableValue to BytesRef if grouping by ValueSource
-  @SuppressWarnings("unchecked")
   private AbstractSecondPassGroupingCollector<?> createSecondPassCollector(AbstractFirstPassGroupingCollector<?> firstPassGroupingCollector,
                                                                         String groupField,
                                                                         Collection<SearchGroup<BytesRef>> searchGroups,
@@ -268,7 +268,7 @@ public class TestGrouping extends LuceneTestCase {
         mvalSearchGroups.add(sg);
       }
 
-      return new FunctionSecondPassGroupingCollector(mvalSearchGroups, groupSort, sortWithinGroup, maxDocsPerGroup, getScores, getMaxScores, fillSortFields, vs, new HashMap<>());
+      return new FunctionSecondPassGroupingCollector(mvalSearchGroups, groupSort, sortWithinGroup, maxDocsPerGroup, getScores, getMaxScores, fillSortFields, vs, new ContextMap());
     }
   }
 
@@ -278,7 +278,7 @@ public class TestGrouping extends LuceneTestCase {
       return new TermAllGroupsCollector(groupField);
     } else {
       ValueSource vs = new BytesRefFieldSource(groupField);
-      return new FunctionAllGroupsCollector(vs, new HashMap<>());
+      return new FunctionAllGroupsCollector(vs, new ContextMap());
     }
   }
 
diff --git a/lucene/highlighter/src/test/org/apache/lucene/search/uhighlight/TestUnifiedHighlighterMTQ.java b/lucene/highlighter/src/test/org/apache/lucene/search/uhighlight/TestUnifiedHighlighterMTQ.java
index 10f36a7..d4dcc4d 100644
--- a/lucene/highlighter/src/test/org/apache/lucene/search/uhighlight/TestUnifiedHighlighterMTQ.java
+++ b/lucene/highlighter/src/test/org/apache/lucene/search/uhighlight/TestUnifiedHighlighterMTQ.java
@@ -993,7 +993,7 @@ public class TestUnifiedHighlighterMTQ extends LuceneTestCase {
     int docId = searcher.search(new TermQuery(new Term("id", "id")), 1).scoreDocs[0].doc;
 
     WildcardQuery wildcardQuery = new WildcardQuery(new Term("body", "foxtr*"));
-    SpanMultiTermQueryWrapper wildcardQueryWrapper = new SpanMultiTermQueryWrapper<>(wildcardQuery);
+    SpanMultiTermQueryWrapper<?> wildcardQueryWrapper = new SpanMultiTermQueryWrapper<>(wildcardQuery);
 
     SpanQuery wrappedQuery = new MyWrapperSpanQuery(wildcardQueryWrapper);
 
diff --git a/lucene/queries/src/java/org/apache/lucene/queries/function/BoostedQuery.java b/lucene/queries/src/java/org/apache/lucene/queries/function/BoostedQuery.java
index c8b9423..eb30f70 100644
--- a/lucene/queries/src/java/org/apache/lucene/queries/function/BoostedQuery.java
+++ b/lucene/queries/src/java/org/apache/lucene/queries/function/BoostedQuery.java
@@ -19,7 +19,6 @@ package org.apache.lucene.queries.function;
 import java.io.IOException;
 import java.util.Collection;
 import java.util.Collections;
-import java.util.Map;
 import java.util.Set;
 
 import org.apache.lucene.index.IndexReader;
@@ -65,7 +64,7 @@ public final class BoostedQuery extends Query {
 
   private class BoostedWeight extends Weight {
     Weight qWeight;
-    Map fcontext;
+    ContextMap fcontext;
 
     public BoostedWeight(IndexSearcher searcher, boolean needsScores, float boost) throws IOException {
       super(BoostedQuery.this);
diff --git a/lucene/queries/src/java/org/apache/lucene/queries/function/ContextMap.java b/lucene/queries/src/java/org/apache/lucene/queries/function/ContextMap.java
new file mode 100644
index 0000000..caf677a
--- /dev/null
+++ b/lucene/queries/src/java/org/apache/lucene/queries/function/ContextMap.java
@@ -0,0 +1,33 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License.  You may obtain a copy of the License at
+ *
+ *     http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.apache.lucene.queries.function;
+
+import java.util.HashMap;
+import java.util.IdentityHashMap;
+
+public class ContextMap extends HashMap<Object,Object> {
+  public ContextMap() { // empty
+  }
+
+  public ContextMap(ContextMap source) { // new copy
+    super(source);
+  }
+
+  public ContextMap(IdentityHashMap<?,?> source) { // for solr
+    super(source);
+  }
+}
diff --git a/lucene/queries/src/java/org/apache/lucene/queries/function/FunctionQuery.java b/lucene/queries/src/java/org/apache/lucene/queries/function/FunctionQuery.java
index 4acb563..61d6610 100644
--- a/lucene/queries/src/java/org/apache/lucene/queries/function/FunctionQuery.java
+++ b/lucene/queries/src/java/org/apache/lucene/queries/function/FunctionQuery.java
@@ -17,7 +17,6 @@
 package org.apache.lucene.queries.function;
 
 import java.io.IOException;
-import java.util.Map;
 import java.util.Set;
 
 import org.apache.lucene.index.IndexReader;
@@ -56,7 +55,7 @@ public class FunctionQuery extends Query {
   protected class FunctionWeight extends Weight {
     protected final IndexSearcher searcher;
     protected final float boost;
-    protected final Map context;
+    protected final ContextMap context;
 
     public FunctionWeight(IndexSearcher searcher, float boost) throws IOException {
       super(FunctionQuery.this);
diff --git a/lucene/queries/src/java/org/apache/lucene/queries/function/FunctionRangeQuery.java b/lucene/queries/src/java/org/apache/lucene/queries/function/FunctionRangeQuery.java
index 41572a5..6dafb28 100644
--- a/lucene/queries/src/java/org/apache/lucene/queries/function/FunctionRangeQuery.java
+++ b/lucene/queries/src/java/org/apache/lucene/queries/function/FunctionRangeQuery.java
@@ -17,7 +17,6 @@
 package org.apache.lucene.queries.function;
 
 import java.io.IOException;
-import java.util.Map;
 import java.util.Objects;
 import java.util.Set;
 
@@ -119,8 +118,7 @@ public class FunctionRangeQuery extends Query {
   }
 
   private class FunctionRangeWeight extends Weight {
-    @SuppressWarnings("rawtypes")
-    private final Map vsContext;
+    private final ContextMap vsContext;
 
     public FunctionRangeWeight(IndexSearcher searcher) throws IOException {
       super(FunctionRangeQuery.this);
diff --git a/lucene/queries/src/java/org/apache/lucene/queries/function/ValueSource.java b/lucene/queries/src/java/org/apache/lucene/queries/function/ValueSource.java
index 4064fc9..d534947 100644
--- a/lucene/queries/src/java/org/apache/lucene/queries/function/ValueSource.java
+++ b/lucene/queries/src/java/org/apache/lucene/queries/function/ValueSource.java
@@ -17,8 +17,6 @@
 package org.apache.lucene.queries.function;
 
 import java.io.IOException;
-import java.util.IdentityHashMap;
-import java.util.Map;
 
 import org.apache.lucene.index.LeafReaderContext;
 import org.apache.lucene.search.FieldComparator;
@@ -42,7 +40,7 @@ public abstract class ValueSource {
    * docID manner, and you must call this method again to iterate through
    * the values again.
    */
-  public abstract FunctionValues getValues(Map context, LeafReaderContext readerContext) throws IOException;
+  public abstract FunctionValues getValues(ContextMap context, LeafReaderContext readerContext) throws IOException;
 
   @Override
   public abstract boolean equals(Object o);
@@ -66,14 +64,14 @@ public abstract class ValueSource {
    * weight info in the context. The context object will be passed to getValues()
    * where this info can be retrieved.
    */
-  public void createWeight(Map context, IndexSearcher searcher) throws IOException {
+  public void createWeight(ContextMap context, IndexSearcher searcher) throws IOException {
   }
 
   /**
    * Returns a new non-threadsafe context map.
    */
-  public static Map newContext(IndexSearcher searcher) {
-    Map context = new IdentityHashMap();
+  public static ContextMap newContext(IndexSearcher searcher) {
+    ContextMap context = new ContextMap();
     context.put("searcher", searcher);
     return context;
   }
@@ -85,8 +83,8 @@ public abstract class ValueSource {
 
   /**
    * EXPERIMENTAL: This method is subject to change.
-   * <p>
-   * Get the SortField for this ValueSource.  Uses the {@link #getValues(java.util.Map, org.apache.lucene.index.LeafReaderContext)}
+   * <p>   * Get the SortField for this ValueSource.  Uses the {@link #getValues(ContextMap, org.apache.lucene.index.LeafReaderContext)}
+
    * to populate the SortField.
    *
    * @param reverse true if this is a reverse sort.
@@ -103,16 +101,16 @@ public abstract class ValueSource {
 
     @Override
     public SortField rewrite(IndexSearcher searcher) throws IOException {
-      Map context = newContext(searcher);
+      ContextMap context = newContext(searcher);
       createWeight(context, searcher);
       return new SortField(getField(), new ValueSourceComparatorSource(context), getReverse());
     }
   }
 
   class ValueSourceComparatorSource extends FieldComparatorSource {
-    private final Map context;
+    private final ContextMap context;
 
-    public ValueSourceComparatorSource(Map context) {
+    public ValueSourceComparatorSource(ContextMap context) {
       this.context = context;
     }
 
@@ -132,10 +130,10 @@ public abstract class ValueSource {
     private final double[] values;
     private FunctionValues docVals;
     private double bottom;
-    private final Map fcontext;
+    private final ContextMap fcontext;
     private double topValue;
 
-    ValueSourceComparator(Map fcontext, int numHits) {
+    ValueSourceComparator(ContextMap fcontext, int numHits) {
       this.fcontext = fcontext;
       values = new double[numHits];
     }
diff --git a/lucene/queries/src/java/org/apache/lucene/queries/function/valuesource/BytesRefFieldSource.java b/lucene/queries/src/java/org/apache/lucene/queries/function/valuesource/BytesRefFieldSource.java
index bb33122..ad7e929 100644
--- a/lucene/queries/src/java/org/apache/lucene/queries/function/valuesource/BytesRefFieldSource.java
+++ b/lucene/queries/src/java/org/apache/lucene/queries/function/valuesource/BytesRefFieldSource.java
@@ -17,13 +17,13 @@
 package org.apache.lucene.queries.function.valuesource;
 
 import java.io.IOException;
-import java.util.Map;
 
 import org.apache.lucene.index.BinaryDocValues;
 import org.apache.lucene.index.DocValues;
 import org.apache.lucene.index.DocValuesType;
 import org.apache.lucene.index.FieldInfo;
 import org.apache.lucene.index.LeafReaderContext;
+import org.apache.lucene.queries.function.ContextMap;
 import org.apache.lucene.queries.function.FunctionValues;
 import org.apache.lucene.queries.function.docvalues.DocTermsIndexDocValues;
 import org.apache.lucene.util.BytesRef;
@@ -41,7 +41,7 @@ public class BytesRefFieldSource extends FieldCacheSource {
   }
 
   @Override
-  public FunctionValues getValues(Map context, LeafReaderContext readerContext) throws IOException {
+  public FunctionValues getValues(ContextMap context, LeafReaderContext readerContext) throws IOException {
     final FieldInfo fieldInfo = readerContext.reader().getFieldInfos().fieldInfo(field);
 
     // To be sorted or not to be sorted, that is the question
diff --git a/lucene/queries/src/java/org/apache/lucene/queries/function/valuesource/ComparisonBoolFunction.java b/lucene/queries/src/java/org/apache/lucene/queries/function/valuesource/ComparisonBoolFunction.java
index 1a936d9..0cf67c2 100644
--- a/lucene/queries/src/java/org/apache/lucene/queries/function/valuesource/ComparisonBoolFunction.java
+++ b/lucene/queries/src/java/org/apache/lucene/queries/function/valuesource/ComparisonBoolFunction.java
@@ -18,9 +18,9 @@
 package org.apache.lucene.queries.function.valuesource;
 
 import java.io.IOException;
-import java.util.Map;
 
 import org.apache.lucene.index.LeafReaderContext;
+import org.apache.lucene.queries.function.ContextMap;
 import org.apache.lucene.queries.function.FunctionValues;
 import org.apache.lucene.queries.function.ValueSource;
 import org.apache.lucene.queries.function.docvalues.BoolDocValues;
@@ -50,7 +50,7 @@ public abstract class ComparisonBoolFunction extends BoolFunction {
   }
 
   @Override
-  public FunctionValues getValues(Map context, LeafReaderContext readerContext) throws IOException {
+  public FunctionValues getValues(ContextMap context, LeafReaderContext readerContext) throws IOException {
     final FunctionValues lhsVal = this.lhs.getValues(context, readerContext);
     final FunctionValues rhsVal = this.rhs.getValues(context, readerContext);
     final String compLabel = this.name();
@@ -97,7 +97,7 @@ public abstract class ComparisonBoolFunction extends BoolFunction {
   }
 
   @Override
-  public void createWeight(Map context, IndexSearcher searcher) throws IOException {
+  public void createWeight(ContextMap context, IndexSearcher searcher) throws IOException {
     lhs.createWeight(context, searcher);
     rhs.createWeight(context, searcher);
   }
diff --git a/lucene/queries/src/java/org/apache/lucene/queries/function/valuesource/ConstDoubleDocValues.java b/lucene/queries/src/java/org/apache/lucene/queries/function/valuesource/ConstDoubleDocValues.java
new file mode 100644
index 0000000..c44db35
--- /dev/null
+++ b/lucene/queries/src/java/org/apache/lucene/queries/function/valuesource/ConstDoubleDocValues.java
@@ -0,0 +1,66 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License.  You may obtain a copy of the License at
+ *
+ *     http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.apache.lucene.queries.function.valuesource;
+
+import org.apache.lucene.queries.function.ValueSource;
+import org.apache.lucene.queries.function.docvalues.DoubleDocValues;
+
+
+class ConstDoubleDocValues extends DoubleDocValues {
+  final int ival;
+  final float fval;
+  final double dval;
+  final long lval;
+  final String sval;
+  final ValueSource parent;
+
+  ConstDoubleDocValues(double val, ValueSource parent) {
+    super(parent);
+    ival = (int)val;
+    fval = (float)val;
+    dval = val;
+    lval = (long)val;
+    sval = Double.toString(val);
+    this.parent = parent;
+  }
+
+  @Override
+  public float floatVal(int doc) {
+    return fval;
+  }
+  @Override
+  public int intVal(int doc) {
+    return ival;
+  }
+  @Override
+  public long longVal(int doc) {
+    return lval;
+  }
+  @Override
+  public double doubleVal(int doc) {
+    return dval;
+  }
+  @Override
+  public String strVal(int doc) {
+    return sval;
+  }
+  @Override
+  public String toString(int doc) {
+    return parent.description() + '=' + sval;
+  }
+}
+
diff --git a/lucene/queries/src/java/org/apache/lucene/queries/function/valuesource/ConstIntDocValues.java b/lucene/queries/src/java/org/apache/lucene/queries/function/valuesource/ConstIntDocValues.java
new file mode 100644
index 0000000..d2b6a7f
--- /dev/null
+++ b/lucene/queries/src/java/org/apache/lucene/queries/function/valuesource/ConstIntDocValues.java
@@ -0,0 +1,65 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License.  You may obtain a copy of the License at
+ *
+ *     http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.apache.lucene.queries.function.valuesource;
+
+import org.apache.lucene.queries.function.docvalues.IntDocValues;
+import org.apache.lucene.queries.function.ValueSource;
+
+class ConstIntDocValues extends IntDocValues {
+  final int ival;
+  final float fval;
+  final double dval;
+  final long lval;
+  final String sval;
+  final ValueSource parent;
+
+  ConstIntDocValues(int val, ValueSource parent) {
+    super(parent);
+    ival = val;
+    fval = val;
+    dval = val;
+    lval = val;
+    sval = Integer.toString(val);
+    this.parent = parent;
+  }
+
+  @Override
+  public float floatVal(int doc) {
+    return fval;
+  }
+  @Override
+  public int intVal(int doc) {
+    return ival;
+  }
+  @Override
+  public long longVal(int doc) {
+    return lval;
+  }
+  @Override
+  public double doubleVal(int doc) {
+    return dval;
+  }
+  @Override
+  public String strVal(int doc) {
+    return sval;
+  }
+  @Override
+  public String toString(int doc) {
+    return parent.description() + '=' + sval;
+  }
+}
+
diff --git a/lucene/queries/src/java/org/apache/lucene/queries/function/valuesource/ConstValueSource.java b/lucene/queries/src/java/org/apache/lucene/queries/function/valuesource/ConstValueSource.java
index 125422f..4d1a0b1 100644
--- a/lucene/queries/src/java/org/apache/lucene/queries/function/valuesource/ConstValueSource.java
+++ b/lucene/queries/src/java/org/apache/lucene/queries/function/valuesource/ConstValueSource.java
@@ -18,10 +18,10 @@ package org.apache.lucene.queries.function.valuesource;
 
 import org.apache.lucene.index.LeafReaderContext;
 import org.apache.lucene.queries.function.FunctionValues;
+import org.apache.lucene.queries.function.ContextMap;
 import org.apache.lucene.queries.function.docvalues.FloatDocValues;
 
 import java.io.IOException;
-import java.util.Map;
 
 /**
  * <code>ConstValueSource</code> returns a constant for all documents
@@ -41,7 +41,7 @@ public class ConstValueSource extends ConstNumberSource {
   }
 
   @Override
-  public FunctionValues getValues(Map context, LeafReaderContext readerContext) throws IOException {
+  public FunctionValues getValues(ContextMap context, LeafReaderContext readerContext) throws IOException {
     return new FloatDocValues(this) {
       @Override
       public float floatVal(int doc) {
diff --git a/lucene/queries/src/java/org/apache/lucene/queries/function/valuesource/DefFunction.java b/lucene/queries/src/java/org/apache/lucene/queries/function/valuesource/DefFunction.java
index f3fd004..c3a712b 100644
--- a/lucene/queries/src/java/org/apache/lucene/queries/function/valuesource/DefFunction.java
+++ b/lucene/queries/src/java/org/apache/lucene/queries/function/valuesource/DefFunction.java
@@ -17,12 +17,12 @@
 package org.apache.lucene.queries.function.valuesource;
 import org.apache.lucene.index.LeafReaderContext;
 import org.apache.lucene.queries.function.FunctionValues;
+import org.apache.lucene.queries.function.ContextMap;
 import org.apache.lucene.queries.function.ValueSource;
 import org.apache.lucene.util.BytesRefBuilder;
 
 import java.io.IOException;
 import java.util.List;
-import java.util.Map;
 
 /**
  * {@link ValueSource} implementation which only returns the values from the provided
@@ -42,7 +42,7 @@ public class DefFunction extends MultiFunction {
 
 
   @Override
-  public FunctionValues getValues(Map fcontext, LeafReaderContext readerContext) throws IOException {
+  public FunctionValues getValues(ContextMap fcontext, LeafReaderContext readerContext) throws IOException {
 
 
     return new Values(valsArr(sources, fcontext, readerContext)) {
diff --git a/lucene/queries/src/java/org/apache/lucene/queries/function/valuesource/DocFreqValueSource.java b/lucene/queries/src/java/org/apache/lucene/queries/function/valuesource/DocFreqValueSource.java
index e03e316..b9c3abc 100644
--- a/lucene/queries/src/java/org/apache/lucene/queries/function/valuesource/DocFreqValueSource.java
+++ b/lucene/queries/src/java/org/apache/lucene/queries/function/valuesource/DocFreqValueSource.java
@@ -16,106 +16,16 @@
  */
 package org.apache.lucene.queries.function.valuesource;
 
+import org.apache.lucene.queries.function.ContextMap;
+
 import org.apache.lucene.index.LeafReaderContext;
 import org.apache.lucene.index.Term;
 import org.apache.lucene.queries.function.FunctionValues;
 import org.apache.lucene.queries.function.ValueSource;
-import org.apache.lucene.queries.function.docvalues.DoubleDocValues;
-import org.apache.lucene.queries.function.docvalues.IntDocValues;
 import org.apache.lucene.search.IndexSearcher;
 import org.apache.lucene.util.BytesRef;
 
 import java.io.IOException;
-import java.util.Map;
-
-
-class ConstIntDocValues extends IntDocValues {
-  final int ival;
-  final float fval;
-  final double dval;
-  final long lval;
-  final String sval;
-  final ValueSource parent;
-
-  ConstIntDocValues(int val, ValueSource parent) {
-    super(parent);
-    ival = val;
-    fval = val;
-    dval = val;
-    lval = val;
-    sval = Integer.toString(val);
-    this.parent = parent;
-  }
-
-  @Override
-  public float floatVal(int doc) {
-    return fval;
-  }
-  @Override
-  public int intVal(int doc) {
-    return ival;
-  }
-  @Override
-  public long longVal(int doc) {
-    return lval;
-  }
-  @Override
-  public double doubleVal(int doc) {
-    return dval;
-  }
-  @Override
-  public String strVal(int doc) {
-    return sval;
-  }
-  @Override
-  public String toString(int doc) {
-    return parent.description() + '=' + sval;
-  }
-}
-
-class ConstDoubleDocValues extends DoubleDocValues {
-  final int ival;
-  final float fval;
-  final double dval;
-  final long lval;
-  final String sval;
-  final ValueSource parent;
-
-  ConstDoubleDocValues(double val, ValueSource parent) {
-    super(parent);
-    ival = (int)val;
-    fval = (float)val;
-    dval = val;
-    lval = (long)val;
-    sval = Double.toString(val);
-    this.parent = parent;
-  }
-
-  @Override
-  public float floatVal(int doc) {
-    return fval;
-  }
-  @Override
-  public int intVal(int doc) {
-    return ival;
-  }
-  @Override
-  public long longVal(int doc) {
-    return lval;
-  }
-  @Override
-  public double doubleVal(int doc) {
-    return dval;
-  }
-  @Override
-  public String strVal(int doc) {
-    return sval;
-  }
-  @Override
-  public String toString(int doc) {
-    return parent.description() + '=' + sval;
-  }
-}
 
 
 /**
@@ -145,14 +55,14 @@ public class DocFreqValueSource extends ValueSource {
   }
 
   @Override
-  public FunctionValues getValues(Map context, LeafReaderContext readerContext) throws IOException {
+  public FunctionValues getValues(ContextMap context, LeafReaderContext readerContext) throws IOException {
     IndexSearcher searcher = (IndexSearcher)context.get("searcher");
     int docfreq = searcher.getIndexReader().docFreq(new Term(indexedField, indexedBytes));
     return new ConstIntDocValues(docfreq, this);
   }
 
   @Override
-  public void createWeight(Map context, IndexSearcher searcher) throws IOException {
+  public void createWeight(ContextMap context, IndexSearcher searcher) throws IOException {
     context.put("searcher",searcher);
   }
 
@@ -168,4 +78,3 @@ public class DocFreqValueSource extends ValueSource {
     return this.indexedField.equals(other.indexedField) && this.indexedBytes.equals(other.indexedBytes);
   }
 }
-
diff --git a/lucene/queries/src/java/org/apache/lucene/queries/function/valuesource/DoubleConstValueSource.java b/lucene/queries/src/java/org/apache/lucene/queries/function/valuesource/DoubleConstValueSource.java
index 74a4774..002d017 100644
--- a/lucene/queries/src/java/org/apache/lucene/queries/function/valuesource/DoubleConstValueSource.java
+++ b/lucene/queries/src/java/org/apache/lucene/queries/function/valuesource/DoubleConstValueSource.java
@@ -18,10 +18,10 @@ package org.apache.lucene.queries.function.valuesource;
 
 import org.apache.lucene.index.LeafReaderContext;
 import org.apache.lucene.queries.function.FunctionValues;
+import org.apache.lucene.queries.function.ContextMap;
 import org.apache.lucene.queries.function.docvalues.DoubleDocValues;
 
 import java.io.IOException;
-import java.util.Map;
 
 /**
  * Function that returns a constant double value for every document.
@@ -43,7 +43,7 @@ public class DoubleConstValueSource extends ConstNumberSource {
   }
 
   @Override
-  public FunctionValues getValues(Map context, LeafReaderContext readerContext) throws IOException {
+  public FunctionValues getValues(ContextMap context, LeafReaderContext readerContext) throws IOException {
     return new DoubleDocValues(this) {
       @Override
       public float floatVal(int doc) {
diff --git a/lucene/queries/src/java/org/apache/lucene/queries/function/valuesource/DoubleFieldSource.java b/lucene/queries/src/java/org/apache/lucene/queries/function/valuesource/DoubleFieldSource.java
index d525dab..4341fe5 100644
--- a/lucene/queries/src/java/org/apache/lucene/queries/function/valuesource/DoubleFieldSource.java
+++ b/lucene/queries/src/java/org/apache/lucene/queries/function/valuesource/DoubleFieldSource.java
@@ -17,12 +17,12 @@
 package org.apache.lucene.queries.function.valuesource;
 
 import java.io.IOException;
-import java.util.Map;
 
 import org.apache.lucene.index.DocValues;
 import org.apache.lucene.index.LeafReaderContext;
 import org.apache.lucene.index.NumericDocValues;
 import org.apache.lucene.queries.function.FunctionValues;
+import org.apache.lucene.queries.function.ContextMap;
 import org.apache.lucene.queries.function.docvalues.DoubleDocValues;
 import org.apache.lucene.search.SortField.Type;
 import org.apache.lucene.search.SortField;
@@ -50,7 +50,7 @@ public class DoubleFieldSource extends FieldCacheSource {
   }
   
   @Override
-  public FunctionValues getValues(Map context, LeafReaderContext readerContext) throws IOException {
+  public FunctionValues getValues(ContextMap context, LeafReaderContext readerContext) throws IOException {
 
     final NumericDocValues values = DocValues.getNumeric(readerContext.reader(), field);
 
diff --git a/lucene/queries/src/java/org/apache/lucene/queries/function/valuesource/DualFloatFunction.java b/lucene/queries/src/java/org/apache/lucene/queries/function/valuesource/DualFloatFunction.java
index e42ba65..a336b71 100644
--- a/lucene/queries/src/java/org/apache/lucene/queries/function/valuesource/DualFloatFunction.java
+++ b/lucene/queries/src/java/org/apache/lucene/queries/function/valuesource/DualFloatFunction.java
@@ -19,11 +19,11 @@ package org.apache.lucene.queries.function.valuesource;
 import org.apache.lucene.index.LeafReaderContext;
 import org.apache.lucene.queries.function.FunctionValues;
 import org.apache.lucene.queries.function.ValueSource;
+import org.apache.lucene.queries.function.ContextMap;
 import org.apache.lucene.queries.function.docvalues.FloatDocValues;
 import org.apache.lucene.search.IndexSearcher;
 
 import java.io.IOException;
-import java.util.Map;
 
 /**
  * Abstract {@link ValueSource} implementation which wraps two ValueSources
@@ -51,7 +51,7 @@ public abstract class DualFloatFunction extends ValueSource {
   }
 
   @Override
-  public FunctionValues getValues(Map context, LeafReaderContext readerContext) throws IOException {
+  public FunctionValues getValues(ContextMap context, LeafReaderContext readerContext) throws IOException {
     final FunctionValues aVals =  a.getValues(context, readerContext);
     final FunctionValues bVals =  b.getValues(context, readerContext);
     return new FloatDocValues(this) {
@@ -75,7 +75,7 @@ public abstract class DualFloatFunction extends ValueSource {
   }
 
   @Override
-  public void createWeight(Map context, IndexSearcher searcher) throws IOException {
+  public void createWeight(ContextMap context, IndexSearcher searcher) throws IOException {
     a.createWeight(context,searcher);
     b.createWeight(context,searcher);
   }
diff --git a/lucene/queries/src/java/org/apache/lucene/queries/function/valuesource/EnumFieldSource.java b/lucene/queries/src/java/org/apache/lucene/queries/function/valuesource/EnumFieldSource.java
index 2667660..a137658 100644
--- a/lucene/queries/src/java/org/apache/lucene/queries/function/valuesource/EnumFieldSource.java
+++ b/lucene/queries/src/java/org/apache/lucene/queries/function/valuesource/EnumFieldSource.java
@@ -23,6 +23,7 @@ import org.apache.lucene.index.DocValues;
 import org.apache.lucene.index.LeafReaderContext;
 import org.apache.lucene.index.NumericDocValues;
 import org.apache.lucene.queries.function.FunctionValues;
+import org.apache.lucene.queries.function.ContextMap;
 import org.apache.lucene.queries.function.ValueSourceScorer;
 import org.apache.lucene.queries.function.docvalues.IntDocValues;
 import org.apache.lucene.util.mutable.MutableValue;
@@ -93,7 +94,7 @@ public class EnumFieldSource extends FieldCacheSource {
 
 
   @Override
-  public FunctionValues getValues(Map context, LeafReaderContext readerContext) throws IOException {
+  public FunctionValues getValues(ContextMap context, LeafReaderContext readerContext) throws IOException {
     final NumericDocValues arr = DocValues.getNumeric(readerContext.reader(), field);
 
     return new IntDocValues(this) {
diff --git a/lucene/queries/src/java/org/apache/lucene/queries/function/valuesource/FloatFieldSource.java b/lucene/queries/src/java/org/apache/lucene/queries/function/valuesource/FloatFieldSource.java
index c4ab4b9..3beca43 100644
--- a/lucene/queries/src/java/org/apache/lucene/queries/function/valuesource/FloatFieldSource.java
+++ b/lucene/queries/src/java/org/apache/lucene/queries/function/valuesource/FloatFieldSource.java
@@ -17,12 +17,12 @@
 package org.apache.lucene.queries.function.valuesource;
 
 import java.io.IOException;
-import java.util.Map;
 
 import org.apache.lucene.index.DocValues;
 import org.apache.lucene.index.LeafReaderContext;
 import org.apache.lucene.index.NumericDocValues;
 import org.apache.lucene.queries.function.FunctionValues;
+import org.apache.lucene.queries.function.ContextMap;
 import org.apache.lucene.queries.function.docvalues.FloatDocValues;
 import org.apache.lucene.search.SortField.Type;
 import org.apache.lucene.search.SortField;
@@ -50,7 +50,7 @@ public class FloatFieldSource extends FieldCacheSource {
   }
   
   @Override
-  public FunctionValues getValues(Map context, LeafReaderContext readerContext) throws IOException {
+  public FunctionValues getValues(ContextMap context, LeafReaderContext readerContext) throws IOException {
 
     final NumericDocValues arr = DocValues.getNumeric(readerContext.reader(), field);
     
diff --git a/lucene/queries/src/java/org/apache/lucene/queries/function/valuesource/IDFValueSource.java b/lucene/queries/src/java/org/apache/lucene/queries/function/valuesource/IDFValueSource.java
index 34e5697..d967c9c 100644
--- a/lucene/queries/src/java/org/apache/lucene/queries/function/valuesource/IDFValueSource.java
+++ b/lucene/queries/src/java/org/apache/lucene/queries/function/valuesource/IDFValueSource.java
@@ -18,6 +18,7 @@ package org.apache.lucene.queries.function.valuesource;
 
 import org.apache.lucene.index.*;
 import org.apache.lucene.queries.function.FunctionValues;
+import org.apache.lucene.queries.function.ContextMap;
 import org.apache.lucene.search.IndexSearcher;
 import org.apache.lucene.search.similarities.PerFieldSimilarityWrapper;
 import org.apache.lucene.search.similarities.Similarity;
@@ -25,7 +26,6 @@ import org.apache.lucene.search.similarities.TFIDFSimilarity;
 import org.apache.lucene.util.BytesRef;
 
 import java.io.IOException;
-import java.util.Map;
 
 /** 
  * Function that returns {@link TFIDFSimilarity #idf(long, long)}
@@ -45,7 +45,7 @@ public class IDFValueSource extends DocFreqValueSource {
   }
 
   @Override
-  public FunctionValues getValues(Map context, LeafReaderContext readerContext) throws IOException {
+  public FunctionValues getValues(ContextMap context, LeafReaderContext readerContext) throws IOException {
     IndexSearcher searcher = (IndexSearcher)context.get("searcher");
     TFIDFSimilarity sim = asTFIDF(searcher.getSimilarity(true), field);
     if (sim == null) {
diff --git a/lucene/queries/src/java/org/apache/lucene/queries/function/valuesource/IfFunction.java b/lucene/queries/src/java/org/apache/lucene/queries/function/valuesource/IfFunction.java
index 45d18db..f8c7db4 100644
--- a/lucene/queries/src/java/org/apache/lucene/queries/function/valuesource/IfFunction.java
+++ b/lucene/queries/src/java/org/apache/lucene/queries/function/valuesource/IfFunction.java
@@ -18,12 +18,12 @@ package org.apache.lucene.queries.function.valuesource;
 
 import org.apache.lucene.index.LeafReaderContext;
 import org.apache.lucene.queries.function.FunctionValues;
+import org.apache.lucene.queries.function.ContextMap;
 import org.apache.lucene.queries.function.ValueSource;
 import org.apache.lucene.search.IndexSearcher;
 import org.apache.lucene.util.BytesRefBuilder;
 
 import java.io.IOException;
-import java.util.Map;
 
 
 /**
@@ -43,7 +43,7 @@ public class IfFunction extends BoolFunction {
   }
 
   @Override
-  public FunctionValues getValues(Map context, LeafReaderContext readerContext) throws IOException {
+  public FunctionValues getValues(ContextMap context, LeafReaderContext readerContext) throws IOException {
     final FunctionValues ifVals = ifSource.getValues(context, readerContext);
     final FunctionValues trueVals = trueSource.getValues(context, readerContext);
     final FunctionValues falseVals = falseSource.getValues(context, readerContext);
@@ -142,7 +142,7 @@ public class IfFunction extends BoolFunction {
   }
 
   @Override
-  public void createWeight(Map context, IndexSearcher searcher) throws IOException {
+  public void createWeight(ContextMap context, IndexSearcher searcher) throws IOException {
     ifSource.createWeight(context, searcher);
     trueSource.createWeight(context, searcher);
     falseSource.createWeight(context, searcher);
diff --git a/lucene/queries/src/java/org/apache/lucene/queries/function/valuesource/IntFieldSource.java b/lucene/queries/src/java/org/apache/lucene/queries/function/valuesource/IntFieldSource.java
index 2887e03..6f3f2bb 100644
--- a/lucene/queries/src/java/org/apache/lucene/queries/function/valuesource/IntFieldSource.java
+++ b/lucene/queries/src/java/org/apache/lucene/queries/function/valuesource/IntFieldSource.java
@@ -17,12 +17,12 @@
 package org.apache.lucene.queries.function.valuesource;
 
 import java.io.IOException;
-import java.util.Map;
 
 import org.apache.lucene.index.LeafReaderContext;
 import org.apache.lucene.index.DocValues;
 import org.apache.lucene.index.NumericDocValues;
 import org.apache.lucene.queries.function.FunctionValues;
+import org.apache.lucene.queries.function.ContextMap;
 import org.apache.lucene.queries.function.docvalues.IntDocValues;
 import org.apache.lucene.search.SortField;
 import org.apache.lucene.search.SortField.Type;
@@ -50,7 +50,7 @@ public class IntFieldSource extends FieldCacheSource {
   }
   
   @Override
-  public FunctionValues getValues(Map context, LeafReaderContext readerContext) throws IOException {
+  public FunctionValues getValues(ContextMap context, LeafReaderContext readerContext) throws IOException {
     
     final NumericDocValues arr = DocValues.getNumeric(readerContext.reader(), field);
 
diff --git a/lucene/queries/src/java/org/apache/lucene/queries/function/valuesource/JoinDocFreqValueSource.java b/lucene/queries/src/java/org/apache/lucene/queries/function/valuesource/JoinDocFreqValueSource.java
index db936ba..bcfaf2b 100644
--- a/lucene/queries/src/java/org/apache/lucene/queries/function/valuesource/JoinDocFreqValueSource.java
+++ b/lucene/queries/src/java/org/apache/lucene/queries/function/valuesource/JoinDocFreqValueSource.java
@@ -17,7 +17,6 @@
 package org.apache.lucene.queries.function.valuesource;
 
 import java.io.IOException;
-import java.util.Map;
 
 import org.apache.lucene.index.BinaryDocValues;
 import org.apache.lucene.index.DocValues;
@@ -28,6 +27,7 @@ import org.apache.lucene.index.ReaderUtil;
 import org.apache.lucene.index.Terms;
 import org.apache.lucene.index.TermsEnum;
 import org.apache.lucene.queries.function.FunctionValues;
+import org.apache.lucene.queries.function.ContextMap;
 import org.apache.lucene.queries.function.docvalues.IntDocValues;
 import org.apache.lucene.util.BytesRef;
 
@@ -53,7 +53,7 @@ public class JoinDocFreqValueSource extends FieldCacheSource {
   }
 
   @Override
-  public FunctionValues getValues(Map context, LeafReaderContext readerContext) throws IOException
+  public FunctionValues getValues(ContextMap context, LeafReaderContext readerContext) throws IOException
   {
     final BinaryDocValues terms = DocValues.getBinary(readerContext.reader(), field);
     final IndexReader top = ReaderUtil.getTopLevelContext(readerContext).reader();
diff --git a/lucene/queries/src/java/org/apache/lucene/queries/function/valuesource/LinearFloatFunction.java b/lucene/queries/src/java/org/apache/lucene/queries/function/valuesource/LinearFloatFunction.java
index bbc7419..734ca49 100644
--- a/lucene/queries/src/java/org/apache/lucene/queries/function/valuesource/LinearFloatFunction.java
+++ b/lucene/queries/src/java/org/apache/lucene/queries/function/valuesource/LinearFloatFunction.java
@@ -18,12 +18,12 @@ package org.apache.lucene.queries.function.valuesource;
 
 import org.apache.lucene.index.LeafReaderContext;
 import org.apache.lucene.queries.function.FunctionValues;
+import org.apache.lucene.queries.function.ContextMap;
 import org.apache.lucene.queries.function.ValueSource;
 import org.apache.lucene.queries.function.docvalues.FloatDocValues;
 import org.apache.lucene.search.IndexSearcher;
 
 import java.io.IOException;
-import java.util.Map;
 
 /**
  * <code>LinearFloatFunction</code> implements a linear function over
@@ -50,7 +50,7 @@ public class LinearFloatFunction extends ValueSource {
   }
 
   @Override
-  public FunctionValues getValues(Map context, LeafReaderContext readerContext) throws IOException {
+  public FunctionValues getValues(ContextMap context, LeafReaderContext readerContext) throws IOException {
     final FunctionValues vals =  source.getValues(context, readerContext);
     return new FloatDocValues(this) {
       @Override
@@ -69,7 +69,7 @@ public class LinearFloatFunction extends ValueSource {
   }
 
   @Override
-  public void createWeight(Map context, IndexSearcher searcher) throws IOException {
+  public void createWeight(ContextMap context, IndexSearcher searcher) throws IOException {
     source.createWeight(context, searcher);
   }
 
diff --git a/lucene/queries/src/java/org/apache/lucene/queries/function/valuesource/LiteralValueSource.java b/lucene/queries/src/java/org/apache/lucene/queries/function/valuesource/LiteralValueSource.java
index aeb3b49..ba5a8ce 100644
--- a/lucene/queries/src/java/org/apache/lucene/queries/function/valuesource/LiteralValueSource.java
+++ b/lucene/queries/src/java/org/apache/lucene/queries/function/valuesource/LiteralValueSource.java
@@ -17,12 +17,12 @@
 package org.apache.lucene.queries.function.valuesource;
 import org.apache.lucene.index.LeafReaderContext;
 import org.apache.lucene.queries.function.FunctionValues;
+import org.apache.lucene.queries.function.ContextMap;
 import org.apache.lucene.queries.function.ValueSource;
 import org.apache.lucene.queries.function.docvalues.StrDocValues;
 import org.apache.lucene.util.BytesRef;
 import org.apache.lucene.util.BytesRefBuilder;
 
-import java.util.Map;
 import java.io.IOException;
 
 
@@ -45,7 +45,7 @@ public class LiteralValueSource extends ValueSource {
   }
 
   @Override
-  public FunctionValues getValues(Map context, LeafReaderContext readerContext) throws IOException {
+  public FunctionValues getValues(ContextMap context, LeafReaderContext readerContext) throws IOException {
 
     return new StrDocValues(this) {
       @Override
diff --git a/lucene/queries/src/java/org/apache/lucene/queries/function/valuesource/LongFieldSource.java b/lucene/queries/src/java/org/apache/lucene/queries/function/valuesource/LongFieldSource.java
index 2a43f60..4f330e3 100644
--- a/lucene/queries/src/java/org/apache/lucene/queries/function/valuesource/LongFieldSource.java
+++ b/lucene/queries/src/java/org/apache/lucene/queries/function/valuesource/LongFieldSource.java
@@ -17,12 +17,12 @@
 package org.apache.lucene.queries.function.valuesource;
 
 import java.io.IOException;
-import java.util.Map;
 
 import org.apache.lucene.index.LeafReaderContext;
 import org.apache.lucene.index.DocValues;
 import org.apache.lucene.index.NumericDocValues;
 import org.apache.lucene.queries.function.FunctionValues;
+import org.apache.lucene.queries.function.ContextMap;
 import org.apache.lucene.queries.function.docvalues.LongDocValues;
 import org.apache.lucene.search.SortField;
 import org.apache.lucene.search.SortField.Type;
@@ -62,7 +62,7 @@ public class LongFieldSource extends FieldCacheSource {
   }
   
   @Override
-  public FunctionValues getValues(Map context, LeafReaderContext readerContext) throws IOException {
+  public FunctionValues getValues(ContextMap context, LeafReaderContext readerContext) throws IOException {
     
     final NumericDocValues arr = DocValues.getNumeric(readerContext.reader(), field);
 
diff --git a/lucene/queries/src/java/org/apache/lucene/queries/function/valuesource/MaxDocValueSource.java b/lucene/queries/src/java/org/apache/lucene/queries/function/valuesource/MaxDocValueSource.java
index ccd7326..024f029 100644
--- a/lucene/queries/src/java/org/apache/lucene/queries/function/valuesource/MaxDocValueSource.java
+++ b/lucene/queries/src/java/org/apache/lucene/queries/function/valuesource/MaxDocValueSource.java
@@ -19,11 +19,11 @@ package org.apache.lucene.queries.function.valuesource;
 import org.apache.lucene.index.LeafReaderContext;
 import org.apache.lucene.index.IndexReader; // javadocs
 import org.apache.lucene.queries.function.FunctionValues;
+import org.apache.lucene.queries.function.ContextMap;
 import org.apache.lucene.queries.function.ValueSource;
 import org.apache.lucene.search.IndexSearcher;
 
 import java.io.IOException;
-import java.util.Map;
 
 /**
  * Returns the value of {@link IndexReader#maxDoc()}
@@ -41,12 +41,12 @@ public class MaxDocValueSource extends ValueSource {
   }
 
   @Override
-  public void createWeight(Map context, IndexSearcher searcher) throws IOException {
+  public void createWeight(ContextMap context, IndexSearcher searcher) throws IOException {
     context.put("searcher",searcher);
   }
 
   @Override
-  public FunctionValues getValues(Map context, LeafReaderContext readerContext) throws IOException {
+  public FunctionValues getValues(ContextMap context, LeafReaderContext readerContext) throws IOException {
     IndexSearcher searcher = (IndexSearcher)context.get("searcher");
     return new ConstIntDocValues(searcher.getIndexReader().maxDoc(), this);
   }
diff --git a/lucene/queries/src/java/org/apache/lucene/queries/function/valuesource/MultiBoolFunction.java b/lucene/queries/src/java/org/apache/lucene/queries/function/valuesource/MultiBoolFunction.java
index f368b4a..817a49d 100644
--- a/lucene/queries/src/java/org/apache/lucene/queries/function/valuesource/MultiBoolFunction.java
+++ b/lucene/queries/src/java/org/apache/lucene/queries/function/valuesource/MultiBoolFunction.java
@@ -18,13 +18,13 @@ package org.apache.lucene.queries.function.valuesource;
 
 import org.apache.lucene.index.LeafReaderContext;
 import org.apache.lucene.queries.function.FunctionValues;
+import org.apache.lucene.queries.function.ContextMap;
 import org.apache.lucene.queries.function.ValueSource;
 import org.apache.lucene.queries.function.docvalues.BoolDocValues;
 import org.apache.lucene.search.IndexSearcher;
 
 import java.io.IOException;
 import java.util.List;
-import java.util.Map;
 
 /**
  * Abstract {@link ValueSource} implementation which wraps multiple ValueSources
@@ -42,7 +42,7 @@ public abstract class MultiBoolFunction extends BoolFunction {
   protected abstract boolean func(int doc, FunctionValues[] vals) throws IOException;
 
   @Override
-  public BoolDocValues getValues(Map context, LeafReaderContext readerContext) throws IOException {
+  public BoolDocValues getValues(ContextMap context, LeafReaderContext readerContext) throws IOException {
     final FunctionValues[] vals =  new FunctionValues[sources.size()];
     int i=0;
     for (ValueSource source : sources) {
@@ -102,7 +102,7 @@ public abstract class MultiBoolFunction extends BoolFunction {
   }
 
   @Override
-  public void createWeight(Map context, IndexSearcher searcher) throws IOException {
+  public void createWeight(ContextMap context, IndexSearcher searcher) throws IOException {
     for (ValueSource source : sources) {
       source.createWeight(context, searcher);
     }
diff --git a/lucene/queries/src/java/org/apache/lucene/queries/function/valuesource/MultiFloatFunction.java b/lucene/queries/src/java/org/apache/lucene/queries/function/valuesource/MultiFloatFunction.java
index f2deb21..0c72b85 100644
--- a/lucene/queries/src/java/org/apache/lucene/queries/function/valuesource/MultiFloatFunction.java
+++ b/lucene/queries/src/java/org/apache/lucene/queries/function/valuesource/MultiFloatFunction.java
@@ -17,11 +17,11 @@
 package org.apache.lucene.queries.function.valuesource;
 import org.apache.lucene.index.LeafReaderContext;
 import org.apache.lucene.queries.function.FunctionValues;
+import org.apache.lucene.queries.function.ContextMap;
 import org.apache.lucene.queries.function.ValueSource;
 import org.apache.lucene.queries.function.docvalues.FloatDocValues;
 import org.apache.lucene.search.IndexSearcher;
 
-import java.util.Map;
 import java.util.Arrays;
 import java.io.IOException;
 
@@ -70,7 +70,7 @@ public abstract class MultiFloatFunction extends ValueSource {
   }
 
   @Override
-  public FunctionValues getValues(Map context, LeafReaderContext readerContext) throws IOException {
+  public FunctionValues getValues(ContextMap context, LeafReaderContext readerContext) throws IOException {
     final FunctionValues[] valsArr = new FunctionValues[sources.length];
     for (int i=0; i<sources.length; i++) {
       valsArr[i] = sources[i].getValues(context, readerContext);
@@ -92,7 +92,7 @@ public abstract class MultiFloatFunction extends ValueSource {
   }
 
   @Override
-  public void createWeight(Map context, IndexSearcher searcher) throws IOException {
+  public void createWeight(ContextMap context, IndexSearcher searcher) throws IOException {
     for (ValueSource source : sources)
       source.createWeight(context, searcher);
   }
diff --git a/lucene/queries/src/java/org/apache/lucene/queries/function/valuesource/MultiFunction.java b/lucene/queries/src/java/org/apache/lucene/queries/function/valuesource/MultiFunction.java
index d7db435..07e51dd 100644
--- a/lucene/queries/src/java/org/apache/lucene/queries/function/valuesource/MultiFunction.java
+++ b/lucene/queries/src/java/org/apache/lucene/queries/function/valuesource/MultiFunction.java
@@ -17,12 +17,12 @@
 package org.apache.lucene.queries.function.valuesource;
 import org.apache.lucene.index.LeafReaderContext;
 import org.apache.lucene.queries.function.FunctionValues;
+import org.apache.lucene.queries.function.ContextMap;
 import org.apache.lucene.queries.function.ValueSource;
 import org.apache.lucene.search.IndexSearcher;
 
 import java.io.IOException;
 import java.util.List;
-import java.util.Map;
 
 /**
  * Abstract parent class for {@link ValueSource} implementations that wrap multiple
@@ -112,7 +112,7 @@ public abstract class MultiFunction extends ValueSource {
     return sb.toString();
   }
 
-  public static FunctionValues[] valsArr(List<ValueSource> sources, Map fcontext, LeafReaderContext readerContext) throws IOException {
+  public static FunctionValues[] valsArr(List<ValueSource> sources, ContextMap fcontext, LeafReaderContext readerContext) throws IOException {
     final FunctionValues[] valsArr = new FunctionValues[sources.size()];
     int i=0;
     for (ValueSource source : sources) {
@@ -157,7 +157,7 @@ public abstract class MultiFunction extends ValueSource {
   }
 
   @Override
-  public void createWeight(Map context, IndexSearcher searcher) throws IOException {
+  public void createWeight(ContextMap context, IndexSearcher searcher) throws IOException {
     for (ValueSource source : sources)
       source.createWeight(context, searcher);
   }
diff --git a/lucene/queries/src/java/org/apache/lucene/queries/function/valuesource/NormValueSource.java b/lucene/queries/src/java/org/apache/lucene/queries/function/valuesource/NormValueSource.java
index d556454..7827ed4 100644
--- a/lucene/queries/src/java/org/apache/lucene/queries/function/valuesource/NormValueSource.java
+++ b/lucene/queries/src/java/org/apache/lucene/queries/function/valuesource/NormValueSource.java
@@ -17,11 +17,11 @@
 package org.apache.lucene.queries.function.valuesource;
 
 import java.io.IOException;
-import java.util.Map;
 
 import org.apache.lucene.index.LeafReaderContext;
 import org.apache.lucene.index.NumericDocValues;
 import org.apache.lucene.queries.function.FunctionValues;
+import org.apache.lucene.queries.function.ContextMap;
 import org.apache.lucene.queries.function.ValueSource;
 import org.apache.lucene.queries.function.docvalues.FloatDocValues;
 import org.apache.lucene.search.IndexSearcher;
@@ -50,12 +50,12 @@ public class NormValueSource extends ValueSource {
   }
 
   @Override
-  public void createWeight(Map context, IndexSearcher searcher) throws IOException {
+  public void createWeight(ContextMap context, IndexSearcher searcher) throws IOException {
     context.put("searcher",searcher);
   }
 
   @Override
-  public FunctionValues getValues(Map context, LeafReaderContext readerContext) throws IOException {
+  public FunctionValues getValues(ContextMap context, LeafReaderContext readerContext) throws IOException {
     IndexSearcher searcher = (IndexSearcher)context.get("searcher");
     final TFIDFSimilarity similarity = IDFValueSource.asTFIDF(searcher.getSimilarity(true), field);
     if (similarity == null) {
diff --git a/lucene/queries/src/java/org/apache/lucene/queries/function/valuesource/NumDocsValueSource.java b/lucene/queries/src/java/org/apache/lucene/queries/function/valuesource/NumDocsValueSource.java
index 6f92f1e..23d6b88 100644
--- a/lucene/queries/src/java/org/apache/lucene/queries/function/valuesource/NumDocsValueSource.java
+++ b/lucene/queries/src/java/org/apache/lucene/queries/function/valuesource/NumDocsValueSource.java
@@ -20,10 +20,10 @@ import org.apache.lucene.index.LeafReaderContext;
 import org.apache.lucene.index.IndexReader;
 import org.apache.lucene.index.ReaderUtil;
 import org.apache.lucene.queries.function.FunctionValues;
+import org.apache.lucene.queries.function.ContextMap;
 import org.apache.lucene.queries.function.ValueSource;
 
 import java.io.IOException;
-import java.util.Map;
 
 /**
  * Returns the value of {@link IndexReader#numDocs()}
@@ -41,7 +41,7 @@ public class NumDocsValueSource extends ValueSource {
   }
 
   @Override
-  public FunctionValues getValues(Map context, LeafReaderContext readerContext) throws IOException {
+  public FunctionValues getValues(ContextMap context, LeafReaderContext readerContext) throws IOException {
     // Searcher has no numdocs so we must use the reader instead
     return new ConstIntDocValues(ReaderUtil.getTopLevelContext(readerContext).reader().numDocs(), this);
   }
diff --git a/lucene/queries/src/java/org/apache/lucene/queries/function/valuesource/QueryValueSource.java b/lucene/queries/src/java/org/apache/lucene/queries/function/valuesource/QueryValueSource.java
index 21cb70a..1a1630a 100644
--- a/lucene/queries/src/java/org/apache/lucene/queries/function/valuesource/QueryValueSource.java
+++ b/lucene/queries/src/java/org/apache/lucene/queries/function/valuesource/QueryValueSource.java
@@ -17,11 +17,11 @@
 package org.apache.lucene.queries.function.valuesource;
 
 import java.io.IOException;
-import java.util.Map;
 
 import org.apache.lucene.index.LeafReaderContext;
 import org.apache.lucene.index.ReaderUtil;
 import org.apache.lucene.queries.function.FunctionValues;
+import org.apache.lucene.queries.function.ContextMap;
 import org.apache.lucene.queries.function.ValueSource;
 import org.apache.lucene.queries.function.docvalues.FloatDocValues;
 import org.apache.lucene.search.DocIdSetIterator;
@@ -53,7 +53,7 @@ public class QueryValueSource extends ValueSource {
   }
 
   @Override
-  public FunctionValues getValues(Map fcontext, LeafReaderContext readerContext) throws IOException {
+  public FunctionValues getValues(ContextMap fcontext, LeafReaderContext readerContext) throws IOException {
     return new QueryDocValues(this, readerContext, fcontext);
   }
 
@@ -70,7 +70,7 @@ public class QueryValueSource extends ValueSource {
   }
 
   @Override
-  public void createWeight(Map context, IndexSearcher searcher) throws IOException {
+  public void createWeight(ContextMap context, IndexSearcher searcher) throws IOException {
     Weight w = searcher.createNormalizedWeight(q, true);
     context.put(this, w);
   }
@@ -81,7 +81,7 @@ class QueryDocValues extends FloatDocValues {
   final LeafReaderContext readerContext;
   final Weight weight;
   final float defVal;
-  final Map fcontext;
+  final ContextMap fcontext;
   final Query q;
 
   Scorer scorer;
@@ -94,7 +94,7 @@ class QueryDocValues extends FloatDocValues {
   int lastDocRequested=Integer.MAX_VALUE;
   
 
-  public QueryDocValues(QueryValueSource vs, LeafReaderContext readerContext, Map fcontext) throws IOException {
+  public QueryDocValues(QueryValueSource vs, LeafReaderContext readerContext, ContextMap fcontext) throws IOException {
     super(vs);
 
     this.readerContext = readerContext;
diff --git a/lucene/queries/src/java/org/apache/lucene/queries/function/valuesource/RangeMapFloatFunction.java b/lucene/queries/src/java/org/apache/lucene/queries/function/valuesource/RangeMapFloatFunction.java
index 5492c7f..a89bb9e 100644
--- a/lucene/queries/src/java/org/apache/lucene/queries/function/valuesource/RangeMapFloatFunction.java
+++ b/lucene/queries/src/java/org/apache/lucene/queries/function/valuesource/RangeMapFloatFunction.java
@@ -18,12 +18,12 @@ package org.apache.lucene.queries.function.valuesource;
 
 import org.apache.lucene.index.LeafReaderContext;
 import org.apache.lucene.queries.function.FunctionValues;
+import org.apache.lucene.queries.function.ContextMap;
 import org.apache.lucene.queries.function.ValueSource;
 import org.apache.lucene.queries.function.docvalues.FloatDocValues;
 import org.apache.lucene.search.IndexSearcher;
 
 import java.io.IOException;
-import java.util.Map;
 
 /**
  * <code>RangeMapFloatFunction</code> implements a map function over
@@ -58,7 +58,7 @@ public class RangeMapFloatFunction extends ValueSource {
   }
 
   @Override
-  public FunctionValues getValues(Map context, LeafReaderContext readerContext) throws IOException {
+  public FunctionValues getValues(ContextMap context, LeafReaderContext readerContext) throws IOException {
     final FunctionValues vals =  source.getValues(context, readerContext);
     final FunctionValues targets = target.getValues(context, readerContext);
     final FunctionValues defaults = (this.defaultVal == null) ? null : defaultVal.getValues(context, readerContext);
@@ -76,7 +76,7 @@ public class RangeMapFloatFunction extends ValueSource {
   }
 
   @Override
-  public void createWeight(Map context, IndexSearcher searcher) throws IOException {
+  public void createWeight(ContextMap context, IndexSearcher searcher) throws IOException {
     source.createWeight(context, searcher);
   }
 
diff --git a/lucene/queries/src/java/org/apache/lucene/queries/function/valuesource/ReciprocalFloatFunction.java b/lucene/queries/src/java/org/apache/lucene/queries/function/valuesource/ReciprocalFloatFunction.java
index d6b050e..3f8f2cb 100644
--- a/lucene/queries/src/java/org/apache/lucene/queries/function/valuesource/ReciprocalFloatFunction.java
+++ b/lucene/queries/src/java/org/apache/lucene/queries/function/valuesource/ReciprocalFloatFunction.java
@@ -18,12 +18,12 @@ package org.apache.lucene.queries.function.valuesource;
 
 import org.apache.lucene.index.LeafReaderContext;
 import org.apache.lucene.queries.function.FunctionValues;
+import org.apache.lucene.queries.function.ContextMap;
 import org.apache.lucene.queries.function.ValueSource;
 import org.apache.lucene.queries.function.docvalues.FloatDocValues;
 import org.apache.lucene.search.IndexSearcher;
 
 import java.io.IOException;
-import java.util.Map;
 
 /**
  * <code>ReciprocalFloatFunction</code> implements a reciprocal function f(x) = a/(mx+b), based on
@@ -60,7 +60,7 @@ public class ReciprocalFloatFunction extends ValueSource {
   }
 
   @Override
-  public FunctionValues getValues(Map context, LeafReaderContext readerContext) throws IOException {
+  public FunctionValues getValues(ContextMap context, LeafReaderContext readerContext) throws IOException {
     final FunctionValues vals = source.getValues(context, readerContext);
     return new FloatDocValues(this) {
       @Override
@@ -81,7 +81,7 @@ public class ReciprocalFloatFunction extends ValueSource {
   }
 
   @Override
-  public void createWeight(Map context, IndexSearcher searcher) throws IOException {
+  public void createWeight(ContextMap context, IndexSearcher searcher) throws IOException {
     source.createWeight(context, searcher);
   }
 
diff --git a/lucene/queries/src/java/org/apache/lucene/queries/function/valuesource/ScaleFloatFunction.java b/lucene/queries/src/java/org/apache/lucene/queries/function/valuesource/ScaleFloatFunction.java
index 38bd86a..1b66f0f 100644
--- a/lucene/queries/src/java/org/apache/lucene/queries/function/valuesource/ScaleFloatFunction.java
+++ b/lucene/queries/src/java/org/apache/lucene/queries/function/valuesource/ScaleFloatFunction.java
@@ -19,6 +19,7 @@ package org.apache.lucene.queries.function.valuesource;
 import org.apache.lucene.index.LeafReaderContext;
 import org.apache.lucene.index.ReaderUtil;
 import org.apache.lucene.queries.function.FunctionValues;
+import org.apache.lucene.queries.function.ContextMap;
 import org.apache.lucene.queries.function.ValueSource;
 import org.apache.lucene.queries.function.docvalues.FloatDocValues;
 import org.apache.lucene.search.IndexSearcher;
@@ -59,7 +60,7 @@ public class ScaleFloatFunction extends ValueSource {
     float maxVal;
   }
 
-  private ScaleInfo createScaleInfo(Map context, LeafReaderContext readerContext) throws IOException {
+  private ScaleInfo createScaleInfo(ContextMap context, LeafReaderContext readerContext) throws IOException {
     final List<LeafReaderContext> leaves = ReaderUtil.getTopLevelContext(readerContext).leaves();
 
     float minVal = Float.POSITIVE_INFINITY;
@@ -95,12 +96,12 @@ public class ScaleFloatFunction extends ValueSource {
     ScaleInfo scaleInfo = new ScaleInfo();
     scaleInfo.minVal = minVal;
     scaleInfo.maxVal = maxVal;
-    context.put(ScaleFloatFunction.this, scaleInfo);
+    ((Map<Object,Object>)context).put(ScaleFloatFunction.this, scaleInfo);
     return scaleInfo;
   }
 
   @Override
-  public FunctionValues getValues(Map context, LeafReaderContext readerContext) throws IOException {
+  public FunctionValues getValues(ContextMap context, LeafReaderContext readerContext) throws IOException {
 
     ScaleInfo scaleInfo = (ScaleInfo)context.get(ScaleFloatFunction.this);
     if (scaleInfo == null) {
@@ -133,7 +134,7 @@ public class ScaleFloatFunction extends ValueSource {
   }
 
   @Override
-  public void createWeight(Map context, IndexSearcher searcher) throws IOException {
+  public void createWeight(ContextMap context, IndexSearcher searcher) throws IOException {
     source.createWeight(context, searcher);
   }
 
diff --git a/lucene/queries/src/java/org/apache/lucene/queries/function/valuesource/SimpleBoolFunction.java b/lucene/queries/src/java/org/apache/lucene/queries/function/valuesource/SimpleBoolFunction.java
index d9ad8c4..715dfc0 100644
--- a/lucene/queries/src/java/org/apache/lucene/queries/function/valuesource/SimpleBoolFunction.java
+++ b/lucene/queries/src/java/org/apache/lucene/queries/function/valuesource/SimpleBoolFunction.java
@@ -18,12 +18,12 @@ package org.apache.lucene.queries.function.valuesource;
 
 import org.apache.lucene.index.LeafReaderContext;
 import org.apache.lucene.queries.function.FunctionValues;
+import org.apache.lucene.queries.function.ContextMap;
 import org.apache.lucene.queries.function.ValueSource;
 import org.apache.lucene.queries.function.docvalues.BoolDocValues;
 import org.apache.lucene.search.IndexSearcher;
 
 import java.io.IOException;
-import java.util.Map;
 
 /**
  * {@link BoolFunction} implementation which applies an extendible boolean
@@ -44,7 +44,7 @@ public abstract class SimpleBoolFunction extends BoolFunction {
   protected abstract boolean func(int doc, FunctionValues vals) throws IOException;
 
   @Override
-  public BoolDocValues getValues(Map context, LeafReaderContext readerContext) throws IOException {
+  public BoolDocValues getValues(ContextMap context, LeafReaderContext readerContext) throws IOException {
     final FunctionValues vals =  source.getValues(context, readerContext);
     return new BoolDocValues(this) {
       @Override
@@ -76,7 +76,7 @@ public abstract class SimpleBoolFunction extends BoolFunction {
   }
 
   @Override
-  public void createWeight(Map context, IndexSearcher searcher) throws IOException {
+  public void createWeight(ContextMap context, IndexSearcher searcher) throws IOException {
     source.createWeight(context, searcher);
   }
 }
diff --git a/lucene/queries/src/java/org/apache/lucene/queries/function/valuesource/SimpleFloatFunction.java b/lucene/queries/src/java/org/apache/lucene/queries/function/valuesource/SimpleFloatFunction.java
index f74f8e4..a700bdd 100644
--- a/lucene/queries/src/java/org/apache/lucene/queries/function/valuesource/SimpleFloatFunction.java
+++ b/lucene/queries/src/java/org/apache/lucene/queries/function/valuesource/SimpleFloatFunction.java
@@ -18,11 +18,11 @@ package org.apache.lucene.queries.function.valuesource;
 
 import org.apache.lucene.index.LeafReaderContext;
 import org.apache.lucene.queries.function.FunctionValues;
+import org.apache.lucene.queries.function.ContextMap;
 import org.apache.lucene.queries.function.ValueSource;
 import org.apache.lucene.queries.function.docvalues.FloatDocValues;
 
 import java.io.IOException;
-import java.util.Map;
 
 /** A simple float function with a single argument
  */
@@ -34,7 +34,7 @@ import java.util.Map;
   protected abstract float func(int doc, FunctionValues vals) throws IOException;
 
   @Override
-  public FunctionValues getValues(Map context, LeafReaderContext readerContext) throws IOException {
+  public FunctionValues getValues(ContextMap context, LeafReaderContext readerContext) throws IOException {
     final FunctionValues vals =  source.getValues(context, readerContext);
     return new FloatDocValues(this) {
       @Override
diff --git a/lucene/queries/src/java/org/apache/lucene/queries/function/valuesource/SingleFunction.java b/lucene/queries/src/java/org/apache/lucene/queries/function/valuesource/SingleFunction.java
index f7eb699..d02d033 100644
--- a/lucene/queries/src/java/org/apache/lucene/queries/function/valuesource/SingleFunction.java
+++ b/lucene/queries/src/java/org/apache/lucene/queries/function/valuesource/SingleFunction.java
@@ -17,10 +17,10 @@
 package org.apache.lucene.queries.function.valuesource;
 
 import org.apache.lucene.queries.function.ValueSource;
+import org.apache.lucene.queries.function.ContextMap;
 import org.apache.lucene.search.IndexSearcher;
 
 import java.io.IOException;
-import java.util.Map;
 
 /** A function with a single argument
  */
@@ -52,7 +52,7 @@ import java.util.Map;
   }
 
   @Override
-  public void createWeight(Map context, IndexSearcher searcher) throws IOException {
+  public void createWeight(ContextMap context, IndexSearcher searcher) throws IOException {
     source.createWeight(context, searcher);
   }
 }
\ No newline at end of file
diff --git a/lucene/queries/src/java/org/apache/lucene/queries/function/valuesource/SortedSetFieldSource.java b/lucene/queries/src/java/org/apache/lucene/queries/function/valuesource/SortedSetFieldSource.java
index d32cc3b..ffa9e17 100644
--- a/lucene/queries/src/java/org/apache/lucene/queries/function/valuesource/SortedSetFieldSource.java
+++ b/lucene/queries/src/java/org/apache/lucene/queries/function/valuesource/SortedSetFieldSource.java
@@ -17,13 +17,13 @@
 package org.apache.lucene.queries.function.valuesource;
 
 import java.io.IOException;
-import java.util.Map;
 
 import org.apache.lucene.index.DocValues;
 import org.apache.lucene.index.LeafReaderContext;
 import org.apache.lucene.index.SortedDocValues;
 import org.apache.lucene.index.SortedSetDocValues;
 import org.apache.lucene.queries.function.FunctionValues;
+import org.apache.lucene.queries.function.ContextMap;
 import org.apache.lucene.queries.function.docvalues.DocTermsIndexDocValues;
 import org.apache.lucene.search.SortField;
 import org.apache.lucene.search.SortedSetSelector;
@@ -55,7 +55,7 @@ public class SortedSetFieldSource extends FieldCacheSource {
   }
 
   @Override
-  public FunctionValues getValues(Map context, LeafReaderContext readerContext) throws IOException {
+  public FunctionValues getValues(ContextMap context, LeafReaderContext readerContext) throws IOException {
     SortedSetDocValues sortedSet = DocValues.getSortedSet(readerContext.reader(), field);
     SortedDocValues view = SortedSetSelector.wrap(sortedSet, selector);
     return new DocTermsIndexDocValues(this.field, this, view) {
diff --git a/lucene/queries/src/java/org/apache/lucene/queries/function/valuesource/SumTotalTermFreqValueSource.java b/lucene/queries/src/java/org/apache/lucene/queries/function/valuesource/SumTotalTermFreqValueSource.java
index 746ad8e..ddb1dd3 100644
--- a/lucene/queries/src/java/org/apache/lucene/queries/function/valuesource/SumTotalTermFreqValueSource.java
+++ b/lucene/queries/src/java/org/apache/lucene/queries/function/valuesource/SumTotalTermFreqValueSource.java
@@ -19,12 +19,12 @@ package org.apache.lucene.queries.function.valuesource;
 import org.apache.lucene.index.LeafReaderContext;
 import org.apache.lucene.index.Terms;
 import org.apache.lucene.queries.function.FunctionValues;
+import org.apache.lucene.queries.function.ContextMap;
 import org.apache.lucene.queries.function.ValueSource;
 import org.apache.lucene.queries.function.docvalues.LongDocValues;
 import org.apache.lucene.search.IndexSearcher;
 
 import java.io.IOException;
-import java.util.Map;
 
 /**
  * <code>SumTotalTermFreqValueSource</code> returns the number of tokens.
@@ -50,12 +50,12 @@ public class SumTotalTermFreqValueSource extends ValueSource {
   }
 
   @Override
-  public FunctionValues getValues(Map context, LeafReaderContext readerContext) throws IOException {
+  public FunctionValues getValues(ContextMap context, LeafReaderContext readerContext) throws IOException {
     return (FunctionValues)context.get(this);
   }
 
   @Override
-  public void createWeight(Map context, IndexSearcher searcher) throws IOException {
+  public void createWeight(ContextMap context, IndexSearcher searcher) throws IOException {
     long sumTotalTermFreq = 0;
     for (LeafReaderContext readerContext : searcher.getTopReaderContext().leaves()) {
       Terms terms = readerContext.reader().terms(indexedField);
diff --git a/lucene/queries/src/java/org/apache/lucene/queries/function/valuesource/TFValueSource.java b/lucene/queries/src/java/org/apache/lucene/queries/function/valuesource/TFValueSource.java
index f0e252c..cb08dd9 100644
--- a/lucene/queries/src/java/org/apache/lucene/queries/function/valuesource/TFValueSource.java
+++ b/lucene/queries/src/java/org/apache/lucene/queries/function/valuesource/TFValueSource.java
@@ -17,7 +17,6 @@
 package org.apache.lucene.queries.function.valuesource;
 
 import java.io.IOException;
-import java.util.Map;
 
 import org.apache.lucene.index.PostingsEnum;
 import org.apache.lucene.index.Fields;
@@ -25,6 +24,7 @@ import org.apache.lucene.index.LeafReaderContext;
 import org.apache.lucene.index.Terms;
 import org.apache.lucene.index.TermsEnum;
 import org.apache.lucene.queries.function.FunctionValues;
+import org.apache.lucene.queries.function.ContextMap;
 import org.apache.lucene.queries.function.docvalues.FloatDocValues;
 import org.apache.lucene.search.DocIdSetIterator;
 import org.apache.lucene.search.IndexSearcher;
@@ -49,7 +49,7 @@ public class TFValueSource extends TermFreqValueSource {
   }
 
   @Override
-  public FunctionValues getValues(Map context, LeafReaderContext readerContext) throws IOException {
+  public FunctionValues getValues(ContextMap context, LeafReaderContext readerContext) throws IOException {
     Fields fields = readerContext.reader().fields();
     final Terms terms = fields.terms(indexedField);
     IndexSearcher searcher = (IndexSearcher)context.get("searcher");
diff --git a/lucene/queries/src/java/org/apache/lucene/queries/function/valuesource/TermFreqValueSource.java b/lucene/queries/src/java/org/apache/lucene/queries/function/valuesource/TermFreqValueSource.java
index 789e3e9..11bdc1c 100644
--- a/lucene/queries/src/java/org/apache/lucene/queries/function/valuesource/TermFreqValueSource.java
+++ b/lucene/queries/src/java/org/apache/lucene/queries/function/valuesource/TermFreqValueSource.java
@@ -17,7 +17,6 @@
 package org.apache.lucene.queries.function.valuesource;
 
 import java.io.IOException;
-import java.util.Map;
 
 import org.apache.lucene.index.PostingsEnum;
 import org.apache.lucene.index.Fields;
@@ -25,6 +24,7 @@ import org.apache.lucene.index.LeafReaderContext;
 import org.apache.lucene.index.Terms;
 import org.apache.lucene.index.TermsEnum;
 import org.apache.lucene.queries.function.FunctionValues;
+import org.apache.lucene.queries.function.ContextMap;
 import org.apache.lucene.queries.function.docvalues.IntDocValues;
 import org.apache.lucene.search.DocIdSetIterator;
 import org.apache.lucene.util.BytesRef;
@@ -47,7 +47,7 @@ public class TermFreqValueSource extends DocFreqValueSource {
   }
 
   @Override
-  public FunctionValues getValues(Map context, LeafReaderContext readerContext) throws IOException {
+  public FunctionValues getValues(ContextMap context, LeafReaderContext readerContext) throws IOException {
     Fields fields = readerContext.reader().fields();
     final Terms terms = fields.terms(indexedField);
 
diff --git a/lucene/queries/src/java/org/apache/lucene/queries/function/valuesource/TotalTermFreqValueSource.java b/lucene/queries/src/java/org/apache/lucene/queries/function/valuesource/TotalTermFreqValueSource.java
index aabe45f..08e8018 100644
--- a/lucene/queries/src/java/org/apache/lucene/queries/function/valuesource/TotalTermFreqValueSource.java
+++ b/lucene/queries/src/java/org/apache/lucene/queries/function/valuesource/TotalTermFreqValueSource.java
@@ -19,13 +19,13 @@ package org.apache.lucene.queries.function.valuesource;
 import org.apache.lucene.index.LeafReaderContext;
 import org.apache.lucene.index.Term;
 import org.apache.lucene.queries.function.FunctionValues;
+import org.apache.lucene.queries.function.ContextMap;
 import org.apache.lucene.queries.function.ValueSource;
 import org.apache.lucene.queries.function.docvalues.LongDocValues;
 import org.apache.lucene.search.IndexSearcher;
 import org.apache.lucene.util.BytesRef;
 
 import java.io.IOException;
-import java.util.Map;
 
 /**
  * <code>TotalTermFreqValueSource</code> returns the total term freq 
@@ -57,12 +57,12 @@ public class TotalTermFreqValueSource extends ValueSource {
   }
 
   @Override
-  public FunctionValues getValues(Map context, LeafReaderContext readerContext) throws IOException {
+  public FunctionValues getValues(ContextMap context, LeafReaderContext readerContext) throws IOException {
     return (FunctionValues)context.get(this);
   }
 
   @Override
-  public void createWeight(Map context, IndexSearcher searcher) throws IOException {
+  public void createWeight(ContextMap context, IndexSearcher searcher) throws IOException {
     long totalTermFreq = 0;
     for (LeafReaderContext readerContext : searcher.getTopReaderContext().leaves()) {
       long val = readerContext.reader().totalTermFreq(new Term(indexedField, indexedBytes));
diff --git a/lucene/queries/src/java/org/apache/lucene/queries/function/valuesource/VectorValueSource.java b/lucene/queries/src/java/org/apache/lucene/queries/function/valuesource/VectorValueSource.java
index 768243a..084c18c 100644
--- a/lucene/queries/src/java/org/apache/lucene/queries/function/valuesource/VectorValueSource.java
+++ b/lucene/queries/src/java/org/apache/lucene/queries/function/valuesource/VectorValueSource.java
@@ -17,12 +17,12 @@
 package org.apache.lucene.queries.function.valuesource;
 import org.apache.lucene.index.LeafReaderContext;
 import org.apache.lucene.queries.function.FunctionValues;
+import org.apache.lucene.queries.function.ContextMap;
 import org.apache.lucene.queries.function.ValueSource;
 import org.apache.lucene.search.IndexSearcher;
 
 import java.io.IOException;
 import java.util.List;
-import java.util.Map;
 
 
 /**
@@ -52,7 +52,7 @@ public class VectorValueSource extends MultiValueSource {
   }
 
   @Override
-  public FunctionValues getValues(Map context, LeafReaderContext readerContext) throws IOException {
+  public FunctionValues getValues(ContextMap context, LeafReaderContext readerContext) throws IOException {
     int size = sources.size();
 
     // special-case x,y and lat,lon since it's so common
@@ -178,7 +178,7 @@ public class VectorValueSource extends MultiValueSource {
   }
 
   @Override
-  public void createWeight(Map context, IndexSearcher searcher) throws IOException {
+  public void createWeight(ContextMap context, IndexSearcher searcher) throws IOException {
     for (ValueSource source : sources)
       source.createWeight(context, searcher);
   }
diff --git a/lucene/queries/src/test/org/apache/lucene/queries/function/TestSortedSetFieldSource.java b/lucene/queries/src/test/org/apache/lucene/queries/function/TestSortedSetFieldSource.java
index b72bfeb..c5289b0 100644
--- a/lucene/queries/src/test/org/apache/lucene/queries/function/TestSortedSetFieldSource.java
+++ b/lucene/queries/src/test/org/apache/lucene/queries/function/TestSortedSetFieldSource.java
@@ -16,14 +16,13 @@
  */
 package org.apache.lucene.queries.function;
 
-import java.util.Collections;
-
 import org.apache.lucene.document.Document;
 import org.apache.lucene.document.Field;
 import org.apache.lucene.document.SortedSetDocValuesField;
 import org.apache.lucene.index.LeafReader;
 import org.apache.lucene.index.DirectoryReader;
 import org.apache.lucene.index.IndexWriter;
+import org.apache.lucene.queries.function.ContextMap;
 import org.apache.lucene.queries.function.valuesource.SortedSetFieldSource;
 import org.apache.lucene.search.IndexSearcher;
 import org.apache.lucene.search.SortField;
@@ -53,7 +52,7 @@ public class TestSortedSetFieldSource extends LuceneTestCase {
     LeafReader ar = getOnlyLeafReader(ir);
     
     ValueSource vs = new SortedSetFieldSource("value");
-    FunctionValues values = vs.getValues(Collections.emptyMap(), ar.getContext());
+    FunctionValues values = vs.getValues(new ContextMap(), ar.getContext());
     assertEquals("baz", values.strVal(0));
     assertEquals("bar", values.strVal(1));
 
diff --git a/lucene/queries/src/test/org/apache/lucene/queries/function/TestValueSources.java b/lucene/queries/src/test/org/apache/lucene/queries/function/TestValueSources.java
index 57caac6..66ce02a 100644
--- a/lucene/queries/src/test/org/apache/lucene/queries/function/TestValueSources.java
+++ b/lucene/queries/src/test/org/apache/lucene/queries/function/TestValueSources.java
@@ -18,7 +18,6 @@ package org.apache.lucene.queries.function;
 
 import java.util.Arrays;
 import java.util.List;
-import java.util.Map;
 import java.io.IOException;
 
 import org.apache.lucene.analysis.Analyzer;
@@ -34,6 +33,7 @@ import org.apache.lucene.index.IndexReader;
 import org.apache.lucene.index.IndexWriterConfig;
 import org.apache.lucene.index.RandomIndexWriter;
 import org.apache.lucene.index.LeafReaderContext;
+import org.apache.lucene.queries.function.ContextMap;
 import org.apache.lucene.queries.function.docvalues.FloatDocValues;
 import org.apache.lucene.queries.function.valuesource.BytesRefFieldSource;
 import org.apache.lucene.queries.function.valuesource.ConstValueSource;
@@ -518,7 +518,7 @@ public class TestValueSources extends LuceneTestCase {
     
     // actual doc / index is not relevant for this test
     final LeafReaderContext leaf = searcher.getIndexReader().leaves().get(0);
-    final Map context = ValueSource.newContext(searcher);
+    final ContextMap context = ValueSource.newContext(searcher);
 
     ALL_EXIST_VS.createWeight(context, searcher);
     NONE_EXIST_VS.createWeight(context, searcher);
@@ -582,7 +582,7 @@ public class TestValueSources extends LuceneTestCase {
    * value from the <code>expected</code> {@link ValueSource}
    */
   void assertExists(ValueSource expected, ValueSource actual) {
-    Map context = ValueSource.newContext(searcher);
+    ContextMap context = ValueSource.newContext(searcher);
     try {
       expected.createWeight(context, searcher);
       actual.createWeight(context, searcher);
@@ -646,7 +646,7 @@ public class TestValueSources extends LuceneTestCase {
     }
     
     @Override
-    public FunctionValues getValues(Map context, LeafReaderContext readerContext) {
+    public FunctionValues getValues(ContextMap context, LeafReaderContext readerContext) {
       return new FloatDocValues(this) {
         @Override
         public float floatVal(int doc) {
diff --git a/lucene/spatial-extras/src/java/org/apache/lucene/spatial/bbox/BBoxSimilarityValueSource.java b/lucene/spatial-extras/src/java/org/apache/lucene/spatial/bbox/BBoxSimilarityValueSource.java
index b1424e0..8dbb2e7 100644
--- a/lucene/spatial-extras/src/java/org/apache/lucene/spatial/bbox/BBoxSimilarityValueSource.java
+++ b/lucene/spatial-extras/src/java/org/apache/lucene/spatial/bbox/BBoxSimilarityValueSource.java
@@ -17,11 +17,11 @@
 package org.apache.lucene.spatial.bbox;
 
 import java.io.IOException;
-import java.util.Map;
 import java.util.concurrent.atomic.AtomicReference;
 
 import org.apache.lucene.index.LeafReaderContext;
 import org.apache.lucene.queries.function.FunctionValues;
+import org.apache.lucene.queries.function.ContextMap;
 import org.apache.lucene.queries.function.ValueSource;
 import org.apache.lucene.queries.function.docvalues.DoubleDocValues;
 import org.apache.lucene.search.Explanation;
@@ -48,7 +48,7 @@ public abstract class BBoxSimilarityValueSource extends ValueSource {
   }
 
   @Override
-  public void createWeight(Map context, IndexSearcher searcher) throws IOException {
+  public void createWeight(ContextMap context, IndexSearcher searcher) throws IOException {
     bboxValueSource.createWeight(context, searcher);
   }
 
@@ -61,7 +61,7 @@ public abstract class BBoxSimilarityValueSource extends ValueSource {
   protected abstract String similarityDescription();
 
   @Override
-  public FunctionValues getValues(Map context, LeafReaderContext readerContext) throws IOException {
+  public FunctionValues getValues(ContextMap context, LeafReaderContext readerContext) throws IOException {
 
     final FunctionValues shapeValues = bboxValueSource.getValues(context, readerContext);
 
diff --git a/lucene/spatial-extras/src/java/org/apache/lucene/spatial/bbox/BBoxValueSource.java b/lucene/spatial-extras/src/java/org/apache/lucene/spatial/bbox/BBoxValueSource.java
index ef9f54e..5e49725 100644
--- a/lucene/spatial-extras/src/java/org/apache/lucene/spatial/bbox/BBoxValueSource.java
+++ b/lucene/spatial-extras/src/java/org/apache/lucene/spatial/bbox/BBoxValueSource.java
@@ -17,13 +17,13 @@
 package org.apache.lucene.spatial.bbox;
 
 import java.io.IOException;
-import java.util.Map;
 
 import org.apache.lucene.index.DocValues;
 import org.apache.lucene.index.LeafReader;
 import org.apache.lucene.index.LeafReaderContext;
 import org.apache.lucene.index.NumericDocValues;
 import org.apache.lucene.queries.function.FunctionValues;
+import org.apache.lucene.queries.function.ContextMap;
 import org.apache.lucene.queries.function.ValueSource;
 import org.apache.lucene.search.Explanation;
 import org.locationtech.spatial4j.shape.Rectangle;
@@ -48,7 +48,7 @@ class BBoxValueSource extends ValueSource {
   }
 
   @Override
-  public FunctionValues getValues(Map context, LeafReaderContext readerContext) throws IOException {
+  public FunctionValues getValues(ContextMap context, LeafReaderContext readerContext) throws IOException {
     LeafReader reader = readerContext.reader();
     final NumericDocValues minX = DocValues.getNumeric(reader, strategy.field_minX);
     final NumericDocValues minY = DocValues.getNumeric(reader, strategy.field_minY);
diff --git a/lucene/spatial-extras/src/java/org/apache/lucene/spatial/composite/CompositeVerifyQuery.java b/lucene/spatial-extras/src/java/org/apache/lucene/spatial/composite/CompositeVerifyQuery.java
index d556efa..e4b3a67 100644
--- a/lucene/spatial-extras/src/java/org/apache/lucene/spatial/composite/CompositeVerifyQuery.java
+++ b/lucene/spatial-extras/src/java/org/apache/lucene/spatial/composite/CompositeVerifyQuery.java
@@ -17,11 +17,11 @@
 package org.apache.lucene.spatial.composite;
 
 import java.io.IOException;
-import java.util.Map;
 
 import org.apache.lucene.index.IndexReader;
 import org.apache.lucene.index.LeafReaderContext;
 import org.apache.lucene.queries.function.FunctionValues;
+import org.apache.lucene.queries.function.ContextMap;
 import org.apache.lucene.queries.function.ValueSource;
 import org.apache.lucene.search.ConstantScoreScorer;
 import org.apache.lucene.search.ConstantScoreWeight;
@@ -84,7 +84,7 @@ public class CompositeVerifyQuery extends Query {
   @Override
   public Weight createWeight(IndexSearcher searcher, boolean needsScores, float boost) throws IOException {
     final Weight indexQueryWeight = indexQuery.createWeight(searcher, false, boost);//scores aren't unsupported
-    final Map valueSourceContext = ValueSource.newContext(searcher);
+    final ContextMap valueSourceContext = ValueSource.newContext(searcher);
 
     return new ConstantScoreWeight(this, boost) {
 
diff --git a/lucene/spatial-extras/src/java/org/apache/lucene/spatial/composite/IntersectsRPTVerifyQuery.java b/lucene/spatial-extras/src/java/org/apache/lucene/spatial/composite/IntersectsRPTVerifyQuery.java
index ce8c207..3b0c239 100644
--- a/lucene/spatial-extras/src/java/org/apache/lucene/spatial/composite/IntersectsRPTVerifyQuery.java
+++ b/lucene/spatial-extras/src/java/org/apache/lucene/spatial/composite/IntersectsRPTVerifyQuery.java
@@ -17,11 +17,11 @@
 package org.apache.lucene.spatial.composite;
 
 import java.io.IOException;
-import java.util.Map;
 
 import org.apache.lucene.index.LeafReaderContext;
 import org.apache.lucene.queries.function.FunctionValues;
 import org.apache.lucene.queries.function.ValueSource;
+import org.apache.lucene.queries.function.ContextMap;
 import org.apache.lucene.search.ConstantScoreScorer;
 import org.apache.lucene.search.ConstantScoreWeight;
 import org.apache.lucene.search.DocIdSet;
@@ -83,7 +83,7 @@ public class IntersectsRPTVerifyQuery extends Query {
 
   @Override
   public Weight createWeight(IndexSearcher searcher, boolean needsScores, float boost) throws IOException {
-    final Map valueSourceContext = ValueSource.newContext(searcher);
+    final ContextMap valueSourceContext = ValueSource.newContext(searcher);
 
     return new ConstantScoreWeight(this, boost) {
       @Override
diff --git a/lucene/spatial-extras/src/java/org/apache/lucene/spatial/serialized/SerializedDVStrategy.java b/lucene/spatial-extras/src/java/org/apache/lucene/spatial/serialized/SerializedDVStrategy.java
index 47ac90e..4734d9c 100644
--- a/lucene/spatial-extras/src/java/org/apache/lucene/spatial/serialized/SerializedDVStrategy.java
+++ b/lucene/spatial-extras/src/java/org/apache/lucene/spatial/serialized/SerializedDVStrategy.java
@@ -22,13 +22,13 @@ import java.io.DataInputStream;
 import java.io.DataOutputStream;
 import java.io.FilterOutputStream;
 import java.io.IOException;
-import java.util.Map;
 
 import org.apache.lucene.document.BinaryDocValuesField;
 import org.apache.lucene.document.Field;
 import org.apache.lucene.index.BinaryDocValues;
 import org.apache.lucene.index.LeafReaderContext;
 import org.apache.lucene.queries.function.FunctionValues;
+import org.apache.lucene.queries.function.ContextMap;
 import org.apache.lucene.queries.function.ValueSource;
 import org.apache.lucene.search.ConstantScoreScorer;
 import org.apache.lucene.search.ConstantScoreWeight;
@@ -195,7 +195,7 @@ public class SerializedDVStrategy extends SpatialStrategy {
     }
 
     @Override
-    public FunctionValues getValues(Map context, LeafReaderContext readerContext) throws IOException {
+    public FunctionValues getValues(ContextMap context, LeafReaderContext readerContext) throws IOException {
       final BinaryDocValues docValues = readerContext.reader().getBinaryDocValues(fieldName);
 
       return new FunctionValues() {
diff --git a/lucene/spatial-extras/src/java/org/apache/lucene/spatial/util/CachingDoubleValueSource.java b/lucene/spatial-extras/src/java/org/apache/lucene/spatial/util/CachingDoubleValueSource.java
index d43d4e8..14cbdf4 100644
--- a/lucene/spatial-extras/src/java/org/apache/lucene/spatial/util/CachingDoubleValueSource.java
+++ b/lucene/spatial-extras/src/java/org/apache/lucene/spatial/util/CachingDoubleValueSource.java
@@ -19,6 +19,7 @@ package org.apache.lucene.spatial.util;
 import org.apache.lucene.index.LeafReaderContext;
 import org.apache.lucene.queries.function.FunctionValues;
 import org.apache.lucene.queries.function.ValueSource;
+import org.apache.lucene.queries.function.ContextMap;
 
 import java.io.IOException;
 import java.util.HashMap;
@@ -46,7 +47,7 @@ public class CachingDoubleValueSource extends ValueSource {
   }
 
   @Override
-  public FunctionValues getValues(Map context, LeafReaderContext readerContext) throws IOException {
+  public FunctionValues getValues(ContextMap context, LeafReaderContext readerContext) throws IOException {
     final int base = readerContext.docBase;
     final FunctionValues vals = source.getValues(context,readerContext);
     return new FunctionValues() {
diff --git a/lucene/spatial-extras/src/java/org/apache/lucene/spatial/util/DistanceToShapeValueSource.java b/lucene/spatial-extras/src/java/org/apache/lucene/spatial/util/DistanceToShapeValueSource.java
index 6993adb..2111699 100644
--- a/lucene/spatial-extras/src/java/org/apache/lucene/spatial/util/DistanceToShapeValueSource.java
+++ b/lucene/spatial-extras/src/java/org/apache/lucene/spatial/util/DistanceToShapeValueSource.java
@@ -20,11 +20,11 @@ import java.io.IOException;
 import java.util.ArrayList;
 import java.util.Arrays;
 import java.util.List;
-import java.util.Map;
 
 import org.apache.lucene.index.LeafReaderContext;
 import org.apache.lucene.queries.function.FunctionValues;
 import org.apache.lucene.queries.function.ValueSource;
+import org.apache.lucene.queries.function.ContextMap;
 import org.apache.lucene.queries.function.docvalues.DoubleDocValues;
 import org.apache.lucene.search.Explanation;
 import org.apache.lucene.search.IndexSearcher;
@@ -66,12 +66,12 @@ public class DistanceToShapeValueSource extends ValueSource {
   }
 
   @Override
-  public void createWeight(Map context, IndexSearcher searcher) throws IOException {
+  public void createWeight(ContextMap context, IndexSearcher searcher) throws IOException {
     shapeValueSource.createWeight(context, searcher);
   }
 
   @Override
-  public FunctionValues getValues(Map context, LeafReaderContext readerContext) throws IOException {
+  public FunctionValues getValues(ContextMap context, LeafReaderContext readerContext) throws IOException {
     final FunctionValues shapeValues = shapeValueSource.getValues(context, readerContext);
 
     return new DoubleDocValues(this) {
diff --git a/lucene/spatial-extras/src/java/org/apache/lucene/spatial/util/ShapeAreaValueSource.java b/lucene/spatial-extras/src/java/org/apache/lucene/spatial/util/ShapeAreaValueSource.java
index 9c2c0e3..614eeb9 100644
--- a/lucene/spatial-extras/src/java/org/apache/lucene/spatial/util/ShapeAreaValueSource.java
+++ b/lucene/spatial-extras/src/java/org/apache/lucene/spatial/util/ShapeAreaValueSource.java
@@ -20,7 +20,6 @@ import java.io.IOException;
 import java.util.ArrayList;
 import java.util.Arrays;
 import java.util.List;
-import java.util.Map;
 
 import org.locationtech.spatial4j.context.SpatialContext;
 import org.locationtech.spatial4j.shape.Shape;
@@ -28,6 +27,7 @@ import org.locationtech.spatial4j.shape.Shape;
 import org.apache.lucene.index.LeafReaderContext;
 import org.apache.lucene.queries.function.FunctionValues;
 import org.apache.lucene.queries.function.ValueSource;
+import org.apache.lucene.queries.function.ContextMap;
 import org.apache.lucene.queries.function.docvalues.DoubleDocValues;
 import org.apache.lucene.search.Explanation;
 import org.apache.lucene.search.IndexSearcher;
@@ -59,12 +59,12 @@ public class ShapeAreaValueSource extends ValueSource {
   }
 
   @Override
-  public void createWeight(Map context, IndexSearcher searcher) throws IOException {
+  public void createWeight(ContextMap context, IndexSearcher searcher) throws IOException {
     shapeValueSource.createWeight(context, searcher);
   }
 
   @Override
-  public FunctionValues getValues(Map context, LeafReaderContext readerContext) throws IOException {
+  public FunctionValues getValues(ContextMap context, LeafReaderContext readerContext) throws IOException {
     final FunctionValues shapeValues = shapeValueSource.getValues(context, readerContext);
 
     return new DoubleDocValues(this) {
diff --git a/lucene/spatial-extras/src/java/org/apache/lucene/spatial/util/ShapeFieldCacheDistanceValueSource.java b/lucene/spatial-extras/src/java/org/apache/lucene/spatial/util/ShapeFieldCacheDistanceValueSource.java
index 1ac84e8..e447c6a 100644
--- a/lucene/spatial-extras/src/java/org/apache/lucene/spatial/util/ShapeFieldCacheDistanceValueSource.java
+++ b/lucene/spatial-extras/src/java/org/apache/lucene/spatial/util/ShapeFieldCacheDistanceValueSource.java
@@ -22,10 +22,10 @@ import org.locationtech.spatial4j.shape.Point;
 import org.apache.lucene.index.LeafReaderContext;
 import org.apache.lucene.queries.function.FunctionValues;
 import org.apache.lucene.queries.function.ValueSource;
+import org.apache.lucene.queries.function.ContextMap;
 
 import java.io.IOException;
 import java.util.List;
-import java.util.Map;
 
 /**
  * An implementation of the Lucene ValueSource that returns the spatial distance
@@ -56,7 +56,7 @@ public class ShapeFieldCacheDistanceValueSource extends ValueSource {
   }
 
   @Override
-  public FunctionValues getValues(Map context, final LeafReaderContext readerContext) throws IOException {
+  public FunctionValues getValues(ContextMap context, final LeafReaderContext readerContext) throws IOException {
     return new FunctionValues() {
       private final ShapeFieldCache<Point> cache =
           provider.getCache(readerContext.reader());
diff --git a/lucene/spatial-extras/src/java/org/apache/lucene/spatial/util/ShapePredicateValueSource.java b/lucene/spatial-extras/src/java/org/apache/lucene/spatial/util/ShapePredicateValueSource.java
index d0dc51f..4927f0a 100644
--- a/lucene/spatial-extras/src/java/org/apache/lucene/spatial/util/ShapePredicateValueSource.java
+++ b/lucene/spatial-extras/src/java/org/apache/lucene/spatial/util/ShapePredicateValueSource.java
@@ -21,6 +21,7 @@ import org.locationtech.spatial4j.shape.Shape;
 import org.apache.lucene.index.LeafReaderContext;
 import org.apache.lucene.queries.function.FunctionValues;
 import org.apache.lucene.queries.function.ValueSource;
+import org.apache.lucene.queries.function.ContextMap;
 import org.apache.lucene.queries.function.docvalues.BoolDocValues;
 import org.apache.lucene.search.Explanation;
 import org.apache.lucene.search.IndexSearcher;
@@ -30,7 +31,6 @@ import java.io.IOException;
 import java.util.ArrayList;
 import java.util.Arrays;
 import java.util.List;
-import java.util.Map;
 
 /**
  * A boolean ValueSource that compares a shape from a provided ValueSource with a given Shape and sees
@@ -62,12 +62,12 @@ public class ShapePredicateValueSource extends ValueSource {
   }
 
   @Override
-  public void createWeight(Map context, IndexSearcher searcher) throws IOException {
+  public void createWeight(ContextMap context, IndexSearcher searcher) throws IOException {
     shapeValuesource.createWeight(context, searcher);
   }
 
   @Override
-  public FunctionValues getValues(Map context, LeafReaderContext readerContext) throws IOException {
+  public FunctionValues getValues(ContextMap context, LeafReaderContext readerContext) throws IOException {
     final FunctionValues shapeValues = shapeValuesource.getValues(context, readerContext);
 
     return new BoolDocValues(this) {
diff --git a/lucene/spatial-extras/src/java/org/apache/lucene/spatial/vector/DistanceValueSource.java b/lucene/spatial-extras/src/java/org/apache/lucene/spatial/vector/DistanceValueSource.java
index e1f8f7c..21826f1 100644
--- a/lucene/spatial-extras/src/java/org/apache/lucene/spatial/vector/DistanceValueSource.java
+++ b/lucene/spatial-extras/src/java/org/apache/lucene/spatial/vector/DistanceValueSource.java
@@ -24,9 +24,9 @@ import org.apache.lucene.index.LeafReaderContext;
 import org.apache.lucene.index.DocValues;
 import org.apache.lucene.queries.function.FunctionValues;
 import org.apache.lucene.queries.function.ValueSource;
+import org.apache.lucene.queries.function.ContextMap;
 
 import java.io.IOException;
-import java.util.Map;
 
 /**
  * An implementation of the Lucene ValueSource model that returns the distance
@@ -61,7 +61,7 @@ public class DistanceValueSource extends ValueSource {
    * Returns the FunctionValues used by the function query.
    */
   @Override
-  public FunctionValues getValues(Map context, LeafReaderContext readerContext) throws IOException {
+  public FunctionValues getValues(ContextMap context, LeafReaderContext readerContext) throws IOException {
     LeafReader reader = readerContext.reader();
 
     final NumericDocValues ptX = DocValues.getNumeric(reader, strategy.getFieldNameX());
diff --git a/lucene/suggest/src/java/org/apache/lucene/search/suggest/DocumentValueSourceDictionary.java b/lucene/suggest/src/java/org/apache/lucene/search/suggest/DocumentValueSourceDictionary.java
index 2c0b8f4..98ff5fd 100644
--- a/lucene/suggest/src/java/org/apache/lucene/search/suggest/DocumentValueSourceDictionary.java
+++ b/lucene/suggest/src/java/org/apache/lucene/search/suggest/DocumentValueSourceDictionary.java
@@ -17,7 +17,6 @@
 package org.apache.lucene.search.suggest;
 
 import java.io.IOException;
-import java.util.HashMap;
 import java.util.List;
 
 import org.apache.lucene.document.Document;
@@ -26,6 +25,7 @@ import org.apache.lucene.index.LeafReaderContext;
 import org.apache.lucene.index.ReaderUtil;
 import org.apache.lucene.queries.function.FunctionValues;
 import org.apache.lucene.queries.function.ValueSource;
+import org.apache.lucene.queries.function.ContextMap;
 
 
 /**
@@ -123,7 +123,7 @@ public class DocumentValueSourceDictionary extends DocumentDictionary {
       }
       starts[leaves.size()] = reader.maxDoc();
       currentWeightValues = (leaves.size() > 0) 
-          ? weightsValueSource.getValues(new HashMap<String, Object>(), leaves.get(currentLeafIndex))
+          ? weightsValueSource.getValues(new ContextMap(), leaves.get(currentLeafIndex))
           : null;
     }
     
@@ -140,7 +140,7 @@ public class DocumentValueSourceDictionary extends DocumentDictionary {
       if (subIndex != currentLeafIndex) {
         currentLeafIndex = subIndex;
         try {
-          currentWeightValues = weightsValueSource.getValues(new HashMap<String, Object>(), leaves.get(currentLeafIndex));
+          currentWeightValues = weightsValueSource.getValues(new ContextMap(), leaves.get(currentLeafIndex));
         } catch (IOException e) {
           throw new RuntimeException(e);
         }
diff --git a/lucene/suggest/src/test/org/apache/lucene/search/suggest/analyzing/BlendedInfixSuggesterTest.java b/lucene/suggest/src/test/org/apache/lucene/search/suggest/analyzing/BlendedInfixSuggesterTest.java
index fe14e23..40270b9 100644
--- a/lucene/suggest/src/test/org/apache/lucene/search/suggest/analyzing/BlendedInfixSuggesterTest.java
+++ b/lucene/suggest/src/test/org/apache/lucene/search/suggest/analyzing/BlendedInfixSuggesterTest.java
@@ -28,6 +28,7 @@ import org.apache.lucene.analysis.MockAnalyzer;
 import org.apache.lucene.analysis.MockTokenizer;
 import org.apache.lucene.analysis.standard.StandardAnalyzer;
 import org.apache.lucene.search.BooleanQuery;
+import org.apache.lucene.search.BooleanClause.Occur;
 import org.apache.lucene.search.suggest.Input;
 import org.apache.lucene.search.suggest.InputArrayIterator;
 import org.apache.lucene.search.suggest.Lookup;
@@ -302,17 +303,17 @@ public class BlendedInfixSuggesterTest extends LuceneTestCase {
     assertEquals(2, responses.size());
 
 
-    responses = suggester.lookup(term, (Map) null, 1, false, false);
+    responses = suggester.lookup(term, (Map<BytesRef,Occur>) null, 1, false, false);
     assertEquals(1, responses.size());
 
-    responses = suggester.lookup(term, (Map) null, 2, false, false);
+    responses = suggester.lookup(term, (Map<BytesRef,Occur>) null, 2, false, false);
     assertEquals(2, responses.size());
 
 
-    responses = suggester.lookup(term, (Set) null, 1, false, false);
+    responses = suggester.lookup(term, (Set<BytesRef>) null, 1, false, false);
     assertEquals(1, responses.size());
 
-    responses = suggester.lookup(term, (Set) null, 2, false, false);
+    responses = suggester.lookup(term, (Set<BytesRef>) null, 2, false, false);
     assertEquals(2, responses.size());
 
 
