jackrabbit-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From ju...@apache.org
Subject svn commit: r1055124 - in /jackrabbit/branches/2.2: ./ jackrabbit-core/src/main/java/org/apache/jackrabbit/core/query/lucene/
Date Tue, 04 Jan 2011 18:10:29 GMT
Author: jukka
Date: Tue Jan  4 18:10:28 2011
New Revision: 1055124

URL: http://svn.apache.org/viewvc?rev=1055124&view=rev
Log:
2.2: Merged revision 1055117 (JCR-2836)

Modified:
    jackrabbit/branches/2.2/   (props changed)
    jackrabbit/branches/2.2/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/query/lucene/AbstractQueryImpl.java
    jackrabbit/branches/2.2/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/query/lucene/IOCounters.java
    jackrabbit/branches/2.2/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/query/lucene/JackrabbitQueryParser.java
    jackrabbit/branches/2.2/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/query/lucene/LocalNameRangeQuery.java
    jackrabbit/branches/2.2/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/query/lucene/LuceneQueryBuilder.java
    jackrabbit/branches/2.2/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/query/lucene/LuceneQueryFactory.java
    jackrabbit/branches/2.2/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/query/lucene/MatchAllQuery.java
    jackrabbit/branches/2.2/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/query/lucene/MatchAllScorer.java
    jackrabbit/branches/2.2/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/query/lucene/MatchAllWeight.java
    jackrabbit/branches/2.2/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/query/lucene/NameRangeQuery.java
    jackrabbit/branches/2.2/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/query/lucene/PerQueryCache.java
    jackrabbit/branches/2.2/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/query/lucene/QueryImpl.java
    jackrabbit/branches/2.2/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/query/lucene/QueryResultImpl.java
    jackrabbit/branches/2.2/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/query/lucene/RangeQuery.java
    jackrabbit/branches/2.2/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/query/lucene/SearchIndex.java
    jackrabbit/branches/2.2/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/query/lucene/Util.java
    jackrabbit/branches/2.2/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/query/lucene/WildcardNameQuery.java
    jackrabbit/branches/2.2/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/query/lucene/WildcardQuery.java

Propchange: jackrabbit/branches/2.2/
------------------------------------------------------------------------------
--- svn:mergeinfo (original)
+++ svn:mergeinfo Tue Jan  4 18:10:28 2011
@@ -2,4 +2,4 @@
 /jackrabbit/sandbox/JCR-1456:774917-886178
 /jackrabbit/sandbox/JCR-2170:812417-816332
 /jackrabbit/sandbox/tripod-JCR-2209:795441-795863
-/jackrabbit/trunk:1038201,1038203,1038205,1038657,1039064,1039347,1039408,1039422-1039423,1039888,1039946,1040033,1040090,1040459,1040601,1040606,1040661,1040958,1041379,1041439,1041761,1042643,1042647,1042978-1042982,1043084-1043086,1043088,1043343,1043357-1043358,1043430,1043554,1043616,1043618,1043637,1043656,1044312,1049473,1049491,1049520,1050346,1055068,1055070-1055071
+/jackrabbit/trunk:1038201,1038203,1038205,1038657,1039064,1039347,1039408,1039422-1039423,1039888,1039946,1040033,1040090,1040459,1040601,1040606,1040661,1040958,1041379,1041439,1041761,1042643,1042647,1042978-1042982,1043084-1043086,1043088,1043343,1043357-1043358,1043430,1043554,1043616,1043618,1043637,1043656,1044312,1049473,1049491,1049520,1050346,1055068,1055070-1055071,1055117

Modified: jackrabbit/branches/2.2/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/query/lucene/AbstractQueryImpl.java
URL: http://svn.apache.org/viewvc/jackrabbit/branches/2.2/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/query/lucene/AbstractQueryImpl.java?rev=1055124&r1=1055123&r2=1055124&view=diff
==============================================================================
--- jackrabbit/branches/2.2/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/query/lucene/AbstractQueryImpl.java (original)
+++ jackrabbit/branches/2.2/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/query/lucene/AbstractQueryImpl.java Tue Jan  4 18:10:28 2011
@@ -51,6 +51,8 @@ public abstract class AbstractQueryImpl 
      */
     private boolean documentOrder = true;
 
+    protected final PerQueryCache cache = new PerQueryCache();
+
     /**
      * Creates a new query instance from a query string.
      *

Modified: jackrabbit/branches/2.2/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/query/lucene/IOCounters.java
URL: http://svn.apache.org/viewvc/jackrabbit/branches/2.2/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/query/lucene/IOCounters.java?rev=1055124&r1=1055123&r2=1055124&view=diff
==============================================================================
--- jackrabbit/branches/2.2/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/query/lucene/IOCounters.java (original)
+++ jackrabbit/branches/2.2/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/query/lucene/IOCounters.java Tue Jan  4 18:10:28 2011
@@ -16,37 +16,30 @@
  */
 package org.apache.jackrabbit.core.query.lucene;
 
+import java.util.Map;
+import java.util.WeakHashMap;
+
 /**
  * <code>IOCounters</code> provides a basic mechanism to track I/O during query
  * execution.
  */
 public class IOCounters {
 
-    /**
-     * The key in the per-query-cache that identifies the read count.
-     */
-    private static final Object READ_COUNT = new Object();
+    private static final Map<Thread, Long> counts =
+        new WeakHashMap<Thread, Long>();
 
     /**
      * @return the current read count for caused by the current thread.
      */
-    public static long getReads() {
-        Long value = (Long) PerQueryCache.getInstance().get(IOCounters.class,  READ_COUNT);
-        if (value == null) {
-            value = 0L;
-        }
-        return value;
+    public static synchronized long getReads() {
+        Long count = counts.get(Thread.currentThread());
+        return count != null ? count : 0;
     }
 
     /**
      * Increments the read count caused by the current thread.
      */
-    public static void incrRead() {
-        PerQueryCache cache = PerQueryCache.getInstance();
-        Long value = (Long) cache.get(IOCounters.class,  READ_COUNT);
-        if (value == null) {
-            value = 0L;
-        }
-        cache.put(IOCounters.class, READ_COUNT, value + 1);
+    public static synchronized void incrRead() {
+        counts.put(Thread.currentThread(), getReads() + 1);
     }
 }

Modified: jackrabbit/branches/2.2/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/query/lucene/JackrabbitQueryParser.java
URL: http://svn.apache.org/viewvc/jackrabbit/branches/2.2/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/query/lucene/JackrabbitQueryParser.java?rev=1055124&r1=1055123&r2=1055124&view=diff
==============================================================================
--- jackrabbit/branches/2.2/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/query/lucene/JackrabbitQueryParser.java (original)
+++ jackrabbit/branches/2.2/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/query/lucene/JackrabbitQueryParser.java Tue Jan  4 18:10:28 2011
@@ -36,6 +36,8 @@ public class JackrabbitQueryParser exten
      */
     private final SynonymProvider synonymProvider;
 
+    private final PerQueryCache cache;
+
     /**
      * Creates a new query parser instance.
      *
@@ -46,9 +48,11 @@ public class JackrabbitQueryParser exten
      */
     public JackrabbitQueryParser(String fieldName,
                                  Analyzer analyzer,
-                                 SynonymProvider synonymProvider) {
+                                 SynonymProvider synonymProvider,
+                                 PerQueryCache cache) {
         super(fieldName, analyzer);
         this.synonymProvider = synonymProvider;
+        this.cache = cache;
         setAllowLeadingWildcard(true);
         setDefaultOperator(Operator.AND);
     }
@@ -155,7 +159,7 @@ public class JackrabbitQueryParser exten
         if (getLowercaseExpandedTerms()) {
             termStr = termStr.toLowerCase();
         }
-        return new WildcardQuery(field, null, translateWildcards(termStr));
+        return new WildcardQuery(field, null, translateWildcards(termStr), cache);
     }
 
     /**

Modified: jackrabbit/branches/2.2/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/query/lucene/LocalNameRangeQuery.java
URL: http://svn.apache.org/viewvc/jackrabbit/branches/2.2/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/query/lucene/LocalNameRangeQuery.java?rev=1055124&r1=1055123&r2=1055124&view=diff
==============================================================================
--- jackrabbit/branches/2.2/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/query/lucene/LocalNameRangeQuery.java (original)
+++ jackrabbit/branches/2.2/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/query/lucene/LocalNameRangeQuery.java Tue Jan  4 18:10:28 2011
@@ -34,8 +34,9 @@ public class LocalNameRangeQuery extends
      */
     public LocalNameRangeQuery(String lowerName,
                                String upperName,
-                               boolean inclusive) {
-        super(getLowerTerm(lowerName), getUpperTerm(upperName), inclusive);
+                               boolean inclusive,
+                               PerQueryCache cache) {
+        super(getLowerTerm(lowerName), getUpperTerm(upperName), inclusive, cache);
     }
 
     /**

Modified: jackrabbit/branches/2.2/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/query/lucene/LuceneQueryBuilder.java
URL: http://svn.apache.org/viewvc/jackrabbit/branches/2.2/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/query/lucene/LuceneQueryBuilder.java?rev=1055124&r1=1055123&r2=1055124&view=diff
==============================================================================
--- jackrabbit/branches/2.2/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/query/lucene/LuceneQueryBuilder.java (original)
+++ jackrabbit/branches/2.2/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/query/lucene/LuceneQueryBuilder.java Tue Jan  4 18:10:28 2011
@@ -158,6 +158,8 @@ public class LuceneQueryBuilder implemen
      */
     private final List<Exception> exceptions = new ArrayList<Exception>();
 
+    private final PerQueryCache cache;
+
     /**
      * Creates a new <code>LuceneQueryBuilder</code> instance.
      *
@@ -182,7 +184,8 @@ public class LuceneQueryBuilder implemen
                                Analyzer analyzer,
                                PropertyTypeRegistry propReg,
                                SynonymProvider synonymProvider,
-                               IndexFormatVersion indexFormatVersion) {
+                               IndexFormatVersion indexFormatVersion,
+                               PerQueryCache cache) {
         this.root = root;
         this.session = session;
         this.sharedItemMgr = sharedItemMgr;
@@ -192,6 +195,7 @@ public class LuceneQueryBuilder implemen
         this.propRegistry = propReg;
         this.synonymProvider = synonymProvider;
         this.indexFormatVersion = indexFormatVersion;
+        this.cache = cache;
 
         this.resolver = NamePathResolverImpl.create(nsMappings);
     }
@@ -221,13 +225,15 @@ public class LuceneQueryBuilder implemen
                                     Analyzer analyzer,
                                     PropertyTypeRegistry propReg,
                                     SynonymProvider synonymProvider,
-                                    IndexFormatVersion indexFormatVersion)
+                                    IndexFormatVersion indexFormatVersion,
+                                    PerQueryCache cache)
             throws RepositoryException {
         HierarchyManager hmgr = new HierarchyManagerImpl(
                 RepositoryImpl.ROOT_NODE_ID, sharedItemMgr);
         LuceneQueryBuilder builder = new LuceneQueryBuilder(
                 root, session, sharedItemMgr, hmgr, nsMappings,
-                analyzer, propReg, synonymProvider, indexFormatVersion);
+                analyzer, propReg, synonymProvider, indexFormatVersion,
+                cache);
 
         Query q = builder.createLuceneQuery();
         if (builder.exceptions.size() > 0) {
@@ -416,7 +422,7 @@ public class LuceneQueryBuilder implemen
                 fieldname = tmp.toString();
             }
             QueryParser parser = new JackrabbitQueryParser(
-                    fieldname, analyzer, synonymProvider);
+                    fieldname, analyzer, synonymProvider, cache);
             Query context = parser.parse(node.getQuery());
             if (relPath != null && (!node.getReferencesProperty() || relPath.getLength() > 1)) {
                 // text search on some child axis
@@ -611,7 +617,7 @@ public class LuceneQueryBuilder implemen
             String refProperty = resolver.getJCRName(node.getRefProperty());
 
             if (node.getIncludeDescendants()) {
-                Query refPropQuery = Util.createMatchAllQuery(refProperty, indexFormatVersion);
+                Query refPropQuery = Util.createMatchAllQuery(refProperty, indexFormatVersion, cache);
                 context = new DescendantSelfAxisQuery(context, refPropQuery, false);
             }
 
@@ -745,7 +751,7 @@ public class LuceneQueryBuilder implemen
                     query = new org.apache.lucene.search.MatchAllDocsQuery();
                 } else {
                     query = new WildcardNameQuery(stringValues[0], 
-                            transform[0], session, nsMappings);
+                            transform[0], session, nsMappings, cache);
                 }
             } else {
                 exceptions.add(new InvalidQueryException("Name function can "
@@ -782,7 +788,7 @@ public class LuceneQueryBuilder implemen
                     for (String value : stringValues) {
                         Term lower = new Term(FieldNames.PROPERTIES, FieldNames.createNamedValue(field, value));
                         Term upper = new Term(FieldNames.PROPERTIES, FieldNames.createNamedValue(field, "\uFFFF"));
-                        or.add(new RangeQuery(lower, upper, true, transform[0]), Occur.SHOULD);
+                        or.add(new RangeQuery(lower, upper, true, transform[0], cache), Occur.SHOULD);
                     }
                     query = or;
                     if (node.getOperation() == QueryConstants.OPERATION_GE_VALUE) {
@@ -795,7 +801,7 @@ public class LuceneQueryBuilder implemen
                     for (String value : stringValues) {
                         Term lower = new Term(FieldNames.PROPERTIES, FieldNames.createNamedValue(field, value));
                         Term upper = new Term(FieldNames.PROPERTIES, FieldNames.createNamedValue(field, "\uFFFF"));
-                        or.add(new RangeQuery(lower, upper, false, transform[0]), Occur.SHOULD);
+                        or.add(new RangeQuery(lower, upper, false, transform[0], cache), Occur.SHOULD);
                     }
                     query = or;
                     if (node.getOperation() == QueryConstants.OPERATION_GT_VALUE) {
@@ -808,7 +814,7 @@ public class LuceneQueryBuilder implemen
                     for (String value : stringValues) {
                         Term lower = new Term(FieldNames.PROPERTIES, FieldNames.createNamedValue(field, ""));
                         Term upper = new Term(FieldNames.PROPERTIES, FieldNames.createNamedValue(field, value));
-                        or.add(new RangeQuery(lower, upper, true, transform[0]), Occur.SHOULD);
+                        or.add(new RangeQuery(lower, upper, true, transform[0], cache), Occur.SHOULD);
                     }
                     query = or;
                     if (node.getOperation() == QueryConstants.OPERATION_LE_VALUE) {
@@ -819,9 +825,9 @@ public class LuceneQueryBuilder implemen
                     // the like operation always has one string value.
                     // no coercing, see above
                     if (stringValues[0].equals("%")) {
-                        query = Util.createMatchAllQuery(field, indexFormatVersion);
+                        query = Util.createMatchAllQuery(field, indexFormatVersion, cache);
                     } else {
-                        query = new WildcardQuery(FieldNames.PROPERTIES, field, stringValues[0], transform[0]);
+                        query = new WildcardQuery(FieldNames.PROPERTIES, field, stringValues[0], transform[0], cache);
                     }
                     break;
                 case QueryConstants.OPERATION_LT_VALUE:      // <
@@ -830,7 +836,7 @@ public class LuceneQueryBuilder implemen
                     for (String value : stringValues) {
                         Term lower = new Term(FieldNames.PROPERTIES, FieldNames.createNamedValue(field, ""));
                         Term upper = new Term(FieldNames.PROPERTIES, FieldNames.createNamedValue(field, value));
-                        or.add(new RangeQuery(lower, upper, false, transform[0]), Occur.SHOULD);
+                        or.add(new RangeQuery(lower, upper, false, transform[0], cache), Occur.SHOULD);
                     }
                     query = or;
                     if (node.getOperation() == QueryConstants.OPERATION_LT_VALUE) {
@@ -840,7 +846,7 @@ public class LuceneQueryBuilder implemen
                 case QueryConstants.OPERATION_NE_VALUE:      // !=
                     // match nodes with property 'field' that includes svp and mvp
                     BooleanQuery notQuery = new BooleanQuery();
-                    notQuery.add(Util.createMatchAllQuery(field, indexFormatVersion), Occur.SHOULD);
+                    notQuery.add(Util.createMatchAllQuery(field, indexFormatVersion, cache), Occur.SHOULD);
                     // exclude all nodes where 'field' has the term in question
                     for (String value : stringValues) {
                         Term t = new Term(FieldNames.PROPERTIES, FieldNames.createNamedValue(field, value));
@@ -867,7 +873,7 @@ public class LuceneQueryBuilder implemen
                     // minus the nodes that have a multi-valued property 'field' and
                     //    all values are equal to term in question
                     notQuery = new BooleanQuery();
-                    notQuery.add(Util.createMatchAllQuery(field, indexFormatVersion), Occur.SHOULD);
+                    notQuery.add(Util.createMatchAllQuery(field, indexFormatVersion, cache), Occur.SHOULD);
                     for (String value : stringValues) {
                         // exclude the nodes that have the term and are single valued
                         Term t = new Term(FieldNames.PROPERTIES, FieldNames.createNamedValue(field, value));
@@ -891,7 +897,7 @@ public class LuceneQueryBuilder implemen
                     query = notQuery;
                     break;
                 case QueryConstants.OPERATION_NULL:
-                    query = new NotQuery(Util.createMatchAllQuery(field, indexFormatVersion));
+                    query = new NotQuery(Util.createMatchAllQuery(field, indexFormatVersion, cache));
                     break;
                 case QueryConstants.OPERATION_SIMILAR:
                     try {
@@ -907,10 +913,10 @@ public class LuceneQueryBuilder implemen
                     }
                     break;
                 case QueryConstants.OPERATION_NOT_NULL:
-                    query = Util.createMatchAllQuery(field, indexFormatVersion);
+                    query = Util.createMatchAllQuery(field, indexFormatVersion, cache);
                     break;
                 case QueryConstants.OPERATION_SPELLCHECK:
-                    query = Util.createMatchAllQuery(field, indexFormatVersion);
+                    query = Util.createMatchAllQuery(field, indexFormatVersion, cache);
                     break;
                 default:
                     throw new IllegalArgumentException("Unknown relation operation: "

Modified: jackrabbit/branches/2.2/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/query/lucene/LuceneQueryFactory.java
URL: http://svn.apache.org/viewvc/jackrabbit/branches/2.2/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/query/lucene/LuceneQueryFactory.java?rev=1055124&r1=1055123&r2=1055124&view=diff
==============================================================================
--- jackrabbit/branches/2.2/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/query/lucene/LuceneQueryFactory.java (original)
+++ jackrabbit/branches/2.2/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/query/lucene/LuceneQueryFactory.java Tue Jan  4 18:10:28 2011
@@ -144,6 +144,8 @@ public class LuceneQueryFactory {
 
     private final String primaryTypeField;
 
+    private final PerQueryCache cache = new PerQueryCache();
+
     /**
      * Creates a new lucene query factory.
      *
@@ -208,7 +210,6 @@ public class LuceneQueryFactory {
             }
             return rows;
         } finally {
-            PerQueryCache.getInstance().dispose();
             Util.closeOrRelease(reader);
         }
     }
@@ -278,7 +279,8 @@ public class LuceneQueryFactory {
             fieldname = tmp.toString();
         }
         QueryParser parser = new JackrabbitQueryParser(
-                fieldname, index.getTextAnalyzer(), index.getSynonymProvider());
+                fieldname, index.getTextAnalyzer(),
+                index.getSynonymProvider(), cache);
         try {
             StaticOperand expr = fts.getFullTextSearchExpression();
             return parser.parse(evaluator.getValue(expr).getString());
@@ -296,7 +298,8 @@ public class LuceneQueryFactory {
      */
     public Query create(PropertyExistenceImpl prop) throws RepositoryException {
         String propName = npResolver.getJCRName(prop.getPropertyQName());
-        return Util.createMatchAllQuery(propName, index.getIndexFormatVersion());
+        return Util.createMatchAllQuery(
+                propName, index.getIndexFormatVersion(), cache);
     }
 
     protected Predicate mapConstraintToQueryAndFilter(
@@ -445,7 +448,8 @@ public class LuceneQueryFactory {
         String query = evaluator.getValue(expression).getString();
         try {
             QueryParser parser = new JackrabbitQueryParser(
-                    field, index.getTextAnalyzer(), index.getSynonymProvider());
+                    field, index.getTextAnalyzer(),
+                    index.getSynonymProvider(), cache);
             return parser.parse(query);
         } catch (ParseException e) {
             throw new RepositoryException(
@@ -509,7 +513,8 @@ public class LuceneQueryFactory {
             throws RepositoryException {
         String name = npResolver.getJCRName(session.getQName(
                 property.getPropertyName()));
-        return Util.createMatchAllQuery(name, index.getIndexFormatVersion());
+        return Util.createMatchAllQuery(
+                name, index.getIndexFormatVersion(), cache);
     }
 
     protected static class Transform {
@@ -636,7 +641,7 @@ public class LuceneQueryFactory {
             int type, int transform) throws RepositoryException {
         String string = getValueString(value, type);
         if (JCR_OPERATOR_LIKE.equals(operator)) {
-            return new WildcardQuery(PROPERTIES, field, string, transform);
+            return new WildcardQuery(PROPERTIES, field, string, transform, cache);
         }
 
         Term term = getTerm(field, string);
@@ -650,17 +655,17 @@ public class LuceneQueryFactory {
                 return new JackrabbitTermQuery(term);
             }
         } else if (JCR_OPERATOR_GREATER_THAN.equals(operator)) {
-            return new RangeQuery(term, getTerm(field, "\uFFFF"), false, transform);
+            return new RangeQuery(term, getTerm(field, "\uFFFF"), false, transform, cache);
         } else if (JCR_OPERATOR_GREATER_THAN_OR_EQUAL_TO.equals(operator)) {
-            return new RangeQuery(term, getTerm(field, "\uFFFF"), true, transform);
+            return new RangeQuery(term, getTerm(field, "\uFFFF"), true, transform, cache);
         } else if (JCR_OPERATOR_LESS_THAN.equals(operator)) {
-            return new RangeQuery(getTerm(field, ""), term, false, transform);
+            return new RangeQuery(getTerm(field, ""), term, false, transform, cache);
         } else if (JCR_OPERATOR_LESS_THAN_OR_EQUAL_TO.equals(operator)) {
-            return new RangeQuery(getTerm(field, ""), term, true, transform);
+            return new RangeQuery(getTerm(field, ""), term, true, transform, cache);
         } else if (JCR_OPERATOR_NOT_EQUAL_TO.equals(operator)) {
             BooleanQuery query = new BooleanQuery();
             query.add(Util.createMatchAllQuery(
-                    field, index.getIndexFormatVersion()), SHOULD);
+                    field, index.getIndexFormatVersion(), cache), SHOULD);
             switch (transform) {
             case TRANSFORM_UPPER_CASE:
                 query.add(new CaseTermQuery.Upper(term), MUST_NOT);

Modified: jackrabbit/branches/2.2/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/query/lucene/MatchAllQuery.java
URL: http://svn.apache.org/viewvc/jackrabbit/branches/2.2/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/query/lucene/MatchAllQuery.java?rev=1055124&r1=1055123&r2=1055124&view=diff
==============================================================================
--- jackrabbit/branches/2.2/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/query/lucene/MatchAllQuery.java (original)
+++ jackrabbit/branches/2.2/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/query/lucene/MatchAllQuery.java Tue Jan  4 18:10:28 2011
@@ -30,6 +30,8 @@ class MatchAllQuery extends Query {
 
     private final String field;
 
+    private final PerQueryCache cache;
+
     /**
      * Creates a new <code>MatchAllQuery</code> .
      * <p/>
@@ -37,11 +39,13 @@ class MatchAllQuery extends Query {
      * @param field the field name.
      * @throws NullPointerException if <code>field</code> is null.
      */
-    MatchAllQuery(String field) throws NullPointerException {
+    MatchAllQuery(String field, PerQueryCache cache)
+            throws NullPointerException {
         if (field == null) {
             throw new NullPointerException("field");
         }
         this.field = field.intern();
+        this.cache = cache;
     }
 
     /**
@@ -51,7 +55,7 @@ class MatchAllQuery extends Query {
      * @return the <code>Weight</code> for this Query.
      */
     protected Weight createWeight(Searcher searcher) {
-        return new MatchAllWeight(this, searcher, field);
+        return new MatchAllWeight(this, searcher, field, cache);
     }
 
     /**

Modified: jackrabbit/branches/2.2/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/query/lucene/MatchAllScorer.java
URL: http://svn.apache.org/viewvc/jackrabbit/branches/2.2/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/query/lucene/MatchAllScorer.java?rev=1055124&r1=1055123&r2=1055124&view=diff
==============================================================================
--- jackrabbit/branches/2.2/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/query/lucene/MatchAllScorer.java (original)
+++ jackrabbit/branches/2.2/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/query/lucene/MatchAllScorer.java Tue Jan  4 18:10:28 2011
@@ -69,7 +69,7 @@ class MatchAllScorer extends Scorer {
      * @throws IOException if an error occurs while collecting hits.
      *                     e.g. while reading from the search index.
      */
-    MatchAllScorer(IndexReader reader, String field)
+    MatchAllScorer(IndexReader reader, String field, PerQueryCache cache)
             throws IOException {
         super(Similarity.getDefault());
         this.reader = reader;
@@ -78,7 +78,7 @@ class MatchAllScorer extends Scorer {
                 = new Explanation(Similarity.getDefault().idf(reader.maxDoc(),
                         reader.maxDoc()),
                         "matchAll");
-        calculateDocFilter();
+        calculateDocFilter(cache);
     }
 
     /**
@@ -136,8 +136,7 @@ class MatchAllScorer extends Scorer {
      *                     the search index.
      */
     @SuppressWarnings({"unchecked"})
-    private void calculateDocFilter() throws IOException {
-        PerQueryCache cache = PerQueryCache.getInstance();
+    private void calculateDocFilter(PerQueryCache cache) throws IOException {
         Map<String, BitSet> readerCache = (Map<String, BitSet>) cache.get(MatchAllScorer.class, reader);
         if (readerCache == null) {
             readerCache = new HashMap<String, BitSet>();

Modified: jackrabbit/branches/2.2/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/query/lucene/MatchAllWeight.java
URL: http://svn.apache.org/viewvc/jackrabbit/branches/2.2/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/query/lucene/MatchAllWeight.java?rev=1055124&r1=1055123&r2=1055124&view=diff
==============================================================================
--- jackrabbit/branches/2.2/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/query/lucene/MatchAllWeight.java (original)
+++ jackrabbit/branches/2.2/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/query/lucene/MatchAllWeight.java Tue Jan  4 18:10:28 2011
@@ -40,6 +40,8 @@ class MatchAllWeight extends AbstractWei
      */
     private final Query query;
 
+    private final PerQueryCache cache;
+
     /**
      * the weight value
      */
@@ -60,10 +62,12 @@ class MatchAllWeight extends AbstractWei
      * @param searcher
      * @param field name of the field to match
      */
-    MatchAllWeight(Query query, Searcher searcher, String field) {
+    MatchAllWeight(
+            Query query, Searcher searcher, String field, PerQueryCache cache) {
         super(searcher);
         this.query = query;
         this.field = field;
+        this.cache = cache;
     }
 
     /**
@@ -73,7 +77,7 @@ class MatchAllWeight extends AbstractWei
      * @return a {@link MatchAllScorer} instance
      */
     protected Scorer createScorer(IndexReader reader) throws IOException {
-        return new MatchAllScorer(reader, field);
+        return new MatchAllScorer(reader, field, cache);
     }
 
     /**

Modified: jackrabbit/branches/2.2/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/query/lucene/NameRangeQuery.java
URL: http://svn.apache.org/viewvc/jackrabbit/branches/2.2/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/query/lucene/NameRangeQuery.java?rev=1055124&r1=1055123&r2=1055124&view=diff
==============================================================================
--- jackrabbit/branches/2.2/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/query/lucene/NameRangeQuery.java (original)
+++ jackrabbit/branches/2.2/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/query/lucene/NameRangeQuery.java Tue Jan  4 18:10:28 2011
@@ -59,6 +59,8 @@ public class NameRangeQuery extends Quer
      */
     private final NamespaceMappings nsMappings;
 
+    private final PerQueryCache cache;
+
     /**
      * Creates a new NameRangeQuery. The lower or the upper name may be
      * <code>null</code>, but not both!
@@ -73,7 +75,8 @@ public class NameRangeQuery extends Quer
                           Name upperName,
                           boolean inclusive,
                           IndexFormatVersion version,
-                          NamespaceMappings nsMappings) {
+                          NamespaceMappings nsMappings,
+                          PerQueryCache cache) {
         if (lowerName == null && upperName == null) {
             throw new IllegalArgumentException("At least one term must be non-null");
         }
@@ -86,23 +89,28 @@ public class NameRangeQuery extends Quer
         this.inclusive = inclusive;
         this.version = version;
         this.nsMappings = nsMappings;
+        this.cache = cache;
     }
 
     /**
      * {@inheritDoc}
      */
     public Query rewrite(IndexReader reader) throws IOException {
+        Query q;
         if (version.getVersion() >= IndexFormatVersion.V3.getVersion()) {
-            RangeQuery localNames = new RangeQuery(getLowerLocalNameTerm(),
-                    getUpperLocalNameTerm(), inclusive);
+            RangeQuery localNames = new RangeQuery(
+                    getLowerLocalNameTerm(), getUpperLocalNameTerm(),
+                    inclusive, cache);
             BooleanQuery query = new BooleanQuery();
             query.add(new JackrabbitTermQuery(new Term(FieldNames.NAMESPACE_URI,
                     getNamespaceURI())), BooleanClause.Occur.MUST);
             query.add(localNames, BooleanClause.Occur.MUST);
-            return query.rewrite(reader);
+            q = query;
         } else {
-            return new RangeQuery(getLowerTerm(), getUpperTerm(), inclusive).rewrite(reader);
+            q = new RangeQuery(
+                    getLowerTerm(), getUpperTerm(), inclusive, cache);
         }
+        return q.rewrite(reader);
     }
 
     /**

Modified: jackrabbit/branches/2.2/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/query/lucene/PerQueryCache.java
URL: http://svn.apache.org/viewvc/jackrabbit/branches/2.2/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/query/lucene/PerQueryCache.java?rev=1055124&r1=1055123&r2=1055124&view=diff
==============================================================================
--- jackrabbit/branches/2.2/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/query/lucene/PerQueryCache.java (original)
+++ jackrabbit/branches/2.2/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/query/lucene/PerQueryCache.java Tue Jan  4 18:10:28 2011
@@ -20,10 +20,8 @@ import java.util.HashMap;
 import java.util.Map;
 
 /**
- * <code>PerQueryCache</code> implements a hash map on a per thread basis for
- * the purpose of caching results while a query is executed. When the query
- * finished the cache can be disposed by calling:
- * <code>PerQueryCache.getInstance().dispose()</code>.
+ * A cache of arbitrarily typed values used during the execution of a
+ * single query.
  */
 class PerQueryCache {
 
@@ -33,29 +31,6 @@ class PerQueryCache {
     private final Map<Key, Object> map = new HashMap<Key, Object>();
 
     /**
-     * Private constructor.
-     */
-    private PerQueryCache() {
-    }
-
-    /**
-     * The per thread cache instance.
-     */
-    private static final ThreadLocal<PerQueryCache> CACHE = new ThreadLocal<PerQueryCache>();
-
-    /**
-     * @return <code>PerQueryCache</code> for the current thread.
-     */
-    static PerQueryCache getInstance() {
-        PerQueryCache cache = CACHE.get();
-        if (cache == null) {
-            cache = new PerQueryCache();
-            CACHE.set(cache);
-        }
-        return cache;
-    }
-
-    /**
      * Returns the value from the cache with the given <code>type</code> and
      * <code>key</code>.
      *
@@ -64,7 +39,7 @@ class PerQueryCache {
      * @return the value assigned to <code>type</code> and <code>key</code> or
      *         <code>null</code> if it does not exist in the cache.
      */
-    Object get(Class type, Object key) {
+    Object get(Class<?> type, Object key) {
         return map.get(new Key(type, key));
     }
 
@@ -78,18 +53,11 @@ class PerQueryCache {
      * @return the existing value in the cache assigned to <code>type</code> and
      *         <code>key</code> or <code>null</code> if there was none.
      */
-    Object put(Class type, Object key, Object value) {
+    Object put(Class<?> type, Object key, Object value) {
         return map.put(new Key(type, key), value);
     }
 
     /**
-     * Disposes the <code>PerQueryCache</code> for the current thread.
-     */
-    void dispose() {
-        CACHE.set(null);
-    }
-
-    /**
      * Simple key class.
      */
     private static final class Key {
@@ -97,7 +65,7 @@ class PerQueryCache {
         /**
          * The query type.
          */
-        private final Class type;
+        private final Class<?> type;
 
         /**
          * The key object.
@@ -110,7 +78,7 @@ class PerQueryCache {
          * @param type the query type.
          * @param key the key object.
          */
-        private Key(Class type, Object key) {
+        private Key(Class<?> type, Object key) {
             this.type = type;
             this.key = key;
         }

Modified: jackrabbit/branches/2.2/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/query/lucene/QueryImpl.java
URL: http://svn.apache.org/viewvc/jackrabbit/branches/2.2/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/query/lucene/QueryImpl.java?rev=1055124&r1=1055123&r2=1055124&view=diff
==============================================================================
--- jackrabbit/branches/2.2/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/query/lucene/QueryImpl.java (original)
+++ jackrabbit/branches/2.2/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/query/lucene/QueryImpl.java Tue Jan  4 18:10:28 2011
@@ -114,7 +114,8 @@ public class QueryImpl extends AbstractQ
                 index.getContext().getItemStateManager(),
                 index.getNamespaceMappings(), index.getTextAnalyzer(),
                 propReg, index.getSynonymProvider(),
-                index.getIndexFormatVersion());
+                index.getIndexFormatVersion(),
+                cache);
 
         OrderQueryNode orderNode = root.getOrderNode();
 

Modified: jackrabbit/branches/2.2/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/query/lucene/QueryResultImpl.java
URL: http://svn.apache.org/viewvc/jackrabbit/branches/2.2/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/query/lucene/QueryResultImpl.java?rev=1055124&r1=1055123&r2=1055124&view=diff
==============================================================================
--- jackrabbit/branches/2.2/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/query/lucene/QueryResultImpl.java (original)
+++ jackrabbit/branches/2.2/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/query/lucene/QueryResultImpl.java Tue Jan  4 18:10:28 2011
@@ -306,8 +306,6 @@ public abstract class QueryResultImpl im
                     log.warn("Unable to close query result: " + e);
                 }
             }
-            // make sure PerQueryCache is disposed
-            PerQueryCache.getInstance().dispose();
         }
     }
 

Modified: jackrabbit/branches/2.2/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/query/lucene/RangeQuery.java
URL: http://svn.apache.org/viewvc/jackrabbit/branches/2.2/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/query/lucene/RangeQuery.java?rev=1055124&r1=1055123&r2=1055124&view=diff
==============================================================================
--- jackrabbit/branches/2.2/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/query/lucene/RangeQuery.java (original)
+++ jackrabbit/branches/2.2/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/query/lucene/RangeQuery.java Tue Jan  4 18:10:28 2011
@@ -74,6 +74,8 @@ public class RangeQuery extends Query im
      */
     private int transform = TRANSFORM_NONE;
 
+    private final PerQueryCache cache;
+
     /**
      * The rewritten range query or <code>null</code> if the range spans more
      * than {@link org.apache.lucene.search.BooleanQuery#maxClauseCount} terms.
@@ -88,8 +90,10 @@ public class RangeQuery extends Query im
      * @param upperTerm the upper term of the interval, or <code>null</code>.
      * @param inclusive if <code>true</code> the interval is inclusive.
      */
-    public RangeQuery(Term lowerTerm, Term upperTerm, boolean inclusive) {
-        this(lowerTerm, upperTerm, inclusive, TRANSFORM_NONE);
+    public RangeQuery(
+            Term lowerTerm, Term upperTerm, boolean inclusive,
+            PerQueryCache cache) {
+        this(lowerTerm, upperTerm, inclusive, TRANSFORM_NONE, cache);
     }
 
     /**
@@ -101,7 +105,9 @@ public class RangeQuery extends Query im
      * @param inclusive if <code>true</code> the interval is inclusive.
      * @param transform how term enums are transformed when read from the index.
      */
-    public RangeQuery(Term lowerTerm, Term upperTerm, boolean inclusive, int transform) {
+    public RangeQuery(
+            Term lowerTerm, Term upperTerm, boolean inclusive, int transform,
+            PerQueryCache cache) {
         if (lowerTerm == null && upperTerm == null) {
             throw new IllegalArgumentException("At least one term must be non-null");
         }
@@ -119,6 +125,7 @@ public class RangeQuery extends Query im
         this.upperTerm = upperTerm;
         this.inclusive = inclusive;
         this.transform = transform;
+        this.cache = cache;
     }
 
     /**
@@ -163,7 +170,7 @@ public class RangeQuery extends Query im
      * @return the <code>Weigth</code> for this query.
      */
     protected Weight createWeight(Searcher searcher) {
-        return new RangeQueryWeight(searcher);
+        return new RangeQueryWeight(searcher, cache);
     }
 
     /**
@@ -212,14 +219,17 @@ public class RangeQuery extends Query im
      */
     private class RangeQueryWeight extends AbstractWeight {
 
+        private final PerQueryCache cache;
+
         /**
          * Creates a new <code>RangeQueryWeight</code> instance using
          * <code>searcher</code>.
          *
          * @param searcher a <code>Searcher</code> instance.
          */
-        RangeQueryWeight(Searcher searcher) {
+        RangeQueryWeight(Searcher searcher, PerQueryCache cache) {
             super(searcher);
+            this.cache = cache;
         }
 
         /**
@@ -229,7 +239,7 @@ public class RangeQuery extends Query im
          * @return a {@link RangeQueryScorer} instance
          */
         protected Scorer createScorer(IndexReader reader) {
-            return new RangeQueryScorer(searcher.getSimilarity(), reader);
+            return new RangeQueryScorer(searcher.getSimilarity(), reader, cache);
         }
 
         /**
@@ -312,7 +322,9 @@ public class RangeQuery extends Query im
          * @param reader the index reader to use.
          */
         @SuppressWarnings({"unchecked"})
-        RangeQueryScorer(Similarity similarity, IndexReader reader) {
+        RangeQueryScorer(
+                Similarity similarity, IndexReader reader,
+                PerQueryCache cache) {
             super(similarity);
             this.reader = reader;
             StringBuffer key = new StringBuffer();
@@ -327,7 +339,6 @@ public class RangeQuery extends Query im
             key.append(transform);
             this.cacheKey = key.toString();
             // check cache
-            PerQueryCache cache = PerQueryCache.getInstance();
             Map<String, BitSet> m = (Map<String, BitSet>) cache.get(RangeQueryScorer.class, reader);
             if (m == null) {
                 m = new HashMap<String, BitSet>();

Modified: jackrabbit/branches/2.2/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/query/lucene/SearchIndex.java
URL: http://svn.apache.org/viewvc/jackrabbit/branches/2.2/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/query/lucene/SearchIndex.java?rev=1055124&r1=1055123&r2=1055124&view=diff
==============================================================================
--- jackrabbit/branches/2.2/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/query/lucene/SearchIndex.java (original)
+++ jackrabbit/branches/2.2/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/query/lucene/SearchIndex.java Tue Jan  4 18:10:28 2011
@@ -795,7 +795,6 @@ public class SearchIndex extends Abstrac
                 try {
                     super.close();
                 } finally {
-                    PerQueryCache.getInstance().dispose();
                     Util.closeOrRelease(reader);
                 }
             }
@@ -829,7 +828,6 @@ public class SearchIndex extends Abstrac
                 try {
                     super.close();
                 } finally {
-                    PerQueryCache.getInstance().dispose();
                     Util.closeOrRelease(reader);
                 }
             }

Modified: jackrabbit/branches/2.2/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/query/lucene/Util.java
URL: http://svn.apache.org/viewvc/jackrabbit/branches/2.2/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/query/lucene/Util.java?rev=1055124&r1=1055123&r2=1055124&view=diff
==============================================================================
--- jackrabbit/branches/2.2/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/query/lucene/Util.java (original)
+++ jackrabbit/branches/2.2/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/query/lucene/Util.java Tue Jan  4 18:10:28 2011
@@ -97,12 +97,13 @@ public class Util {
      * @return Query that matches all nodes that have a property with the given
      *         <code>name</code>.
      */
-    public static Query createMatchAllQuery(String name, IndexFormatVersion version) {
+    public static Query createMatchAllQuery(
+            String name, IndexFormatVersion version, PerQueryCache cache) {
         if (version.getVersion() >= IndexFormatVersion.V2.getVersion()) {
             // new index format style
             return new JackrabbitTermQuery(new Term(FieldNames.PROPERTIES_SET, name));
         } else {
-            return new MatchAllQuery(name);
+            return new MatchAllQuery(name, cache);
         }
     }
 

Modified: jackrabbit/branches/2.2/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/query/lucene/WildcardNameQuery.java
URL: http://svn.apache.org/viewvc/jackrabbit/branches/2.2/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/query/lucene/WildcardNameQuery.java?rev=1055124&r1=1055123&r2=1055124&view=diff
==============================================================================
--- jackrabbit/branches/2.2/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/query/lucene/WildcardNameQuery.java (original)
+++ jackrabbit/branches/2.2/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/query/lucene/WildcardNameQuery.java Tue Jan  4 18:10:28 2011
@@ -53,9 +53,10 @@ public class WildcardNameQuery extends W
     public WildcardNameQuery(String pattern,
                              int transform,
                              NamespaceResolver resolver,
-                             NamespaceMappings nsMappings) {
+                             NamespaceMappings nsMappings,
+                             PerQueryCache cache) {
         super(FieldNames.LABEL, null,
-                convertPattern(pattern, resolver, nsMappings), transform);
+                convertPattern(pattern, resolver, nsMappings), transform, cache);
     }
 
     private static String convertPattern(String pattern,

Modified: jackrabbit/branches/2.2/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/query/lucene/WildcardQuery.java
URL: http://svn.apache.org/viewvc/jackrabbit/branches/2.2/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/query/lucene/WildcardQuery.java?rev=1055124&r1=1055123&r2=1055124&view=diff
==============================================================================
--- jackrabbit/branches/2.2/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/query/lucene/WildcardQuery.java (original)
+++ jackrabbit/branches/2.2/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/query/lucene/WildcardQuery.java Tue Jan  4 18:10:28 2011
@@ -76,6 +76,8 @@ public class WildcardQuery extends Query
      */
     private int transform = TRANSFORM_NONE;
 
+    private final PerQueryCache cache;
+
     /**
      * The standard multi term query to execute wildcard queries. This is only
      * set if the pattern matches less than {@link org.apache.lucene.search.BooleanQuery#maxClauseCount}.
@@ -91,10 +93,13 @@ public class WildcardQuery extends Query
      * @param transform how property values are transformed before they are
      *                  matched using the <code>pattern</code>.
      */
-    public WildcardQuery(String field, final String propName, String pattern, int transform) {
+    public WildcardQuery(
+            String field, final String propName, String pattern, int transform,
+            PerQueryCache cache) {
         this.field = field.intern();
         this.pattern = pattern;
         this.transform = transform;
+        this.cache = cache;
         if (propName != null) {
             tvf = new WildcardTermEnum.TermValueFactory() {
                 @Override
@@ -114,8 +119,9 @@ public class WildcardQuery extends Query
      * @param propName name of the property to search.
      * @param pattern  the wildcard pattern.
      */
-    public WildcardQuery(String field, String propName, String pattern) {
-        this(field, propName, pattern, TRANSFORM_NONE);
+    public WildcardQuery(
+            String field, String propName, String pattern, PerQueryCache cache) {
+        this(field, propName, pattern, TRANSFORM_NONE, cache);
     }
 
     /**
@@ -157,7 +163,7 @@ public class WildcardQuery extends Query
      * @return the <code>Weigth</code> for this query.
      */
     protected Weight createWeight(Searcher searcher) {
-        return new WildcardQueryWeight(searcher);
+        return new WildcardQueryWeight(searcher, cache);
     }
 
     /**
@@ -184,14 +190,17 @@ public class WildcardQuery extends Query
      */
     private class WildcardQueryWeight extends AbstractWeight {
 
+        private final PerQueryCache cache;
+
         /**
          * Creates a new <code>WildcardQueryWeight</code> instance using
          * <code>searcher</code>.
          *
          * @param searcher a <code>Searcher</code> instance.
          */
-        public WildcardQueryWeight(Searcher searcher) {
+        public WildcardQueryWeight(Searcher searcher, PerQueryCache cache) {
             super(searcher);
+            this.cache = cache;
         }
 
         /**
@@ -201,7 +210,7 @@ public class WildcardQuery extends Query
          * @return a {@link WildcardQueryScorer} instance
          */
         protected Scorer createScorer(IndexReader reader) {
-            return new WildcardQueryScorer(searcher.getSimilarity(), reader);
+            return new WildcardQueryScorer(searcher.getSimilarity(), reader, cache);
         }
 
         /**
@@ -283,12 +292,13 @@ public class WildcardQuery extends Query
          * @param reader     the index reader to use.
          */
         @SuppressWarnings({"unchecked"})
-        WildcardQueryScorer(Similarity similarity, IndexReader reader) {
+        WildcardQueryScorer(
+                Similarity similarity, IndexReader reader,
+                PerQueryCache cache) {
             super(similarity);
             this.reader = reader;
             this.cacheKey = field + '\uFFFF' + tvf.createValue('\uFFFF' + pattern) + '\uFFFF' + transform;
             // check cache
-            PerQueryCache cache = PerQueryCache.getInstance();
             Map<String, BitSet> m = (Map<String, BitSet>) cache.get(WildcardQueryScorer.class, reader);
             if (m == null) {
                 m = new HashMap<String, BitSet>();



Mime
View raw message