archiva-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From och...@apache.org
Subject svn commit: r738801 - in /archiva/branches/archiva-nexus-indexer/archiva-modules/archiva-base/archiva-indexer/src: main/java/org/apache/archiva/indexer/search/ test/java/org/apache/archiva/indexer/search/
Date Thu, 29 Jan 2009 08:47:52 GMT
Author: oching
Date: Thu Jan 29 08:47:52 2009
New Revision: 738801

URL: http://svn.apache.org/viewvc?rev=738801&view=rev
Log:
[MRM-749]
o added more tests
o remove indexing contexts after search

Modified:
    archiva/branches/archiva-nexus-indexer/archiva-modules/archiva-base/archiva-indexer/src/main/java/org/apache/archiva/indexer/search/NexusRepositorySearch.java
    archiva/branches/archiva-nexus-indexer/archiva-modules/archiva-base/archiva-indexer/src/test/java/org/apache/archiva/indexer/search/NexusRepositorySearchTest.java

Modified: archiva/branches/archiva-nexus-indexer/archiva-modules/archiva-base/archiva-indexer/src/main/java/org/apache/archiva/indexer/search/NexusRepositorySearch.java
URL: http://svn.apache.org/viewvc/archiva/branches/archiva-nexus-indexer/archiva-modules/archiva-base/archiva-indexer/src/main/java/org/apache/archiva/indexer/search/NexusRepositorySearch.java?rev=738801&r1=738800&r2=738801&view=diff
==============================================================================
--- archiva/branches/archiva-nexus-indexer/archiva-modules/archiva-base/archiva-indexer/src/main/java/org/apache/archiva/indexer/search/NexusRepositorySearch.java
(original)
+++ archiva/branches/archiva-nexus-indexer/archiva-modules/archiva-base/archiva-indexer/src/main/java/org/apache/archiva/indexer/search/NexusRepositorySearch.java
Thu Jan 29 08:47:52 2009
@@ -86,11 +86,11 @@
             FlatSearchRequest request = new FlatSearchRequest( q );
             FlatSearchResponse response = indexer.searchFlat( request );
             
-            if( response == null )
+            if( response == null || response.getTotalHits() == 0 )
             {
                 return new SearchResults();
             }
-
+            
             return convertToSearchResults( response, limits );
         }
         catch ( IndexContextInInconsistentStateException e )
@@ -101,6 +101,24 @@
         {
             throw new RepositorySearchException( e );
         }
+        finally
+        {
+            Map<String, IndexingContext> indexingContexts = indexer.getIndexingContexts();
+            Set<String> keys = indexingContexts.keySet();
+            for( String key : keys )
+            {
+                try                
+                {   
+                    indexer.removeIndexingContext( indexingContexts.get( key ), false );
+                    log.debug( "Indexing context '" + key + "' removed from search." );
+                }
+                catch ( IOException e )
+                {
+                    log.warn( "IOException occurred while removing indexing content '" +
key  + "'." );
+                    continue;
+                }
+            }            
+        }
     }
     
     public SearchResults search( String principal, SearchFields searchFields, SearchResultLimits
limits )
@@ -143,14 +161,12 @@
                 }
             }
             catch ( UnsupportedExistingLuceneIndexException e )
-            {
-                // skip repository
+            {                
                 log.warn( "Error accessing index of repository '" + repo + "' : " + e.getMessage()
);
                 continue;
             }
             catch ( IOException e )
-            {
-                // skip repository
+            {                
                 log.warn( "IO error occured while accessing index of repository '" + repo
+ "' : " + e.getMessage() );
                 continue;
             }

Modified: archiva/branches/archiva-nexus-indexer/archiva-modules/archiva-base/archiva-indexer/src/test/java/org/apache/archiva/indexer/search/NexusRepositorySearchTest.java
URL: http://svn.apache.org/viewvc/archiva/branches/archiva-nexus-indexer/archiva-modules/archiva-base/archiva-indexer/src/test/java/org/apache/archiva/indexer/search/NexusRepositorySearchTest.java?rev=738801&r1=738800&r2=738801&view=diff
==============================================================================
--- archiva/branches/archiva-nexus-indexer/archiva-modules/archiva-base/archiva-indexer/src/test/java/org/apache/archiva/indexer/search/NexusRepositorySearchTest.java
(original)
+++ archiva/branches/archiva-nexus-indexer/archiva-modules/archiva-base/archiva-indexer/src/test/java/org/apache/archiva/indexer/search/NexusRepositorySearchTest.java
Thu Jan 29 08:47:52 2009
@@ -137,12 +137,14 @@
         }
 
         indexerEngine.endIndexing( context );
+        indexer.removeIndexingContext( context, false );
+        
         assertTrue( new File( getBasedir(), "/target/test-classes/" + repository + "/.indexer"
).exists() );
     }
 
     public void testQuickSearch()
         throws Exception
-    {
+    {   
         List<String> selectedRepos = new ArrayList<String>();
         selectedRepos.add( TEST_REPO_1 );
 
@@ -182,7 +184,7 @@
 
     public void testQuickSearchWithPagination()
         throws Exception
-    {
+    {   
         List<String> selectedRepos = new ArrayList<String>();
         selectedRepos.add( TEST_REPO_1 );
 
@@ -258,32 +260,54 @@
         FileUtils.deleteDirectory( new File( getBasedir(), "/target/test-classes/" + TEST_REPO_2
+ "/.indexer" ) );
         assertFalse( new File( getBasedir(), "/target/test-classes/" + TEST_REPO_2 + "/.indexer"
).exists() );
 
-        // there should be no duplicates in the search result hit
         // TODO: [BROWSE] in artifact info from browse, display all the repositories where
the artifact is found
     }
 
     public void testNoMatchFound()
         throws Exception
     {
+        List<String> selectedRepos = new ArrayList<String>();
+        selectedRepos.add( TEST_REPO_1 );
+        
+        archivaConfigControl.expectAndReturn( archivaConfig.getConfiguration(), config );
+
+        archivaConfigControl.replay();
+
+        SearchResults results = search.search( "user", selectedRepos, "dfghdfkweriuasndsaie",
null );
+
+        archivaConfigControl.verify();
 
+        assertNotNull( results );
+        assertEquals( 0, results.getTotalHits() );
     }
 
     public void testNoIndexFound()
         throws Exception
     {
+        List<String> selectedRepos = new ArrayList<String>();
+        selectedRepos.add( "non-existing-repo" );
+        
+        archivaConfigControl.expectAndReturn( archivaConfig.getConfiguration(), config );
 
+        archivaConfigControl.replay();
+
+        SearchResults results = search.search( "user", selectedRepos, "org.apache.archiva",
null );
+        assertNotNull( results );
+        assertEquals( 0, results.getTotalHits() );
+        
+        archivaConfigControl.verify();            
     }
 
     public void testSearchWithinSearchResults()
         throws Exception
     {
-
+       
     }
 
     public void testAdvancedSearch()
         throws Exception
     {
-
+        
     }
 
 }



Mime
View raw message