maven-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From csta...@apache.org
Subject svn commit: r1372380 [1/2] - in /maven/indexer/trunk/indexer-core/src: main/java/org/apache/maven/index/ main/java/org/apache/maven/index/cli/ main/java/org/apache/maven/index/context/ main/java/org/apache/maven/index/incremental/ main/java/org/apache/...
Date Mon, 13 Aug 2012 12:09:14 GMT
Author: cstamas
Date: Mon Aug 13 12:09:13 2012
New Revision: 1372380

URL: http://svn.apache.org/viewvc?rev=1372380&view=rev
Log:
Getting rid completely of locking and warming features.

As Lucene is bumped to 3.6.x, there is no more need to
introduce locking around contexts and warming up....

Build passes just fine (with Nexus too), but the changes as is
here introduces API incompatibilities (most notable IndexingContext
iface)

Added:
    maven/indexer/trunk/indexer-core/src/main/java/org/apache/maven/index/context/NexusIndexMultiReader.java
    maven/indexer/trunk/indexer-core/src/main/java/org/apache/maven/index/context/NexusIndexMultiSearcher.java
      - copied, changed from r1372378, maven/indexer/trunk/indexer-core/src/main/java/org/apache/maven/index/context/NexusIndexWriter.java
    maven/indexer/trunk/indexer-core/src/main/java/org/apache/maven/index/context/NexusIndexSearcherFactory.java
      - copied, changed from r1372378, maven/indexer/trunk/indexer-core/src/main/java/org/apache/maven/index/context/NexusIndexWriter.java
Modified:
    maven/indexer/trunk/indexer-core/src/main/java/org/apache/maven/index/DefaultIndexerEngine.java
    maven/indexer/trunk/indexer-core/src/main/java/org/apache/maven/index/DefaultIteratorResultSet.java
    maven/indexer/trunk/indexer-core/src/main/java/org/apache/maven/index/DefaultScannerListener.java
    maven/indexer/trunk/indexer-core/src/main/java/org/apache/maven/index/DefaultSearchEngine.java
    maven/indexer/trunk/indexer-core/src/main/java/org/apache/maven/index/cli/NexusIndexerCli.java
    maven/indexer/trunk/indexer-core/src/main/java/org/apache/maven/index/context/DefaultIndexingContext.java
    maven/indexer/trunk/indexer-core/src/main/java/org/apache/maven/index/context/IndexingContext.java
    maven/indexer/trunk/indexer-core/src/main/java/org/apache/maven/index/context/MergedIndexingContext.java
    maven/indexer/trunk/indexer-core/src/main/java/org/apache/maven/index/context/NexusIndexSearcher.java
    maven/indexer/trunk/indexer-core/src/main/java/org/apache/maven/index/context/NexusIndexWriter.java
    maven/indexer/trunk/indexer-core/src/main/java/org/apache/maven/index/incremental/DefaultIncrementalHandler.java
    maven/indexer/trunk/indexer-core/src/main/java/org/apache/maven/index/packer/DefaultIndexPacker.java
    maven/indexer/trunk/indexer-core/src/main/java/org/apache/maven/index/updater/IndexDataWriter.java
    maven/indexer/trunk/indexer-core/src/test/java/org/apache/maven/index/AbstractIndexCreatorHelper.java
    maven/indexer/trunk/indexer-core/src/test/java/org/apache/maven/index/AbstractRepoNexusIndexerTest.java
    maven/indexer/trunk/indexer-core/src/test/java/org/apache/maven/index/ConcurrentUseTest.java
    maven/indexer/trunk/indexer-core/src/test/java/org/apache/maven/index/ConcurrentUseWithMergedContextTest.java
    maven/indexer/trunk/indexer-core/src/test/java/org/apache/maven/index/FSDirectoryDeleteTest.java
    maven/indexer/trunk/indexer-core/src/test/java/org/apache/maven/index/Index20081108RegressionTest.java
    maven/indexer/trunk/indexer-core/src/test/java/org/apache/maven/index/Nexus737NexusIndexerTest.java
    maven/indexer/trunk/indexer-core/src/test/java/org/apache/maven/index/updater/IndexDataTest.java

Modified: maven/indexer/trunk/indexer-core/src/main/java/org/apache/maven/index/DefaultIndexerEngine.java
URL: http://svn.apache.org/viewvc/maven/indexer/trunk/indexer-core/src/main/java/org/apache/maven/index/DefaultIndexerEngine.java?rev=1372380&r1=1372379&r2=1372380&view=diff
==============================================================================
--- maven/indexer/trunk/indexer-core/src/main/java/org/apache/maven/index/DefaultIndexerEngine.java (original)
+++ maven/indexer/trunk/indexer-core/src/main/java/org/apache/maven/index/DefaultIndexerEngine.java Mon Aug 13 12:09:13 2012
@@ -153,19 +153,27 @@ public class DefaultIndexerEngine
     {
         try
         {
-            IndexSearcher indexSearcher = context.getIndexSearcher();
-
-            TopDocs result =
-                indexSearcher.search( new TermQuery( new Term( ArtifactInfo.UINFO, ac.getArtifactInfo().getUinfo() ) ),
-                    2 );
+            final IndexSearcher indexSearcher = context.acquireIndexSearcher();
+            try
+            {
+                TopDocs result =
+                    indexSearcher.search(
+                        new TermQuery( new Term( ArtifactInfo.UINFO, ac.getArtifactInfo().getUinfo() ) ), 2 );
 
-            if ( result.totalHits == 1 )
+                if ( result.totalHits == 1 )
+                {
+                    return indexSearcher.doc( result.scoreDocs[0].doc );
+                }
+            }
+            finally
             {
-                return indexSearcher.doc( result.scoreDocs[0].doc );
+                context.releaseIndexSearcher( indexSearcher );
             }
         }
         catch ( IOException e )
         {
+            // huh?
+            throw new IllegalStateException( e );
         }
         return null;
     }

Modified: maven/indexer/trunk/indexer-core/src/main/java/org/apache/maven/index/DefaultIteratorResultSet.java
URL: http://svn.apache.org/viewvc/maven/indexer/trunk/indexer-core/src/main/java/org/apache/maven/index/DefaultIteratorResultSet.java?rev=1372380&r1=1372379&r2=1372380&view=diff
==============================================================================
--- maven/indexer/trunk/indexer-core/src/main/java/org/apache/maven/index/DefaultIteratorResultSet.java (original)
+++ maven/indexer/trunk/indexer-core/src/main/java/org/apache/maven/index/DefaultIteratorResultSet.java Mon Aug 13 12:09:13 2012
@@ -40,6 +40,7 @@ import org.apache.lucene.search.highligh
 import org.apache.lucene.search.highlight.TextFragment;
 import org.apache.maven.index.context.IndexUtils;
 import org.apache.maven.index.context.IndexingContext;
+import org.apache.maven.index.context.NexusIndexMultiSearcher;
 import org.apache.maven.index.creator.JarFileContentsIndexCreator;
 
 /**
@@ -52,7 +53,7 @@ public class DefaultIteratorResultSet
 {
     private final IteratorSearchRequest searchRequest;
 
-    private final IndexSearcher indexSearcher;
+    private final NexusIndexMultiSearcher indexSearcher;
 
     private final List<IndexingContext> contexts;
 
@@ -78,7 +79,8 @@ public class DefaultIteratorResultSet
 
     private ArtifactInfo ai;
 
-    protected DefaultIteratorResultSet( final IteratorSearchRequest request, final IndexSearcher indexSearcher,
+    protected DefaultIteratorResultSet( final IteratorSearchRequest request,
+                                        final NexusIndexMultiSearcher indexSearcher,
                                         final List<IndexingContext> contexts, final TopDocs hits )
         throws IOException
     {
@@ -91,10 +93,13 @@ public class DefaultIteratorResultSet
         {
             int maxDoc = 0;
             this.starts = new int[contexts.size() + 1]; // build starts array
+            // this is good to do as we have NexusIndexMultiSearcher passed in contructor, so it is already open, hence
+            // #acquire() already invoked on underlying NexusIndexMultiReader
+            final List<IndexSearcher> acquiredSearchers = indexSearcher.getNexusIndexMultiReader().getAcquiredSearchers();
             for ( int i = 0; i < contexts.size(); i++ )
             {
                 starts[i] = maxDoc;
-                maxDoc += contexts.get( i ).getIndexReader().maxDoc(); // compute maxDocs
+                maxDoc += acquiredSearchers.get( i ).maxDoc(); // compute maxDocs
             }
             starts[contexts.size()] = maxDoc;
         }
@@ -263,9 +268,13 @@ public class DefaultIteratorResultSet
             return;
         }
 
-        for ( IndexingContext ctx : contexts )
+        try
+        {
+            indexSearcher.release();
+        }
+        catch ( IOException e )
         {
-            ctx.unlock();
+            throw new IllegalStateException( e );
         }
 
         this.cleanedUp = true;
@@ -349,7 +358,7 @@ public class DefaultIteratorResultSet
             text = text.replace( '/', '.' ).replaceAll( "^\\.", "" ).replaceAll( "\n\\.", "\n" );
         }
 
-        Query rewrittenQuery = hr.getQuery().rewrite( context.getIndexReader() );
+        Query rewrittenQuery = hr.getQuery().rewrite( indexSearcher.getIndexReader() );
 
         CachingTokenFilter tokenStream =
             new CachingTokenFilter( context.getAnalyzer().tokenStream( field.getKey(), new StringReader( text ) ) );

Modified: maven/indexer/trunk/indexer-core/src/main/java/org/apache/maven/index/DefaultScannerListener.java
URL: http://svn.apache.org/viewvc/maven/indexer/trunk/indexer-core/src/main/java/org/apache/maven/index/DefaultScannerListener.java?rev=1372380&r1=1372379&r2=1372380&view=diff
==============================================================================
--- maven/indexer/trunk/indexer-core/src/main/java/org/apache/maven/index/DefaultScannerListener.java (original)
+++ maven/indexer/trunk/indexer-core/src/main/java/org/apache/maven/index/DefaultScannerListener.java Mon Aug 13 12:09:13 2012
@@ -29,6 +29,7 @@ import org.apache.lucene.document.Docume
 import org.apache.lucene.index.CorruptIndexException;
 import org.apache.lucene.index.IndexReader;
 import org.apache.lucene.index.Term;
+import org.apache.lucene.search.IndexSearcher;
 import org.apache.lucene.search.TermQuery;
 import org.apache.lucene.search.TopScoreDocCollector;
 import org.apache.maven.index.context.IndexingContext;
@@ -207,29 +208,37 @@ class DefaultScannerListener
     private void initialize( IndexingContext ctx )
         throws IOException, CorruptIndexException
     {
-        IndexReader r = ctx.getIndexReader();
-
-        for ( int i = 0; i < r.maxDoc(); i++ )
+        final IndexSearcher indexSearcher = ctx.acquireIndexSearcher();
+        try
         {
-            if ( !r.isDeleted( i ) )
+            final IndexReader r = indexSearcher.getIndexReader();
+
+            for ( int i = 0; i < r.maxDoc(); i++ )
             {
-                Document d = r.document( i );
+                if ( !r.isDeleted( i ) )
+                {
+                    Document d = r.document( i );
 
-                String uinfo = d.get( ArtifactInfo.UINFO );
+                    String uinfo = d.get( ArtifactInfo.UINFO );
 
-                if ( uinfo != null )
-                {
-                    uinfos.add( uinfo );
+                    if ( uinfo != null )
+                    {
+                        uinfos.add( uinfo );
 
-                    // add all existing groupIds to the lists, as they will
-                    // not be "discovered" and would be missing from the new list..
-                    String groupId = uinfo.substring( 0, uinfo.indexOf( '|' ) );
-                    int n = groupId.indexOf( '.' );
-                    groups.add( n == -1 ? groupId : groupId.substring( 0, n ) );
-                    allGroups.add( groupId );
+                        // add all existing groupIds to the lists, as they will
+                        // not be "discovered" and would be missing from the new list..
+                        String groupId = uinfo.substring( 0, uinfo.indexOf( '|' ) );
+                        int n = groupId.indexOf( '.' );
+                        groups.add( n == -1 ? groupId : groupId.substring( 0, n ) );
+                        allGroups.add( groupId );
+                    }
                 }
             }
         }
+        finally
+        {
+            ctx.releaseIndexSearcher( indexSearcher );
+        }
     }
 
     private void removeDeletedArtifacts( IndexingContext context, ScanningResult result, String contextPath )
@@ -237,51 +246,59 @@ class DefaultScannerListener
     {
         int deleted = 0;
 
-        for ( String uinfo : uinfos )
+        final IndexSearcher indexSearcher = context.acquireIndexSearcher();
+        try
         {
-            TopScoreDocCollector collector = TopScoreDocCollector.create( 1, false );
-
-            context.getIndexSearcher().search( new TermQuery( new Term( ArtifactInfo.UINFO, uinfo ) ), collector );
-
-            if ( collector.getTotalHits() > 0 )
+            for ( String uinfo : uinfos )
             {
-                String[] ra = ArtifactInfo.FS_PATTERN.split( uinfo );
+                TopScoreDocCollector collector = TopScoreDocCollector.create( 1, false );
 
-                ArtifactInfo ai = new ArtifactInfo();
+                indexSearcher.search( new TermQuery( new Term( ArtifactInfo.UINFO, uinfo ) ), collector );
 
-                ai.repository = context.getRepositoryId();
+                if ( collector.getTotalHits() > 0 )
+                {
+                    String[] ra = ArtifactInfo.FS_PATTERN.split( uinfo );
 
-                ai.groupId = ra[0];
+                    ArtifactInfo ai = new ArtifactInfo();
 
-                ai.artifactId = ra[1];
+                    ai.repository = context.getRepositoryId();
 
-                ai.version = ra[2];
+                    ai.groupId = ra[0];
 
-                if ( ra.length > 3 )
-                {
-                    ai.classifier = ArtifactInfo.renvl( ra[3] );
-                }
+                    ai.artifactId = ra[1];
 
-                if ( ra.length > 4 )
-                {
-                    ai.packaging = ArtifactInfo.renvl( ra[4] );
-                }
+                    ai.version = ra[2];
 
-                // minimal ArtifactContext for removal
-                ArtifactContext ac = new ArtifactContext( null, null, null, ai, ai.calculateGav() );
+                    if ( ra.length > 3 )
+                    {
+                        ai.classifier = ArtifactInfo.renvl( ra[3] );
+                    }
 
-                for ( int i = 0; i < collector.getTotalHits(); i++ )
-                {
-                    if ( contextPath == null
-                        || context.getGavCalculator().gavToPath( ac.getGav() ).startsWith( contextPath ) )
+                    if ( ra.length > 4 )
                     {
-                        indexerEngine.remove( context, ac );
+                        ai.packaging = ArtifactInfo.renvl( ra[4] );
                     }
 
-                    deleted++;
+                    // minimal ArtifactContext for removal
+                    ArtifactContext ac = new ArtifactContext( null, null, null, ai, ai.calculateGav() );
+
+                    for ( int i = 0; i < collector.getTotalHits(); i++ )
+                    {
+                        if ( contextPath == null
+                            || context.getGavCalculator().gavToPath( ac.getGav() ).startsWith( contextPath ) )
+                        {
+                            indexerEngine.remove( context, ac );
+                        }
+
+                        deleted++;
+                    }
                 }
             }
         }
+        finally
+        {
+            context.releaseIndexSearcher( indexSearcher );
+        }
 
         if ( deleted > 0 )
         {

Modified: maven/indexer/trunk/indexer-core/src/main/java/org/apache/maven/index/DefaultSearchEngine.java
URL: http://svn.apache.org/viewvc/maven/indexer/trunk/indexer-core/src/main/java/org/apache/maven/index/DefaultSearchEngine.java?rev=1372380&r1=1372379&r2=1372380&view=diff
==============================================================================
--- maven/indexer/trunk/indexer-core/src/main/java/org/apache/maven/index/DefaultSearchEngine.java (original)
+++ maven/indexer/trunk/indexer-core/src/main/java/org/apache/maven/index/DefaultSearchEngine.java Mon Aug 13 12:09:13 2012
@@ -31,15 +31,14 @@ import java.util.TreeMap;
 import java.util.TreeSet;
 
 import org.apache.lucene.document.Document;
-import org.apache.lucene.index.IndexReader;
-import org.apache.lucene.index.MultiReader;
 import org.apache.lucene.search.IndexSearcher;
 import org.apache.lucene.search.Query;
 import org.apache.lucene.search.ScoreDoc;
 import org.apache.lucene.search.TopScoreDocCollector;
 import org.apache.maven.index.context.IndexUtils;
 import org.apache.maven.index.context.IndexingContext;
-import org.apache.maven.index.context.NexusIndexSearcher;
+import org.apache.maven.index.context.NexusIndexMultiReader;
+import org.apache.maven.index.context.NexusIndexMultiSearcher;
 import org.codehaus.plexus.component.annotations.Component;
 import org.codehaus.plexus.logging.AbstractLogEnabled;
 
@@ -90,25 +89,9 @@ public class DefaultSearchEngine
     {
         List<IndexingContext> contexts = getParticipatingContexts( indexingContexts, ignoreContext );
 
-        try
-        {
-            final TreeSet<ArtifactInfo> result = new TreeSet<ArtifactInfo>( request.getArtifactInfoComparator() );
-
-            for ( IndexingContext ctx : contexts )
-            {
-                ctx.lock();
-            }
-
-            return new FlatSearchResponse( request.getQuery(), searchFlat( request, result, contexts,
-                request.getQuery() ), result );
-        }
-        finally
-        {
-            for ( IndexingContext ctx : contexts )
-            {
-                ctx.unlock();
-            }
-        }
+        final TreeSet<ArtifactInfo> result = new TreeSet<ArtifactInfo>( request.getArtifactInfoComparator() );
+        return new FlatSearchResponse( request.getQuery(), searchFlat( request, result, contexts, request.getQuery() ),
+            result );
     }
 
     // ==
@@ -133,27 +116,11 @@ public class DefaultSearchEngine
     {
         List<IndexingContext> contexts = getParticipatingContexts( indexingContexts, ignoreContext );
 
-        try
-        {
-            final TreeMap<String, ArtifactInfoGroup> result =
-                new TreeMap<String, ArtifactInfoGroup>( request.getGroupKeyComparator() );
+        final TreeMap<String, ArtifactInfoGroup> result =
+            new TreeMap<String, ArtifactInfoGroup>( request.getGroupKeyComparator() );
 
-            for ( IndexingContext ctx : contexts )
-            {
-                ctx.lock();
-            }
-
-            return new GroupedSearchResponse( request.getQuery(), searchGrouped( request, result,
-                request.getGrouping(), contexts, request.getQuery() ), result );
-
-        }
-        finally
-        {
-            for ( IndexingContext ctx : contexts )
-            {
-                ctx.unlock();
-            }
-        }
+        return new GroupedSearchResponse( request.getQuery(), searchGrouped( request, result, request.getGrouping(),
+            contexts, request.getQuery() ), result );
     }
 
     // ===
@@ -163,41 +130,48 @@ public class DefaultSearchEngine
         throws IOException
     {
         int hitCount = 0;
-
         for ( IndexingContext context : participatingContexts )
         {
-            final TopScoreDocCollector collector = doSearchWithCeiling( req, context.getIndexSearcher(), query );
-
-            if ( collector.getTotalHits() == 0 )
+            final IndexSearcher indexSearcher = context.acquireIndexSearcher();
+            try
             {
-                // context has no hits, just continue to next one
-                continue;
-            }
-
-            ScoreDoc[] scoreDocs = collector.topDocs().scoreDocs;
+                final TopScoreDocCollector collector = doSearchWithCeiling( req, indexSearcher, query );
 
-            // uhm btw hitCount contains dups
+                if ( collector.getTotalHits() == 0 )
+                {
+                    // context has no hits, just continue to next one
+                    continue;
+                }
 
-            hitCount += collector.getTotalHits();
+                ScoreDoc[] scoreDocs = collector.topDocs().scoreDocs;
 
-            int start = 0; // from == FlatSearchRequest.UNDEFINED ? 0 : from;
+                // uhm btw hitCount contains dups
 
-            // we have to pack the results as long: a) we have found aiCount ones b) we depleted hits
-            for ( int i = start; i < scoreDocs.length; i++ )
-            {
-                Document doc = context.getIndexSearcher().doc( scoreDocs[i].doc );
+                hitCount += collector.getTotalHits();
 
-                ArtifactInfo artifactInfo = IndexUtils.constructArtifactInfo( doc, context );
+                int start = 0; // from == FlatSearchRequest.UNDEFINED ? 0 : from;
 
-                if ( artifactInfo != null )
+                // we have to pack the results as long: a) we have found aiCount ones b) we depleted hits
+                for ( int i = start; i < scoreDocs.length; i++ )
                 {
-                    artifactInfo.repository = context.getRepositoryId();
+                    Document doc = indexSearcher.doc( scoreDocs[i].doc );
 
-                    artifactInfo.context = context.getId();
+                    ArtifactInfo artifactInfo = IndexUtils.constructArtifactInfo( doc, context );
 
-                    result.add( artifactInfo );
+                    if ( artifactInfo != null )
+                    {
+                        artifactInfo.repository = context.getRepositoryId();
+
+                        artifactInfo.context = context.getId();
+
+                        result.add( artifactInfo );
+                    }
                 }
             }
+            finally
+            {
+                context.releaseIndexSearcher( indexSearcher );
+            }
         }
 
         return hitCount;
@@ -211,34 +185,42 @@ public class DefaultSearchEngine
 
         for ( IndexingContext context : participatingContexts )
         {
-            final TopScoreDocCollector collector = doSearchWithCeiling( req, context.getIndexSearcher(), query );
-
-            if ( collector.getTotalHits() > 0 )
+            final IndexSearcher indexSearcher = context.acquireIndexSearcher();
+            try
             {
-                ScoreDoc[] scoreDocs = collector.topDocs().scoreDocs;
+                final TopScoreDocCollector collector = doSearchWithCeiling( req, indexSearcher, query );
 
-                hitCount += collector.getTotalHits();
-
-                for ( int i = 0; i < scoreDocs.length; i++ )
+                if ( collector.getTotalHits() > 0 )
                 {
-                    Document doc = context.getIndexSearcher().doc( scoreDocs[i].doc );
+                    ScoreDoc[] scoreDocs = collector.topDocs().scoreDocs;
 
-                    ArtifactInfo artifactInfo = IndexUtils.constructArtifactInfo( doc, context );
+                    hitCount += collector.getTotalHits();
 
-                    if ( artifactInfo != null )
+                    for ( int i = 0; i < scoreDocs.length; i++ )
                     {
-                        artifactInfo.repository = context.getRepositoryId();
+                        Document doc = indexSearcher.doc( scoreDocs[i].doc );
 
-                        artifactInfo.context = context.getId();
+                        ArtifactInfo artifactInfo = IndexUtils.constructArtifactInfo( doc, context );
 
-                        if ( !grouping.addArtifactInfo( result, artifactInfo ) )
+                        if ( artifactInfo != null )
                         {
-                            // fix the hitCount accordingly
-                            hitCount--;
+                            artifactInfo.repository = context.getRepositoryId();
+
+                            artifactInfo.context = context.getId();
+
+                            if ( !grouping.addArtifactInfo( result, artifactInfo ) )
+                            {
+                                // fix the hitCount accordingly
+                                hitCount--;
+                            }
                         }
                     }
                 }
             }
+            finally
+            {
+                context.releaseIndexSearcher( indexSearcher );
+            }
         }
 
         return hitCount;
@@ -265,42 +247,16 @@ public class DefaultSearchEngine
                                                         boolean ignoreContext )
         throws IOException
     {
-        try
-        {
-            List<IndexingContext> contexts = getParticipatingContexts( indexingContexts, ignoreContext );
-
-            IndexReader multiReader = getMergedIndexReader( indexingContexts, ignoreContext );
+        List<IndexingContext> contexts = getParticipatingContexts( indexingContexts, ignoreContext );
 
-            IndexSearcher indexSearcher = new NexusIndexSearcher( multiReader );
+        NexusIndexMultiReader multiReader = getMergedIndexReader( indexingContexts, ignoreContext );
 
-            TopScoreDocCollector hits = doSearchWithCeiling( request, indexSearcher, request.getQuery() );
+        NexusIndexMultiSearcher indexSearcher = new NexusIndexMultiSearcher( multiReader );
 
-            return new IteratorSearchResponse( request.getQuery(), hits.getTotalHits(), new DefaultIteratorResultSet(
-                request, indexSearcher, contexts, hits.topDocs() ) );
-        }
-        catch ( Throwable e )
-        {
-            // perform cleaup, otherwise DefaultIteratorResultSet will do it
-            for ( IndexingContext ctx : indexingContexts )
-            {
-                if ( ignoreContext || ctx.isSearchable() )
-                {
-                    ctx.unlock();
-                }
-            }
+        TopScoreDocCollector hits = doSearchWithCeiling( request, indexSearcher, request.getQuery() );
 
-            if ( e instanceof IOException )
-            {
-                throw (IOException) e;
-            }
-            else
-            {
-                // wrap it
-                IOException ex = new IOException( e.getMessage() );
-                ex.initCause( e );
-                throw ex;
-            }
-        }
+        return new IteratorSearchResponse( request.getQuery(), hits.getTotalHits(), new DefaultIteratorResultSet(
+            request, indexSearcher, contexts, hits.topDocs() ) );
     }
 
     // ==
@@ -383,48 +339,12 @@ public class DefaultSearchEngine
      * @return
      * @throws IOException
      */
-    protected IndexReader getMergedIndexReader( final Collection<IndexingContext> indexingContexts,
-                                                final boolean ignoreContext )
+    protected NexusIndexMultiReader getMergedIndexReader( final Collection<IndexingContext> indexingContexts,
+                                                          final boolean ignoreContext )
         throws IOException
     {
         final List<IndexingContext> contexts = getParticipatingContexts( indexingContexts, ignoreContext );
-
-        try
-        {
-            final ArrayList<IndexReader> contextsToSearch = new ArrayList<IndexReader>( contexts.size() );
-
-            for ( IndexingContext ctx : contexts )
-            {
-                ctx.lock();
-
-                contextsToSearch.add( ctx.getIndexReader() );
-            }
-
-            MultiReader multiReader =
-                new MultiReader( contextsToSearch.toArray( new IndexReader[contextsToSearch.size()] ) );
-
-            return multiReader;
-        }
-        catch ( Throwable e )
-        {
-            // perform cleaup, otherwise DefaultIteratorResultSet will do it
-            for ( IndexingContext ctx : contexts )
-            {
-                ctx.unlock();
-            }
-
-            if ( e instanceof IOException )
-            {
-                throw (IOException) e;
-            }
-            else
-            {
-                // wrap it
-                IOException ex = new IOException( e.getMessage() );
-                ex.initCause( e );
-                throw ex;
-            }
-        }
+        return new NexusIndexMultiReader( contexts );
     }
 
     protected int getTopDocsCollectorHitNum( final AbstractSearchRequest request, final int ceiling )

Modified: maven/indexer/trunk/indexer-core/src/main/java/org/apache/maven/index/cli/NexusIndexerCli.java
URL: http://svn.apache.org/viewvc/maven/indexer/trunk/indexer-core/src/main/java/org/apache/maven/index/cli/NexusIndexerCli.java?rev=1372380&r1=1372379&r2=1372380&view=diff
==============================================================================
--- maven/indexer/trunk/indexer-core/src/main/java/org/apache/maven/index/cli/NexusIndexerCli.java (original)
+++ maven/indexer/trunk/indexer-core/src/main/java/org/apache/maven/index/cli/NexusIndexerCli.java Mon Aug 13 12:09:13 2012
@@ -19,6 +19,15 @@ package org.apache.maven.index.cli;
  * under the License.
  */
 
+import java.io.BufferedInputStream;
+import java.io.File;
+import java.io.FileInputStream;
+import java.io.IOException;
+import java.lang.reflect.Proxy;
+import java.util.ArrayList;
+import java.util.Arrays;
+import java.util.List;
+
 import org.apache.commons.cli.CommandLine;
 import org.apache.commons.cli.HelpFormatter;
 import org.apache.commons.cli.OptionBuilder;
@@ -30,7 +39,6 @@ import org.apache.maven.index.ArtifactIn
 import org.apache.maven.index.ArtifactScanningListener;
 import org.apache.maven.index.NexusIndexer;
 import org.apache.maven.index.ScanningResult;
-import org.apache.maven.index.context.DefaultIndexingContext;
 import org.apache.maven.index.context.IndexCreator;
 import org.apache.maven.index.context.IndexingContext;
 import org.apache.maven.index.context.UnsupportedExistingLuceneIndexException;
@@ -46,15 +54,6 @@ import org.codehaus.plexus.logging.Logge
 import org.codehaus.plexus.tools.cli.AbstractCli;
 import org.codehaus.plexus.util.IOUtil;
 
-import java.io.BufferedInputStream;
-import java.io.File;
-import java.io.FileInputStream;
-import java.io.IOException;
-import java.lang.reflect.Proxy;
-import java.util.ArrayList;
-import java.util.Arrays;
-import java.util.List;
-
 /**
  * A command line tool that can be used to index local Maven repository.
  * <p/>
@@ -71,7 +70,8 @@ import java.util.List;
  * the incremental updates.
  * <p/>
  * The indexer types could be one of default, min or full. You can also specify list of comma-separated custom index
- * creators. An index creator should be a regular Plexus component, see {@link org.apache.maven.index.creator.MinimalArtifactInfoIndexCreator} and
+ * creators. An index creator should be a regular Plexus component, see
+ * {@link org.apache.maven.index.creator.MinimalArtifactInfoIndexCreator} and
  * {@link org.apache.maven.index.creator.JarFileContentsIndexCreator}.
  */
 public class NexusIndexerCli
@@ -183,37 +183,34 @@ public class NexusIndexerCli
         this.options = options;
 
         options.addOption( OptionBuilder.withLongOpt( "index" ).hasArg() //
-                               .withDescription( "Path to the index folder." ).create( INDEX ) );
+        .withDescription( "Path to the index folder." ).create( INDEX ) );
 
         options.addOption( OptionBuilder.withLongOpt( "destination" ).hasArg() //
-                               .withDescription( "Target folder." ).create( TARGET_DIR ) );
+        .withDescription( "Target folder." ).create( TARGET_DIR ) );
 
         options.addOption( OptionBuilder.withLongOpt( "repository" ).hasArg() //
-                               .withDescription( "Path to the Maven repository." ).create( REPO ) );
+        .withDescription( "Path to the Maven repository." ).create( REPO ) );
 
         options.addOption( OptionBuilder.withLongOpt( "name" ).hasArg() //
-                               .withDescription( "Repository name." ).create( NAME ) );
+        .withDescription( "Repository name." ).create( NAME ) );
 
         options.addOption( OptionBuilder.withLongOpt( "chunks" ) //
-                               .withDescription( "Create incremental chunks." ).create( CREATE_INCREMENTAL_CHUNKS ) );
+        .withDescription( "Create incremental chunks." ).create( CREATE_INCREMENTAL_CHUNKS ) );
 
         options.addOption( OptionBuilder.withLongOpt( "keep" ).hasArg().withDescription(
             "Number of incremental chunks to keep." ).create( INCREMENTAL_CHUNK_KEEP_COUNT ) );
 
         options.addOption( OptionBuilder.withLongOpt( "checksums" ) //
-                               .withDescription( "Create checksums for all files (sha1, md5)." ).create(
-                CREATE_FILE_CHECKSUMS ) );
+        .withDescription( "Create checksums for all files (sha1, md5)." ).create( CREATE_FILE_CHECKSUMS ) );
 
         options.addOption( OptionBuilder.withLongOpt( "type" ).hasArg() //
-                               .withDescription(
-                                   "Indexer type (default, min, full or coma separated list of custom types)." ).create(
-                TYPE ) );
+        .withDescription( "Indexer type (default, min, full or coma separated list of custom types)." ).create( TYPE ) );
 
         options.addOption( OptionBuilder.withLongOpt( "legacy" ) //
-                               .withDescription( "Build legacy .zip index file" ).create( LEGACY ) );
+        .withDescription( "Build legacy .zip index file" ).create( LEGACY ) );
 
         options.addOption( OptionBuilder.withLongOpt( "unpack" ) //
-                               .withDescription( "Unpack an index file" ).create( UNPACK ) );
+        .withDescription( "Unpack an index file" ).create( UNPACK ) );
 
         return options;
     }
@@ -269,7 +266,7 @@ public class NexusIndexerCli
             status = 1;
 
             displayHelp( "Use either unpack (\"" + UNPACK + "\") or index (\"" + INDEX + "\" and \"" + REPO
-                             + "\") options, but none has been found!" );
+                + "\") options, but none has been found!" );
         }
     }
 
@@ -306,8 +303,9 @@ public class NexusIndexerCli
 
         boolean quiet = cli.hasOption( QUIET );
 
-        Integer chunkCount = cli.hasOption( INCREMENTAL_CHUNK_KEEP_COUNT ) ? Integer.parseInt(
-            cli.getOptionValue( INCREMENTAL_CHUNK_KEEP_COUNT ) ) : null;
+        Integer chunkCount =
+            cli.hasOption( INCREMENTAL_CHUNK_KEEP_COUNT ) ? Integer.parseInt( cli.getOptionValue( INCREMENTAL_CHUNK_KEEP_COUNT ) )
+                : null;
 
         if ( !quiet )
         {
@@ -342,19 +340,17 @@ public class NexusIndexerCli
         }
 
         NexusIndexer indexer = plexus.lookup( NexusIndexer.class );
-        // this is a CLI/batch invocation, don't coggle it with threads
-        DefaultIndexingContext.BLOCKING_COMMIT = true;
 
-            long tstart = System.currentTimeMillis();
+        long tstart = System.currentTimeMillis();
 
         IndexingContext context = indexer.addIndexingContext( //
-                                                  repositoryName, // context id
-                                                  repositoryName, // repository id
-                                                  repositoryFolder, // repository folder
-                                                  indexFolder, // index folder
-                                                  null, // repositoryUrl
-                                                  null, // index update url
-                                                  indexers );
+            repositoryName, // context id
+            repositoryName, // repository id
+            repositoryFolder, // repository folder
+            indexFolder, // index folder
+            null, // repositoryUrl
+            null, // index update url
+            indexers );
 
         try
         {
@@ -424,17 +420,14 @@ public class NexusIndexerCli
         try
         {
             is = new BufferedInputStream( new FileInputStream( indexArchive ) );
-            DefaultIndexUpdater.unpackIndexData( is, directory,
-                                                 (IndexingContext) Proxy.newProxyInstance( getClass().getClassLoader(),
-                                                                                           new Class[]{
-                                                                                               IndexingContext.class },
-                                                                                           new PartialImplementation()
-                                                                                           {
-                                                                                               public List<IndexCreator> getIndexCreators()
-                                                                                               {
-                                                                                                   return indexers;
-                                                                                               }
-                                                                                           } )
+            DefaultIndexUpdater.unpackIndexData( is, directory, (IndexingContext) Proxy.newProxyInstance(
+                getClass().getClassLoader(), new Class[] { IndexingContext.class }, new PartialImplementation()
+                {
+                    public List<IndexCreator> getIndexCreators()
+                    {
+                        return indexers;
+                    }
+                } )
 
             );
         }
@@ -526,7 +519,7 @@ public class NexusIndexerCli
         Runtime r = Runtime.getRuntime();
 
         System.err.printf( "Final memory: %dM/%dM\n", //
-                           ( r.totalMemory() - r.freeMemory() ) / MB, r.totalMemory() / MB );
+            ( r.totalMemory() - r.freeMemory() ) / MB, r.totalMemory() / MB );
     }
 
     /**
@@ -571,7 +564,7 @@ public class NexusIndexerCli
             if ( !quiet && debug && "maven-plugin".equals( ai.packaging ) )
             {
                 System.err.printf( "Plugin: %s:%s:%s - %s %s\n", //
-                                   ai.groupId, ai.artifactId, ai.version, ai.prefix, "" + ai.goals );
+                    ai.groupId, ai.artifactId, ai.version, ai.prefix, "" + ai.goals );
             }
 
             if ( !quiet && ( debug || ( t - ts ) > 2000L ) )

Modified: maven/indexer/trunk/indexer-core/src/main/java/org/apache/maven/index/context/DefaultIndexingContext.java
URL: http://svn.apache.org/viewvc/maven/indexer/trunk/indexer-core/src/main/java/org/apache/maven/index/context/DefaultIndexingContext.java?rev=1372380&r1=1372379&r2=1372380&view=diff
==============================================================================
--- maven/indexer/trunk/indexer-core/src/main/java/org/apache/maven/index/context/DefaultIndexingContext.java (original)
+++ maven/indexer/trunk/indexer-core/src/main/java/org/apache/maven/index/context/DefaultIndexingContext.java Mon Aug 13 12:09:13 2012
@@ -38,9 +38,10 @@ import org.apache.lucene.index.CorruptIn
 import org.apache.lucene.index.IndexFileNameFilter;
 import org.apache.lucene.index.IndexReader;
 import org.apache.lucene.index.IndexWriter;
-import org.apache.lucene.index.SerialMergeScheduler;
+import org.apache.lucene.index.IndexWriterConfig;
 import org.apache.lucene.index.Term;
 import org.apache.lucene.search.IndexSearcher;
+import org.apache.lucene.search.SearcherManager;
 import org.apache.lucene.search.TermQuery;
 import org.apache.lucene.search.TopDocs;
 import org.apache.lucene.search.TopScoreDocCollector;
@@ -91,15 +92,10 @@ public class DefaultIndexingContext
 
     private String indexUpdateUrl;
 
-    private IndexReader indexReader;
-
-    private NexusIndexSearcher indexSearcher;
-
-    // disabled for now, see getReadOnlyIndexSearcher() method for explanation
-    // private NexusIndexSearcher readOnlyIndexSearcher;
-
     private NexusIndexWriter indexWriter;
 
+    private SearcherManager searcherManager;
+
     private Date timestamp;
 
     private List<? extends IndexCreator> indexCreators;
@@ -113,8 +109,6 @@ public class DefaultIndexingContext
 
     private ReadWriteLock indexMaintenanceLock = new ReentrantReadWriteLock();
 
-    private Thread bottleWarmerThread;
-
     private DefaultIndexingContext( String id,
                                     String repositoryId,
                                     File repository, //
@@ -135,10 +129,10 @@ public class DefaultIndexingContext
 
         this.indexUpdateUrl = indexUpdateUrl;
 
-        this.indexReader = null;
-
         this.indexWriter = null;
 
+        this.searcherManager = null;
+
         this.indexCreators = indexCreators;
 
         this.indexDirectory = indexDirectory;
@@ -155,8 +149,6 @@ public class DefaultIndexingContext
         this.gavCalculator = new M2GavCalculator();
 
         prepareIndex( reclaimIndex );
-
-        installBottleWarmer();
     }
 
     public DefaultIndexingContext( String id, String repositoryId, File repository, File indexDirectoryFile,
@@ -179,28 +171,28 @@ public class DefaultIndexingContext
 
         if ( indexDirectory instanceof FSDirectory )
         {
-            this.indexDirectoryFile = ( (FSDirectory) indexDirectory ).getFile();
+            this.indexDirectoryFile = ( (FSDirectory) indexDirectory ).getDirectory();
         }
     }
 
     public void lock()
     {
-        indexMaintenanceLock.readLock().lock();
+        //indexMaintenanceLock.readLock().lock();
     }
 
     public void unlock()
     {
-        indexMaintenanceLock.readLock().unlock();
+        //indexMaintenanceLock.readLock().unlock();
     }
 
     public void lockExclusively()
     {
-        indexMaintenanceLock.writeLock().lock();
+        //indexMaintenanceLock.writeLock().lock();
     }
 
     public void unlockExclusively()
     {
-        indexMaintenanceLock.writeLock().unlock();
+        //indexMaintenanceLock.writeLock().unlock();
     }
 
     public Directory getIndexDirectory()
@@ -287,48 +279,56 @@ public class DefaultIndexingContext
         }
 
         // check for descriptor if this is not a "virgin" index
-        if ( getIndexReader().numDocs() > 0 )
+        if ( getSize() > 0 )
         {
-            TopScoreDocCollector collector = TopScoreDocCollector.create( 1, false );
-
-            getIndexSearcher().search( new TermQuery( DESCRIPTOR_TERM ), collector );
-
-            if ( collector.getTotalHits() == 0 )
+            final TopScoreDocCollector collector = TopScoreDocCollector.create( 1, false );
+            final IndexSearcher indexSearcher = acquireIndexSearcher();
+            try
             {
-                throw new UnsupportedExistingLuceneIndexException( "The existing index has no NexusIndexer descriptor" );
-            }
+                indexSearcher.search( new TermQuery( DESCRIPTOR_TERM ), collector );
 
-            if ( collector.getTotalHits() > 1 )
-            {
-                // eh? this is buggy index it seems, just iron it out then
-                storeDescriptor();
-                return;
-            }
-            else
-            {
-                // good, we have one descriptor as should
-                Document descriptor = getIndexSearcher().doc( collector.topDocs().scoreDocs[0].doc );
-                String[] h = StringUtils.split( descriptor.get( FLD_IDXINFO ), ArtifactInfo.FS );
-                // String version = h[0];
-                String repoId = h[1];
-
-                // // compare version
-                // if ( !VERSION.equals( version ) )
-                // {
-                // throw new UnsupportedExistingLuceneIndexException(
-                // "The existing index has version [" + version + "] and not [" + VERSION + "] version!" );
-                // }
+                if ( collector.getTotalHits() == 0 )
+                {
+                    throw new UnsupportedExistingLuceneIndexException(
+                        "The existing index has no NexusIndexer descriptor" );
+                }
 
-                if ( getRepositoryId() == null )
+                if ( collector.getTotalHits() > 1 )
                 {
-                    repositoryId = repoId;
+                    // eh? this is buggy index it seems, just iron it out then
+                    storeDescriptor();
+                    return;
                 }
-                else if ( !getRepositoryId().equals( repoId ) )
+                else
                 {
-                    throw new UnsupportedExistingLuceneIndexException( "The existing index is for repository " //
-                        + "[" + repoId + "] and not for repository [" + getRepositoryId() + "]" );
+                    // good, we have one descriptor as should
+                    Document descriptor = indexSearcher.doc( collector.topDocs().scoreDocs[0].doc );
+                    String[] h = StringUtils.split( descriptor.get( FLD_IDXINFO ), ArtifactInfo.FS );
+                    // String version = h[0];
+                    String repoId = h[1];
+
+                    // // compare version
+                    // if ( !VERSION.equals( version ) )
+                    // {
+                    // throw new UnsupportedExistingLuceneIndexException(
+                    // "The existing index has version [" + version + "] and not [" + VERSION + "] version!" );
+                    // }
+
+                    if ( getRepositoryId() == null )
+                    {
+                        repositoryId = repoId;
+                    }
+                    else if ( !getRepositoryId().equals( repoId ) )
+                    {
+                        throw new UnsupportedExistingLuceneIndexException( "The existing index is for repository " //
+                            + "[" + repoId + "] and not for repository [" + getRepositoryId() + "]" );
+                    }
                 }
             }
+            finally
+            {
+                releaseIndexSearcher( indexSearcher );
+            }
         }
     }
 
@@ -431,7 +431,15 @@ public class DefaultIndexingContext
     public int getSize()
         throws IOException
     {
-        return getIndexReader().numDocs();
+        final IndexSearcher is = acquireIndexSearcher();
+        try
+        {
+            return is.getIndexReader().numDocs();
+        }
+        finally
+        {
+            releaseIndexSearcher( is );
+        }
     }
 
     public String getRepositoryId()
@@ -476,91 +484,17 @@ public class DefaultIndexingContext
 
             indexWriter = null;
         }
-        // IndexSearcher (close only, since we did supply this.indexReader explicitly)
-        if ( indexSearcher != null )
-        {
-            indexSearcher.close();
-
-            indexSearcher = null;
-        }
-        // IndexReader
-        if ( indexReader != null )
+        if ( searcherManager != null )
         {
-            indexReader.close();
+            searcherManager.close();
 
-            indexReader = null;
+            searcherManager = null;
         }
 
-        // IndexWriter open
-        final boolean create = !IndexReader.indexExists( indexDirectory );
-
-        indexWriter = new NexusIndexWriter( getIndexDirectory(), new NexusAnalyzer(), create );
-
-        indexWriter.setRAMBufferSizeMB( 2 );
-
-        indexWriter.setMergeScheduler( new SerialMergeScheduler() );
-
-        indexWriter.commit(); // LUCENE-2386
-
-        openAndWarmupReaders();
-    }
-
-    protected void openAndWarmupReaders()
-        throws IOException
-    {
-        if ( indexReader != null && indexReader.isCurrent() )
-        {
-            return;
-        }
-
-        // IndexReader open
-        IndexReader newIndexReader = IndexReader.open( indexDirectory, true );
-
-        // IndexSearcher open, but with new reader
-        NexusIndexSearcher newIndexSearcher = new NexusIndexSearcher( this, newIndexReader );
-
-        // warm up
-        warmUp( newIndexSearcher );
-
-        lockExclusively();
-
-        try
-        {
-            // IndexSearcher (close only, since we did supply this.indexReader explicitly)
-            if ( indexSearcher != null )
-            {
-                indexSearcher.close();
-            }
-            // IndexReader
-            if ( indexReader != null )
-            {
-                indexReader.close();
-            }
-
-            indexReader = newIndexReader;
-
-            indexSearcher = newIndexSearcher;
-        }
-        finally
-        {
-            unlockExclusively();
-        }
-    }
-
-    protected void warmUp( NexusIndexSearcher searcher )
-        throws IOException
-    {
-        try
-        {
-            // TODO: figure this out better and non blocking
-            searcher.search( new TermQuery( new Term( "g", "org.apache" ) ), 1000 );
-        }
-        catch ( IOException e )
-        {
-            close( false );
-
-            throw e;
-        }
+        final IndexWriterConfig config = NexusIndexWriter.defaultConfig();
+        this.indexWriter = new NexusIndexWriter( getIndexDirectory(), config );
+        this.indexWriter.commit(); // LUCENE-2386
+        this.searcherManager = new SearcherManager( indexWriter, false, new NexusIndexSearcherFactory( this ) );
     }
 
     public IndexWriter getIndexWriter()
@@ -578,95 +512,31 @@ public class DefaultIndexingContext
         }
     }
 
-    public IndexReader getIndexReader()
+    public IndexSearcher acquireIndexSearcher()
         throws IOException
     {
-        lock();
-
-        try
-        {
-            return indexReader;
-        }
-        finally
-        {
-            unlock();
-        }
+        searcherManager.maybeRefresh();
+        return searcherManager.acquire();
     }
 
-    public IndexSearcher getIndexSearcher()
+    public void releaseIndexSearcher( final IndexSearcher is )
         throws IOException
     {
-        lock();
-
-        try
+        if ( is == null )
         {
-            return indexSearcher;
-        }
-        finally
-        {
-            unlock();
+            return;
         }
+        searcherManager.release( is );
     }
 
     public void commit()
         throws IOException
     {
-        // TODO: detect is writer "dirty"?
-        if ( true )
-        {
-            if ( BLOCKING_COMMIT )
-            {
-                lockExclusively();
-            }
-            else
-            {
-                lock();
-            }
-
-            try
-            {
-                doCommit( BLOCKING_COMMIT );
-            }
-            finally
-            {
-                if ( BLOCKING_COMMIT )
-                {
-                    unlockExclusively();
-                }
-                else
-                {
-                    unlock();
-                }
-            }
-        }
-    }
+        lock();
 
-    protected void doCommit( boolean blocking )
-        throws IOException
-    {
         try
         {
-            // TODO: is this needed? Why not put the commit() call into synchronized
-            // since all callers of doCommit() aside of commit() already possess exclusive lock
-            synchronized ( this )
-            {
-                getIndexWriter().commit();
-            }
-
-            // TODO: define some treshold or requirement
-            // for reopening readers (is expensive)
-            // For example: by inserting 1 record among 1M, do we really want to reopen?
-            if ( true )
-            {
-                if ( blocking )
-                {
-                    openAndWarmupReaders();
-                }
-                else
-                {
-                    flagNeedsReopen();
-                }
-            }
+            getIndexWriter().commit();
         }
         catch ( CorruptIndexException e )
         {
@@ -680,45 +550,40 @@ public class DefaultIndexingContext
 
             throw e;
         }
+        finally
+        {
+            unlock();
+        }
     }
 
     public void rollback()
         throws IOException
     {
-        // detect is writer "dirty"?
-        if ( true )
-        {
-            lock();
+        lock();
 
+        try
+        {
             try
             {
-                IndexWriter w = getIndexWriter();
-
-                try
-                {
-                    synchronized ( this )
-                    {
-                        w.rollback();
-                    }
-                }
-                catch ( CorruptIndexException e )
-                {
-                    close( false );
-
-                    throw e;
-                }
-                catch ( IOException e )
-                {
-                    close( false );
+                getIndexWriter().rollback();
+            }
+            catch ( CorruptIndexException e )
+            {
+                close( false );
 
-                    throw e;
-                }
+                throw e;
             }
-            finally
+            catch ( IOException e )
             {
-                unlock();
+                close( false );
+
+                throw e;
             }
         }
+        finally
+        {
+            unlock();
+        }
     }
 
     public void optimize()
@@ -734,7 +599,7 @@ public class DefaultIndexingContext
             {
                 w.optimize();
 
-                doCommit( true );
+                commit();
             }
             catch ( CorruptIndexException e )
             {
@@ -859,12 +724,11 @@ public class DefaultIndexingContext
     {
         lockExclusively();
 
+        IndexSearcher s = acquireIndexSearcher();
         try
         {
             IndexWriter w = getIndexWriter();
 
-            IndexSearcher s = getIndexSearcher();
-
             IndexReader directoryReader = IndexReader.open( directory, true );
 
             TopScoreDocCollector collector = null;
@@ -919,8 +783,7 @@ public class DefaultIndexingContext
             finally
             {
                 directoryReader.close();
-
-                doCommit( true );
+                commit();
             }
 
             rebuildGroups();
@@ -941,6 +804,7 @@ public class DefaultIndexingContext
         }
         finally
         {
+            releaseIndexSearcher( s );
             unlockExclusively();
         }
     }
@@ -948,23 +812,17 @@ public class DefaultIndexingContext
     private void closeReaders()
         throws CorruptIndexException, IOException
     {
-        if ( indexWriter != null )
-        {
-            indexWriter.close();
-
-            indexWriter = null;
-        }
-        if ( indexSearcher != null )
+        if ( searcherManager != null )
         {
-            indexSearcher.close();
+            searcherManager.close();
 
-            indexSearcher = null;
+            searcherManager = null;
         }
-        if ( indexReader != null )
+        if ( indexWriter != null )
         {
-            indexReader.close();
+            indexWriter.close();
 
-            indexReader = null;
+            indexWriter = null;
         }
     }
 
@@ -985,9 +843,10 @@ public class DefaultIndexingContext
     {
         lockExclusively();
 
+        final IndexSearcher is = acquireIndexSearcher();
         try
         {
-            IndexReader r = getIndexReader();
+            final IndexReader r = is.getIndexReader();
 
             Set<String> rootGroups = new LinkedHashSet<String>();
             Set<String> allGroups = new LinkedHashSet<String>();
@@ -1020,6 +879,7 @@ public class DefaultIndexingContext
         }
         finally
         {
+            releaseIndexSearcher( is );
             unlockExclusively();
         }
     }
@@ -1047,8 +907,7 @@ public class DefaultIndexingContext
         try
         {
             setGroups( groups, ArtifactInfo.ALL_GROUPS, ArtifactInfo.ALL_GROUPS_VALUE, ArtifactInfo.ALL_GROUPS_LIST );
-
-            doCommit( true );
+            commit();
         }
         finally
         {
@@ -1079,8 +938,7 @@ public class DefaultIndexingContext
         try
         {
             setGroups( groups, ArtifactInfo.ROOT_GROUPS, ArtifactInfo.ROOT_GROUPS_VALUE, ArtifactInfo.ROOT_GROUPS_LIST );
-
-            doCommit( true );
+            commit();
         }
         finally
         {
@@ -1091,27 +949,34 @@ public class DefaultIndexingContext
     protected Set<String> getGroups( String field, String filedValue, String listField )
         throws IOException, CorruptIndexException
     {
-        TopScoreDocCollector collector = TopScoreDocCollector.create( 1, false );
-
-        getIndexSearcher().search( new TermQuery( new Term( field, filedValue ) ), collector );
+        final TopScoreDocCollector collector = TopScoreDocCollector.create( 1, false );
+        final IndexSearcher indexSearcher = acquireIndexSearcher();
+        try
+        {
+            indexSearcher.search( new TermQuery( new Term( field, filedValue ) ), collector );
 
-        TopDocs topDocs = collector.topDocs();
+            TopDocs topDocs = collector.topDocs();
 
-        Set<String> groups = new LinkedHashSet<String>( Math.max( 10, topDocs.totalHits ) );
+            Set<String> groups = new LinkedHashSet<String>( Math.max( 10, topDocs.totalHits ) );
 
-        if ( topDocs.totalHits > 0 )
-        {
-            Document doc = getIndexSearcher().doc( topDocs.scoreDocs[0].doc );
+            if ( topDocs.totalHits > 0 )
+            {
+                Document doc = indexSearcher.doc( topDocs.scoreDocs[0].doc );
 
-            String groupList = doc.get( listField );
+                String groupList = doc.get( listField );
 
-            if ( groupList != null )
-            {
-                groups.addAll( Arrays.asList( groupList.split( "\\|" ) ) );
+                if ( groupList != null )
+                {
+                    groups.addAll( Arrays.asList( groupList.split( "\\|" ) ) );
+                }
             }
-        }
 
-        return groups;
+            return groups;
+        }
+        finally
+        {
+            releaseIndexSearcher( indexSearcher );
+        }
     }
 
     protected void setGroups( Collection<String> groups, String groupField, String groupFieldValue,
@@ -1143,69 +1008,4 @@ public class DefaultIndexingContext
     {
         return id + " : " + timestamp;
     }
-
-    // ==
-
-    private volatile boolean needsReaderReopen = false;
-
-    protected void flagNeedsReopen()
-    {
-        needsReaderReopen = true;
-    }
-
-    protected void unflagNeedsReopen()
-    {
-        needsReaderReopen = false;
-    }
-
-    protected boolean isReopenNeeded()
-    {
-        return needsReaderReopen;
-    }
-
-    protected void installBottleWarmer()
-    {
-        if ( BLOCKING_COMMIT )
-        {
-            return;
-        }
-
-        Runnable bottleWarmer = new Runnable()
-        {
-            public void run()
-            {
-                // die off when context is closed
-                while ( indexDirectory != null )
-                {
-                    try
-                    {
-                        if ( isReopenNeeded() )
-                        {
-                            openAndWarmupReaders();
-
-                            unflagNeedsReopen();
-                        }
-
-                        Thread.sleep( 1000 );
-                    }
-                    catch ( Exception e )
-                    {
-                        e.printStackTrace();
-                    }
-                }
-            }
-        };
-
-        bottleWarmerThread = new Thread( bottleWarmer, "Index-BottleWarmer-" + id );
-        bottleWarmerThread.setDaemon( true );
-        bottleWarmerThread.start();
-    }
-
-    /**
-     * A flag useful for tests, to make this IndexingContext implementation blocking. If this flag is true, context will
-     * block the commit() calls and will return from it when Lucene commit done AND all the readers are reopened and are
-     * current. TODO: this is currently inherently unsafe (is not final), and is meant to be used in Unit tests only!
-     * Think something and tie this knot properly.
-     */
-    public static boolean BLOCKING_COMMIT = false;
 }

Modified: maven/indexer/trunk/indexer-core/src/main/java/org/apache/maven/index/context/IndexingContext.java
URL: http://svn.apache.org/viewvc/maven/indexer/trunk/indexer-core/src/main/java/org/apache/maven/index/context/IndexingContext.java?rev=1372380&r1=1372379&r2=1372380&view=diff
==============================================================================
--- maven/indexer/trunk/indexer-core/src/main/java/org/apache/maven/index/context/IndexingContext.java (original)
+++ maven/indexer/trunk/indexer-core/src/main/java/org/apache/maven/index/context/IndexingContext.java Mon Aug 13 12:09:13 2012
@@ -27,7 +27,6 @@ import java.util.List;
 import java.util.Set;
 
 import org.apache.lucene.analysis.Analyzer;
-import org.apache.lucene.index.IndexReader;
 import org.apache.lucene.index.IndexWriter;
 import org.apache.lucene.search.IndexSearcher;
 import org.apache.lucene.store.Directory;
@@ -167,21 +166,20 @@ public interface IndexingContext
         throws IOException;
 
     /**
-     * Returns the Lucene IndexReader of this context.
+     * Acquires a fresh instance of {@link IndexSearcher}. You have to release the received instance with
+     * {@link #releaseIndexSearcher(IndexSearcher)}.
      * 
-     * @return reader
-     * @throws IOException
+     * @return
      */
-    IndexReader getIndexReader()
+    IndexSearcher acquireIndexSearcher()
         throws IOException;
 
     /**
-     * Returns the Lucene IndexSearcher of this context.
+     * Releases the {@link IndexSearcher} instance.
      * 
-     * @return searcher
-     * @throws IOException
+     * @param s
      */
-    IndexSearcher getIndexSearcher()
+    void releaseIndexSearcher( IndexSearcher s )
         throws IOException;
 
     /**

Modified: maven/indexer/trunk/indexer-core/src/main/java/org/apache/maven/index/context/MergedIndexingContext.java
URL: http://svn.apache.org/viewvc/maven/indexer/trunk/indexer-core/src/main/java/org/apache/maven/index/context/MergedIndexingContext.java?rev=1372380&r1=1372379&r2=1372380&view=diff
==============================================================================
--- maven/indexer/trunk/indexer-core/src/main/java/org/apache/maven/index/context/MergedIndexingContext.java (original)
+++ maven/indexer/trunk/indexer-core/src/main/java/org/apache/maven/index/context/MergedIndexingContext.java Mon Aug 13 12:09:13 2012
@@ -29,9 +29,7 @@ import java.util.List;
 import java.util.Set;
 
 import org.apache.lucene.analysis.Analyzer;
-import org.apache.lucene.index.IndexReader;
 import org.apache.lucene.index.IndexWriter;
-import org.apache.lucene.index.MultiReader;
 import org.apache.lucene.search.IndexSearcher;
 import org.apache.lucene.store.Directory;
 import org.apache.lucene.store.FSDirectory;
@@ -93,7 +91,7 @@ public class MergedIndexingContext
 
         if ( indexDirectory instanceof FSDirectory )
         {
-            this.directoryFile = ( (FSDirectory) indexDirectory ).getFile();
+            this.directoryFile = ( (FSDirectory) indexDirectory ).getDirectory();
         }
     }
 
@@ -188,28 +186,27 @@ public class MergedIndexingContext
         return size;
     }
 
-    public IndexReader getIndexReader()
+    public IndexSearcher acquireIndexSearcher()
         throws IOException
     {
-        Collection<IndexingContext> members = getMembers();
-
-        ArrayList<IndexReader> contextsToSearch = new ArrayList<IndexReader>( members.size() );
-
-        for ( IndexingContext ctx : members )
-        {
-            contextsToSearch.add( ctx.getIndexReader() );
-        }
-
-        MultiReader multiReader =
-            new MultiReader( contextsToSearch.toArray( new IndexReader[contextsToSearch.size()] ) );
-
-        return multiReader;
+        final NexusIndexMultiReader mr = new NexusIndexMultiReader( getMembers() );
+        return new NexusIndexMultiSearcher( mr );
     }
 
-    public IndexSearcher getIndexSearcher()
+    public void releaseIndexSearcher( IndexSearcher indexSearcher )
         throws IOException
     {
-        return new NexusIndexSearcher( getIndexReader() );
+        if ( indexSearcher instanceof NexusIndexMultiSearcher )
+        {
+            ( (NexusIndexMultiSearcher) indexSearcher ).release();
+        }
+        else
+        {
+            throw new IllegalArgumentException( String.format(
+                "Illegal argument to merged idexing context: it emits class %s but and cannot release class %s!",
+                NexusIndexMultiSearcher.class.getName(), indexSearcher.getClass().getName() ) );
+        }
+
     }
 
     public IndexWriter getIndexWriter()

Added: maven/indexer/trunk/indexer-core/src/main/java/org/apache/maven/index/context/NexusIndexMultiReader.java
URL: http://svn.apache.org/viewvc/maven/indexer/trunk/indexer-core/src/main/java/org/apache/maven/index/context/NexusIndexMultiReader.java?rev=1372380&view=auto
==============================================================================
--- maven/indexer/trunk/indexer-core/src/main/java/org/apache/maven/index/context/NexusIndexMultiReader.java (added)
+++ maven/indexer/trunk/indexer-core/src/main/java/org/apache/maven/index/context/NexusIndexMultiReader.java Mon Aug 13 12:09:13 2012
@@ -0,0 +1,95 @@
+package org.apache.maven.index.context;
+
+/*
+ * 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 java.io.IOException;
+import java.util.ArrayList;
+import java.util.Collection;
+import java.util.Collections;
+import java.util.Iterator;
+import java.util.List;
+
+import org.apache.lucene.index.IndexReader;
+import org.apache.lucene.index.MultiReader;
+import org.apache.lucene.search.IndexSearcher;
+
+public class NexusIndexMultiReader
+{
+    private final List<IndexingContext> contexts;
+
+    private List<IndexSearcher> searchers;
+
+    public NexusIndexMultiReader( final Collection<IndexingContext> contexts )
+    {
+        this.contexts = Collections.unmodifiableList( new ArrayList<IndexingContext>( contexts ) );
+    }
+
+    public synchronized IndexReader acquire()
+        throws IOException
+    {
+        if ( searchers != null )
+        {
+            release();
+            throw new IllegalStateException( "acquire() called 2nd time without release() in between!" );
+        }
+        this.searchers = new ArrayList<IndexSearcher>();
+        final ArrayList<IndexReader> contextReaders = new ArrayList<IndexReader>( contexts.size() );
+        for ( IndexingContext ctx : contexts )
+        {
+            final IndexSearcher indexSearcher = ctx.acquireIndexSearcher();
+            searchers.add( indexSearcher );
+            contextReaders.add( indexSearcher.getIndexReader() );
+        }
+        return new MultiReader( contextReaders.toArray( new IndexReader[contextReaders.size()] ) );
+    }
+
+    public synchronized void release()
+        throws IOException
+    {
+        if ( searchers != null )
+        {
+            final Iterator<IndexingContext> ic = contexts.iterator();
+            final Iterator<IndexSearcher> is = searchers.iterator();
+
+            while ( ic.hasNext() && is.hasNext() )
+            {
+                ic.next().releaseIndexSearcher( is.next() );
+            }
+
+            if ( ic.hasNext() || is.hasNext() )
+            {
+                throw new IllegalStateException( "Context and IndexSearcher mismatch: " + contexts + " vs " + searchers );
+            }
+        }
+
+        searchers = null;
+    }
+
+    /**
+     * Watch out with this method, as it's use depends on (if you control it at all) was {@link #acquire()} method
+     * invoked at all or not. Returns {@code null} if not, otherwise the list of acquired searchers. Not thread safe.
+     * 
+     * @return
+     */
+    public synchronized List<IndexSearcher> getAcquiredSearchers()
+    {
+        return searchers;
+    }
+}

Copied: maven/indexer/trunk/indexer-core/src/main/java/org/apache/maven/index/context/NexusIndexMultiSearcher.java (from r1372378, maven/indexer/trunk/indexer-core/src/main/java/org/apache/maven/index/context/NexusIndexWriter.java)
URL: http://svn.apache.org/viewvc/maven/indexer/trunk/indexer-core/src/main/java/org/apache/maven/index/context/NexusIndexMultiSearcher.java?p2=maven/indexer/trunk/indexer-core/src/main/java/org/apache/maven/index/context/NexusIndexMultiSearcher.java&p1=maven/indexer/trunk/indexer-core/src/main/java/org/apache/maven/index/context/NexusIndexWriter.java&r1=1372378&r2=1372380&rev=1372380&view=diff
==============================================================================
--- maven/indexer/trunk/indexer-core/src/main/java/org/apache/maven/index/context/NexusIndexWriter.java (original)
+++ maven/indexer/trunk/indexer-core/src/main/java/org/apache/maven/index/context/NexusIndexMultiSearcher.java Mon Aug 13 12:09:13 2012
@@ -21,25 +21,26 @@ package org.apache.maven.index.context;
 
 import java.io.IOException;
 
-import org.apache.lucene.analysis.Analyzer;
-import org.apache.lucene.index.CorruptIndexException;
-import org.apache.lucene.index.IndexWriter;
-import org.apache.lucene.store.Directory;
-import org.apache.lucene.store.LockObtainFailedException;
-
-/**
- * An extension of <a
- * href="http://lucene.apache.org/java/2_4_0/api/core/org/apache/lucene/index/IndexWriter.html">Lucene IndexWriter</a>
- * to allow to track if writer is closed
- */
-public class NexusIndexWriter
-    extends IndexWriter
+public class NexusIndexMultiSearcher
+    extends NexusIndexSearcher
 {
-    public NexusIndexWriter( final Directory directory, final Analyzer analyzer, boolean create )
-        throws CorruptIndexException, LockObtainFailedException, IOException
+    private final NexusIndexMultiReader nexusIndexMultiReader;
+
+    public NexusIndexMultiSearcher( final NexusIndexMultiReader reader )
+        throws IOException
     {
-        super( directory, analyzer, create, MaxFieldLength.LIMITED );
+        super( reader.acquire() );
+        this.nexusIndexMultiReader = reader;
+    }
 
-        // setSimilarity( new NexusSimilarity() );
+    public void release()
+        throws IOException
+    {
+        nexusIndexMultiReader.release();
+    }
+
+    public NexusIndexMultiReader getNexusIndexMultiReader()
+    {
+        return nexusIndexMultiReader;
     }
 }

Modified: maven/indexer/trunk/indexer-core/src/main/java/org/apache/maven/index/context/NexusIndexSearcher.java
URL: http://svn.apache.org/viewvc/maven/indexer/trunk/indexer-core/src/main/java/org/apache/maven/index/context/NexusIndexSearcher.java?rev=1372380&r1=1372379&r2=1372380&view=diff
==============================================================================
--- maven/indexer/trunk/indexer-core/src/main/java/org/apache/maven/index/context/NexusIndexSearcher.java (original)
+++ maven/indexer/trunk/indexer-core/src/main/java/org/apache/maven/index/context/NexusIndexSearcher.java Mon Aug 13 12:09:13 2012
@@ -35,12 +35,6 @@ public class NexusIndexSearcher
 {
     private final IndexingContext indexingContext;
 
-    public NexusIndexSearcher( final IndexingContext indexingContext )
-        throws IOException
-    {
-        this( indexingContext, indexingContext.getIndexReader() );
-    }
-
     public NexusIndexSearcher( final IndexReader reader )
         throws IOException
     {

Copied: maven/indexer/trunk/indexer-core/src/main/java/org/apache/maven/index/context/NexusIndexSearcherFactory.java (from r1372378, maven/indexer/trunk/indexer-core/src/main/java/org/apache/maven/index/context/NexusIndexWriter.java)
URL: http://svn.apache.org/viewvc/maven/indexer/trunk/indexer-core/src/main/java/org/apache/maven/index/context/NexusIndexSearcherFactory.java?p2=maven/indexer/trunk/indexer-core/src/main/java/org/apache/maven/index/context/NexusIndexSearcherFactory.java&p1=maven/indexer/trunk/indexer-core/src/main/java/org/apache/maven/index/context/NexusIndexWriter.java&r1=1372378&r2=1372380&rev=1372380&view=diff
==============================================================================
--- maven/indexer/trunk/indexer-core/src/main/java/org/apache/maven/index/context/NexusIndexWriter.java (original)
+++ maven/indexer/trunk/indexer-core/src/main/java/org/apache/maven/index/context/NexusIndexSearcherFactory.java Mon Aug 13 12:09:13 2012
@@ -21,25 +21,23 @@ package org.apache.maven.index.context;
 
 import java.io.IOException;
 
-import org.apache.lucene.analysis.Analyzer;
-import org.apache.lucene.index.CorruptIndexException;
-import org.apache.lucene.index.IndexWriter;
-import org.apache.lucene.store.Directory;
-import org.apache.lucene.store.LockObtainFailedException;
+import org.apache.lucene.index.IndexReader;
+import org.apache.lucene.search.IndexSearcher;
+import org.apache.lucene.search.SearcherFactory;
 
-/**
- * An extension of <a
- * href="http://lucene.apache.org/java/2_4_0/api/core/org/apache/lucene/index/IndexWriter.html">Lucene IndexWriter</a>
- * to allow to track if writer is closed
- */
-public class NexusIndexWriter
-    extends IndexWriter
+public class NexusIndexSearcherFactory
+    extends SearcherFactory
 {
-    public NexusIndexWriter( final Directory directory, final Analyzer analyzer, boolean create )
-        throws CorruptIndexException, LockObtainFailedException, IOException
+    private final IndexingContext context;
+
+    public NexusIndexSearcherFactory( final IndexingContext context )
     {
-        super( directory, analyzer, create, MaxFieldLength.LIMITED );
+        this.context = context;
+    }
 
-        // setSimilarity( new NexusSimilarity() );
+    public IndexSearcher newSearcher( final IndexReader reader )
+        throws IOException
+    {
+        return new NexusIndexSearcher( context, reader );
     }
 }

Modified: maven/indexer/trunk/indexer-core/src/main/java/org/apache/maven/index/context/NexusIndexWriter.java
URL: http://svn.apache.org/viewvc/maven/indexer/trunk/indexer-core/src/main/java/org/apache/maven/index/context/NexusIndexWriter.java?rev=1372380&r1=1372379&r2=1372380&view=diff
==============================================================================
--- maven/indexer/trunk/indexer-core/src/main/java/org/apache/maven/index/context/NexusIndexWriter.java (original)
+++ maven/indexer/trunk/indexer-core/src/main/java/org/apache/maven/index/context/NexusIndexWriter.java Mon Aug 13 12:09:13 2012
@@ -24,8 +24,11 @@ import java.io.IOException;
 import org.apache.lucene.analysis.Analyzer;
 import org.apache.lucene.index.CorruptIndexException;
 import org.apache.lucene.index.IndexWriter;
+import org.apache.lucene.index.IndexWriterConfig;
+import org.apache.lucene.index.SerialMergeScheduler;
 import org.apache.lucene.store.Directory;
 import org.apache.lucene.store.LockObtainFailedException;
+import org.apache.lucene.util.Version;
 
 /**
  * An extension of <a
@@ -35,6 +38,7 @@ import org.apache.lucene.store.LockObtai
 public class NexusIndexWriter
     extends IndexWriter
 {
+    @Deprecated
     public NexusIndexWriter( final Directory directory, final Analyzer analyzer, boolean create )
         throws CorruptIndexException, LockObtainFailedException, IOException
     {
@@ -42,4 +46,21 @@ public class NexusIndexWriter
 
         // setSimilarity( new NexusSimilarity() );
     }
+
+    public NexusIndexWriter( final Directory directory, final IndexWriterConfig config )
+        throws CorruptIndexException, LockObtainFailedException, IOException
+    {
+        super( directory, config );
+    }
+
+    // ==
+
+    public static IndexWriterConfig defaultConfig()
+    {
+        final IndexWriterConfig config = new IndexWriterConfig( Version.LUCENE_36, new NexusAnalyzer() );
+        // default open mode is CreateOrAppend which suits us
+        config.setRAMBufferSizeMB( 2.0 ); // old default
+        config.setMergeScheduler( new SerialMergeScheduler() ); // merging serially
+        return config;
+    }
 }

Modified: maven/indexer/trunk/indexer-core/src/main/java/org/apache/maven/index/incremental/DefaultIncrementalHandler.java
URL: http://svn.apache.org/viewvc/maven/indexer/trunk/indexer-core/src/main/java/org/apache/maven/index/incremental/DefaultIncrementalHandler.java?rev=1372380&r1=1372379&r2=1372380&view=diff
==============================================================================
--- maven/indexer/trunk/indexer-core/src/main/java/org/apache/maven/index/incremental/DefaultIncrementalHandler.java (original)
+++ maven/indexer/trunk/indexer-core/src/main/java/org/apache/maven/index/incremental/DefaultIncrementalHandler.java Mon Aug 13 12:09:13 2012
@@ -19,16 +19,6 @@ package org.apache.maven.index.increment
  * under the License.
  */
 
-import org.apache.lucene.document.Document;
-import org.apache.lucene.index.IndexReader;
-import org.apache.maven.index.ArtifactInfo;
-import org.apache.maven.index.context.IndexingContext;
-import org.apache.maven.index.packer.IndexPackingRequest;
-import org.apache.maven.index.updater.IndexUpdateRequest;
-import org.codehaus.plexus.component.annotations.Component;
-import org.codehaus.plexus.logging.AbstractLogEnabled;
-import org.codehaus.plexus.util.StringUtils;
-
 import java.io.File;
 import java.io.FilenameFilter;
 import java.io.IOException;
@@ -45,6 +35,17 @@ import java.util.Set;
 import java.util.TimeZone;
 import java.util.TreeMap;
 
+import org.apache.lucene.document.Document;
+import org.apache.lucene.index.IndexReader;
+import org.apache.lucene.search.IndexSearcher;
+import org.apache.maven.index.ArtifactInfo;
+import org.apache.maven.index.context.IndexingContext;
+import org.apache.maven.index.packer.IndexPackingRequest;
+import org.apache.maven.index.updater.IndexUpdateRequest;
+import org.codehaus.plexus.component.annotations.Component;
+import org.codehaus.plexus.logging.AbstractLogEnabled;
+import org.codehaus.plexus.util.StringUtils;
+
 @Component( role = IncrementalHandler.class )
 public class DefaultIncrementalHandler
     extends AbstractLogEnabled
@@ -144,32 +145,38 @@ public class DefaultIncrementalHandler
     private List<Integer> getIndexChunk( IndexPackingRequest request, Date timestamp )
         throws IOException
     {
-        List<Integer> chunk = new ArrayList<Integer>();
-
-        IndexReader r = request.getContext().getIndexReader();
-
-        for ( int i = 0; i < r.maxDoc(); i++ )
+        final List<Integer> chunk = new ArrayList<Integer>();
+        final IndexSearcher indexSearcher = request.getContext().acquireIndexSearcher();
+        try
         {
-            if ( !r.isDeleted( i ) )
+            final IndexReader r = indexSearcher.getIndexReader();
+            for ( int i = 0; i < r.maxDoc(); i++ )
             {
-                Document d = r.document( i );
-
-                String lastModified = d.get( ArtifactInfo.LAST_MODIFIED );
-
-                if ( lastModified != null )
+                if ( !r.isDeleted( i ) )
                 {
-                    Date t = new Date( Long.parseLong( lastModified ) );
+                    Document d = r.document( i );
+
+                    String lastModified = d.get( ArtifactInfo.LAST_MODIFIED );
 
-                    // Only add documents that were added after the last time we indexed
-                    if ( t.after( timestamp ) )
+                    if ( lastModified != null )
                     {
-                        chunk.add( i );
+                        Date t = new Date( Long.parseLong( lastModified ) );
+
+                        // Only add documents that were added after the last time we indexed
+                        if ( t.after( timestamp ) )
+                        {
+                            chunk.add( i );
+                        }
                     }
                 }
             }
-        }
 
-        return chunk;
+            return chunk;
+        }
+        finally
+        {
+            request.getContext().releaseIndexSearcher( indexSearcher );
+        }
     }
 
     private void updateProperties( Properties properties, IndexPackingRequest request )
@@ -226,8 +233,8 @@ public class DefaultIncrementalHandler
             {
                 String[] parts = name.split( "\\." );
 
-                if ( parts.length == 3 && parts[0].equals( IndexingContext.INDEX_FILE_PREFIX ) && parts[2].equals(
-                    "gz" ) )
+                if ( parts.length == 3 && parts[0].equals( IndexingContext.INDEX_FILE_PREFIX )
+                    && parts[2].equals( "gz" ) )
                 {
                     return true;
                 }
@@ -311,8 +318,8 @@ public class DefaultIncrementalHandler
                 String value = remoteProps.getProperty( sKey );
 
                 // If we have the current counter, or the next counter, we are good to go
-                if ( Integer.toString( currentLocalCounter ).equals( value ) || Integer.toString(
-                    currentLocalCounter + 1 ).equals( value ) )
+                if ( Integer.toString( currentLocalCounter ).equals( value )
+                    || Integer.toString( currentLocalCounter + 1 ).equals( value ) )
                 {
                     return true;
                 }



Mime
View raw message