Index: lucene/src/java/org/apache/lucene/search/FieldCacheImpl.java =================================================================== --- lucene/src/java/org/apache/lucene/search/FieldCacheImpl.java (revision 1141501) +++ lucene/src/java/org/apache/lucene/search/FieldCacheImpl.java (revision ) @@ -17,32 +17,16 @@ * limitations under the License. */ -import java.io.IOException; -import java.io.PrintStream; -import java.util.ArrayList; -import java.util.HashMap; -import java.util.List; -import java.util.Map; -import java.util.WeakHashMap; - +import org.apache.lucene.index.DocTermOrds; import org.apache.lucene.index.IndexReader; -import org.apache.lucene.search.cache.ByteValuesCreator; -import org.apache.lucene.search.cache.DocTermsCreator; -import org.apache.lucene.search.cache.DocTermsIndexCreator; -import org.apache.lucene.search.cache.DoubleValuesCreator; -import org.apache.lucene.search.cache.EntryCreator; -import org.apache.lucene.search.cache.FloatValuesCreator; -import org.apache.lucene.search.cache.IntValuesCreator; -import org.apache.lucene.search.cache.LongValuesCreator; -import org.apache.lucene.search.cache.ShortValuesCreator; -import org.apache.lucene.search.cache.CachedArray.ByteValues; -import org.apache.lucene.search.cache.CachedArray.DoubleValues; -import org.apache.lucene.search.cache.CachedArray.FloatValues; -import org.apache.lucene.search.cache.CachedArray.IntValues; -import org.apache.lucene.search.cache.CachedArray.LongValues; -import org.apache.lucene.search.cache.CachedArray.ShortValues; +import org.apache.lucene.search.cache.*; +import org.apache.lucene.search.cache.CachedArray.*; import org.apache.lucene.util.FieldCacheSanityChecker; +import java.io.IOException; +import java.io.PrintStream; +import java.util.*; + /** * Expert: The default cache implementation, storing all values in memory. * A WeakHashMap is used for storage. @@ -70,6 +54,7 @@ caches.put(Double.TYPE, new Cache(this)); caches.put(DocTermsIndex.class, new Cache(this)); caches.put(DocTerms.class, new Cache(this)); + caches.put(DocTermOrds.class, new Cache(this)); } public synchronized void purgeAllCaches() { @@ -393,6 +378,11 @@ return (DocTerms)caches.get(DocTerms.class).get(reader, new Entry(field, creator)); } + @SuppressWarnings("unchecked") + public DocTermOrds getDocTermOrds(IndexReader reader, String field) throws IOException { + return (DocTermOrds) caches.get(DocTermOrds.class).get(reader, new Entry(field, new DocTermOrdsCreator(field, 0))); + } + private volatile PrintStream infoStream; public void setInfoStream(PrintStream stream) { Index: lucene/src/java/org/apache/lucene/search/FieldCache.java =================================================================== --- lucene/src/java/org/apache/lucene/search/FieldCache.java (revision 1068526) +++ lucene/src/java/org/apache/lucene/search/FieldCache.java (revision ) @@ -17,6 +17,7 @@ * limitations under the License. */ +import org.apache.lucene.index.DocTermOrds; import org.apache.lucene.index.IndexReader; import org.apache.lucene.index.TermsEnum; import org.apache.lucene.search.cache.EntryCreator; @@ -654,6 +655,18 @@ throws IOException; /** + * Checks the internal cache for an appropriate entry, and if none is found, reads the term values + * in field and returns a {@link DocTermOrds} instance, providing a method to retrieve + * the term (as a BytesRef) per document. + * + * @param reader Used to build a {@link DocTermOrds} instance + * @param field Which field contains the strings. + * @return a {@link DocTermOrds} instance + * @throws IOException If any error occurs. + */ + public DocTermOrds getDocTermOrds(IndexReader reader, String field) throws IOException; + + /** * EXPERT: A unique Identifier/Description for each item in the FieldCache. * Can be useful for logging/debugging. * @lucene.experimental Index: lucene/src/java/org/apache/lucene/search/cache/DocTermOrdsCreator.java =================================================================== --- lucene/src/java/org/apache/lucene/search/cache/DocTermOrdsCreator.java (revision ) +++ lucene/src/java/org/apache/lucene/search/cache/DocTermOrdsCreator.java (revision ) @@ -0,0 +1,51 @@ +package org.apache.lucene.search.cache; + +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You under the Apache License, Version 2.0 + * (the "License"); you may not use this file except in compliance with + * the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +import org.apache.lucene.index.DocTermOrds; +import org.apache.lucene.index.IndexReader; + +import java.io.IOException; + +/** + * Creates {@link DocTermOrds} instances. + */ +public class DocTermOrdsCreator extends EntryCreatorWithOptions { + + private final String field; + + public DocTermOrdsCreator(String field, int flag) { + super(flag); + this.field = field; + } + + @Override + public DocTermOrds create(IndexReader reader) throws IOException { + return new DocTermOrds(reader, field); + } + + @Override + public DocTermOrds validate(DocTermOrds entry, IndexReader reader) throws IOException { + return entry; + } + + @Override + public EntryKey getCacheKey() { + return new SimpleEntryKey(DocTermOrdsCreator.class, field); + } +}