]> source.dussan.org Git - archiva.git/commitdiff
if searching with SearchFields with unknown repo ids do not revert to a search on...
authorOlivier Lamy <olamy@apache.org>
Fri, 14 Oct 2011 16:32:45 +0000 (16:32 +0000)
committerOlivier Lamy <olamy@apache.org>
Fri, 14 Oct 2011 16:32:45 +0000 (16:32 +0000)
git-svn-id: https://svn.apache.org/repos/asf/archiva/trunk@1183413 13f79535-47bb-0310-9956-ffa450edef68

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

index 4b5ad3b369ae84ab8400b17034036f29257b55ac..cd0b7fd306500796fbb2e8a259f2c78fcb5d5785 100644 (file)
@@ -141,6 +141,13 @@ public class NexusRepositorySearch
 
         List<String> indexingContextIds = addIndexingContexts(searchFields.getRepositories());
 
+        // if no index found in the specified one return an empty search result instead of doing a search on all index
+        // olamy: IMHO doesn't make sense
+        if (indexingContextIds == null || indexingContextIds.isEmpty() )
+        {
+            return new SearchResults();
+        }
+
         BooleanQuery q = new BooleanQuery();
         if ( StringUtils.isNotBlank(searchFields.getGroupId()) )
         {
index 8e72c5cbefafb1fb546f85c329358d2c6baf3ae2..6a024dcb1ee10bc7f7c8149e60bec959940f98a8 100644 (file)
@@ -827,4 +827,28 @@ public class NexusRepositorySearchTest
         assertTrue( groupIds.contains( "org.apache.felix") );
         assertTrue( groupIds.contains( "org.apache.archiva" ) );
     }
+
+    @Test
+    public void testSearchWithUnknownRepo()
+        throws Exception
+    {
+        createIndexContainingMoreArtifacts( true );
+
+        List<String> selectedRepos = Arrays.asList( "foo" );
+
+        SearchFields searchFields = new SearchFields();
+        searchFields.setClassName( "SomeClass" );
+        searchFields.setRepositories( selectedRepos );
+
+        archivaConfigControl.expectAndReturn( archivaConfig.getConfiguration(), config , 1 , 2 );
+
+        archivaConfigControl.replay();
+
+        SearchResults results = search.search( "user", searchFields, null );
+
+        archivaConfigControl.verify();
+
+        assertNotNull( results );
+        assertEquals( 0, results.getHits().size() );
+    }
 }