Index: src/main/java/org/apache/jackrabbit/core/query/lucene/MultiIndex.java =================================================================== --- src/main/java/org/apache/jackrabbit/core/query/lucene/MultiIndex.java (revision 746932) +++ src/main/java/org/apache/jackrabbit/core/query/lucene/MultiIndex.java (working copy) @@ -277,8 +277,9 @@ // init volatile index resetVolatileIndex(); - // set index format version - CachingMultiIndexReader reader = getIndexReader(); + // set index format version and at the same time + // initialize hierarchy cache if requested. + CachingMultiIndexReader reader = getIndexReader(handler.isInitializeHierarchyCache()); try { version = IndexFormatVersion.getVersion(reader); } finally { @@ -680,6 +681,21 @@ * @throws IOException if an error occurs constructing the IndexReader. */ public CachingMultiIndexReader getIndexReader() throws IOException { + return getIndexReader(false); + } + + /** + * Returns an read-only IndexReader that spans alls indexes of this + * MultiIndex. + * + * @param initCache when set true the hierarchy cache is + * completely initialized before this call returns. + * Otherwise the cache is initialized in a background + * thread. + * @return an IndexReader. + * @throws IOException if an error occurs constructing the IndexReader. + */ + public CachingMultiIndexReader getIndexReader(boolean initCache) throws IOException { synchronized (updateMonitor) { if (multiReader != null) { multiReader.acquire(); @@ -701,7 +717,7 @@ for (int i = 0; i < indexes.size(); i++) { PersistentIndex pIdx = (PersistentIndex) indexes.get(i); if (indexNames.contains(pIdx.getName())) { - readerList.add(pIdx.getReadOnlyIndexReader()); + readerList.add(pIdx.getReadOnlyIndexReader(initCache)); } } readerList.add(volatileIndex.getReadOnlyIndexReader()); Index: src/main/java/org/apache/jackrabbit/core/query/lucene/SearchIndex.java =================================================================== --- src/main/java/org/apache/jackrabbit/core/query/lucene/SearchIndex.java (revision 746946) +++ src/main/java/org/apache/jackrabbit/core/query/lucene/SearchIndex.java (working copy) @@ -434,6 +434,12 @@ private SortComparatorSource scs; /** + * Flag that indicates whether the hierarchy cache should be initialized + * immediately on startup. + */ + private boolean initializeHierarchyCache = true; + + /** * Indicates if this SearchIndex is closed and cannot be used * anymore. */ @@ -2060,6 +2066,25 @@ this.termInfosIndexDivisor = termInfosIndexDivisor; } + /** + * @return true if the hierarchy cache should be initialized + * immediately on startup. + */ + public boolean isInitializeHierarchyCache() { + return initializeHierarchyCache; + } + + /** + * Whether the hierarchy cache should be initialized immediately on + * startup. + * + * @param initializeHierarchyCache true if the cache should be + * initialized immediately. + */ + public void setInitializeHierarchyCache(boolean initializeHierarchyCache) { + this.initializeHierarchyCache = initializeHierarchyCache; + } + //----------------------------< internal >---------------------------------- /**