From 08d61568b72b9e652a47edc6df4a4f8372dcc865 Mon Sep 17 00:00:00 2001 From: Olivier Lamy Date: Fri, 14 Oct 2011 16:32:45 +0000 Subject: [PATCH] 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 --- .../indexer/search/NexusRepositorySearch.java | 7 ++++++ .../search/NexusRepositorySearchTest.java | 24 +++++++++++++++++++ 2 files changed, 31 insertions(+) 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 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 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() ); + } } -- 2.39.5