diff options
author | Olivier Lamy <olamy@apache.org> | 2011-10-14 16:32:45 +0000 |
---|---|---|
committer | Olivier Lamy <olamy@apache.org> | 2011-10-14 16:32:45 +0000 |
commit | 08d61568b72b9e652a47edc6df4a4f8372dcc865 (patch) | |
tree | c6770fddff6872a5565a1b499e689f506465880e /archiva-modules | |
parent | addd86fec768846339780da5d5f09afaa3c6bcf1 (diff) | |
download | archiva-08d61568b72b9e652a47edc6df4a4f8372dcc865.tar.gz archiva-08d61568b72b9e652a47edc6df4a4f8372dcc865.zip |
if searching with SearchFields with unknown repo ids do not revert to a search on all index.
git-svn-id: https://svn.apache.org/repos/asf/archiva/trunk@1183413 13f79535-47bb-0310-9956-ffa450edef68
Diffstat (limited to 'archiva-modules')
2 files changed, 31 insertions, 0 deletions
diff --git a/archiva-modules/archiva-base/archiva-indexer/src/main/java/org/apache/archiva/indexer/search/NexusRepositorySearch.java b/archiva-modules/archiva-base/archiva-indexer/src/main/java/org/apache/archiva/indexer/search/NexusRepositorySearch.java index 4b5ad3b36..cd0b7fd30 100644 --- a/archiva-modules/archiva-base/archiva-indexer/src/main/java/org/apache/archiva/indexer/search/NexusRepositorySearch.java +++ b/archiva-modules/archiva-base/archiva-indexer/src/main/java/org/apache/archiva/indexer/search/NexusRepositorySearch.java @@ -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()) ) { diff --git a/archiva-modules/archiva-base/archiva-indexer/src/test/java/org/apache/archiva/indexer/search/NexusRepositorySearchTest.java b/archiva-modules/archiva-base/archiva-indexer/src/test/java/org/apache/archiva/indexer/search/NexusRepositorySearchTest.java index 8e72c5cbe..6a024dcb1 100644 --- a/archiva-modules/archiva-base/archiva-indexer/src/test/java/org/apache/archiva/indexer/search/NexusRepositorySearchTest.java +++ b/archiva-modules/archiva-base/archiva-indexer/src/test/java/org/apache/archiva/indexer/search/NexusRepositorySearchTest.java @@ -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() ); + } } |