aboutsummaryrefslogtreecommitdiffstats
path: root/archiva-modules/archiva-base
diff options
context:
space:
mode:
authorBrett Porter <brett@apache.org>2011-06-28 07:31:13 +0000
committerBrett Porter <brett@apache.org>2011-06-28 07:31:13 +0000
commit23e2f88dfb5505ec932173c017d1a003320ffddf (patch)
tree022c2596653ccfeb5739bb07f71fbae517e0e9ca /archiva-modules/archiva-base
parent2db95ef56d57f3e919ecb83b6da7bcc184197654 (diff)
downloadarchiva-23e2f88dfb5505ec932173c017d1a003320ffddf.tar.gz
archiva-23e2f88dfb5505ec932173c017d1a003320ffddf.zip
[MRM-1344] multiple versions appear in search results
Submitted by: Greg Michael Meneses git-svn-id: https://svn.apache.org/repos/asf/archiva/trunk@1140464 13f79535-47bb-0310-9956-ffa450edef68
Diffstat (limited to 'archiva-modules/archiva-base')
-rw-r--r--archiva-modules/archiva-base/archiva-indexer/src/main/java/org/apache/archiva/indexer/search/NexusRepositorySearch.java14
-rw-r--r--archiva-modules/archiva-base/archiva-indexer/src/main/java/org/apache/archiva/indexer/search/SearchResultHit.java5
-rw-r--r--archiva-modules/archiva-base/archiva-indexer/src/test/java/org/apache/archiva/indexer/search/NexusRepositorySearchTest.java53
-rw-r--r--archiva-modules/archiva-base/archiva-indexer/src/test/resources/nexus-search-test-repo/org/apache/archiva/archiva-search/1.0/archiva-search-1.0-sources.jarbin0 -> 2518 bytes
4 files changed, 54 insertions, 18 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 a1f2ccd80..288e0ee39 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
@@ -30,7 +30,6 @@ import org.apache.maven.archiva.configuration.ArchivaConfiguration;
import org.apache.maven.archiva.configuration.Configuration;
import org.apache.maven.archiva.configuration.ManagedRepositoryConfiguration;
import org.apache.maven.index.ArtifactInfo;
-import org.apache.maven.index.Field;
import org.apache.maven.index.FlatSearchRequest;
import org.apache.maven.index.FlatSearchResponse;
import org.apache.maven.index.MAVEN;
@@ -40,15 +39,14 @@ import org.apache.maven.index.context.UnsupportedExistingLuceneIndexException;
import org.apache.maven.index.expr.StringSearchExpression;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
-import org.springframework.context.annotation.Scope;
import org.springframework.stereotype.Service;
-import javax.inject.Inject;
import java.io.File;
import java.io.IOException;
import java.util.List;
import java.util.Map;
import java.util.Set;
+import javax.inject.Inject;
/**
* RepositorySearch implementation which uses the Nexus Indexer for searching.
@@ -274,7 +272,10 @@ public class NexusRepositorySearch
SearchResultHit hit = hitsMap.get( id );
if ( hit != null )
{
- hit.addVersion( artifactInfo.version );
+ if ( !hit.getVersions().contains( artifactInfo.version ) )
+ {
+ hit.addVersion( artifactInfo.version );
+ }
}
else
{
@@ -284,10 +285,7 @@ public class NexusRepositorySearch
// do we still need to set the repository id even though we're merging everything?
//hit.setRepositoryId( artifactInfo.repository );
hit.setUrl( artifactInfo.repository + "/" + artifactInfo.fname );
- if ( !hit.getVersions().contains( artifactInfo.version ) )
- {
- hit.addVersion( artifactInfo.version );
- }
+ hit.addVersion( artifactInfo.version );
}
results.addHit( id, hit );
diff --git a/archiva-modules/archiva-base/archiva-indexer/src/main/java/org/apache/archiva/indexer/search/SearchResultHit.java b/archiva-modules/archiva-base/archiva-indexer/src/main/java/org/apache/archiva/indexer/search/SearchResultHit.java
index 12d7ee45e..253a43c94 100644
--- a/archiva-modules/archiva-base/archiva-indexer/src/main/java/org/apache/archiva/indexer/search/SearchResultHit.java
+++ b/archiva-modules/archiva-base/archiva-indexer/src/main/java/org/apache/archiva/indexer/search/SearchResultHit.java
@@ -125,11 +125,6 @@ public class SearchResultHit
public void addVersion( String version )
{
- if( versions == null )
- {
- versions = new ArrayList<String>();
- }
-
versions.add( version );
}
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 de61692ac..abf861366 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
@@ -41,11 +41,11 @@ import org.junit.runner.RunWith;
import org.springframework.test.context.ContextConfiguration;
import org.springframework.test.context.junit4.SpringJUnit4ClassRunner;
-import javax.inject.Inject;
import java.io.File;
import java.io.IOException;
import java.util.ArrayList;
import java.util.List;
+import javax.inject.Inject;
@RunWith( SpringJUnit4ClassRunner.class )
@@ -140,6 +140,19 @@ public class NexusRepositorySearchTest
createIndex( TEST_REPO_1, files, scan );
}
+
+ private void createIndexContainingMultipleArtifactsSameVersion( boolean scan )
+ throws IOException, UnsupportedExistingLuceneIndexException, IllegalArtifactCoordinateException
+ {
+ List<File> files = new ArrayList<File>();
+
+ files.add( new File( FileUtil.getBasedir(), "/target/test-classes/" + TEST_REPO_1 +
+ "/org/apache/archiva/archiva-search/1.0/archiva-search-1.0.jar" ) );
+ files.add( new File( FileUtil.getBasedir(), "/target/test-classes/" + TEST_REPO_1 +
+ "/org/apache/archiva/archiva-search/1.0/archiva-search-1.0-sources.jar" ) );
+
+ createIndex( TEST_REPO_1, files, scan );
+ }
private ManagedRepositoryConfiguration createRepositoryConfig( String repository )
{
@@ -263,6 +276,36 @@ public class NexusRepositorySearchTest
//TODO: search for class & package names
}
+
+ @Test
+ public void testQuickSearchMultipleArtifactsSameVersion()
+ throws Exception
+ {
+ createIndexContainingMultipleArtifactsSameVersion( false );
+
+ List<String> selectedRepos = new ArrayList<String>();
+ selectedRepos.add( TEST_REPO_1 );
+
+ // search artifactId
+ archivaConfigControl.expectAndReturn( archivaConfig.getConfiguration(), config );
+
+ archivaConfigControl.replay();
+
+ SearchResults results = search.search( "user", selectedRepos, "archiva-search", null, null );
+
+ archivaConfigControl.verify();
+
+ assertNotNull( results );
+ assertEquals( 1, results.getTotalHits() );
+
+ SearchResultHit hit = results.getHits().get( 0 );
+ assertEquals( "org.apache.archiva", hit.getGroupId() );
+ assertEquals( "archiva-search", hit.getArtifactId() );
+ assertEquals( "1.0", hit.getVersions().get( 0 ) );
+
+ //only 1 version of 1.0 is retrieved
+ assertEquals( 1, hit.getVersions().size() );
+ }
// search for existing artifact using multiple keywords
@Test
@@ -308,7 +351,7 @@ public class NexusRepositorySearchTest
assertNotNull( results );
assertEquals( 1, results.getHits().size() );
- assertEquals( "total hits not 4 for page1 " + results, 4, results.getTotalHits() );
+ assertEquals( "total hits not 5 for page1 " + results, 5, results.getTotalHits() );
assertEquals( "returned hits not 1 for page1 " + results, 1, results.getReturnedHitsCount() );
assertEquals( limits, results.getLimits() );
@@ -329,7 +372,7 @@ public class NexusRepositorySearchTest
assertNotNull( results );
assertEquals( "hits not 1", 1, results.getHits().size() );
- assertEquals( "total hits not 4 for page 2 " + results, 4, results.getTotalHits() );
+ assertEquals( "total hits not 5 for page 2 " + results, 5, results.getTotalHits() );
assertEquals( "returned hits not 1 for page2 " + results, 1, results.getReturnedHitsCount() );
assertEquals( limits, results.getLimits() );
}
@@ -362,7 +405,7 @@ public class NexusRepositorySearchTest
archivaConfigControl.verify();
assertNotNull( results );
- assertEquals( 3, results.getTotalHits() );
+ assertEquals( 4, results.getTotalHits() );
SearchResultHit hit = results.getHits().get( 0 );
assertEquals( "org.apache.archiva", hit.getGroupId() );
@@ -718,7 +761,7 @@ public class NexusRepositorySearchTest
archivaConfigControl.verify();
assertNotNull( results );
- assertEquals( 6, results.getTotalHits() );
+ assertEquals( 7, results.getTotalHits() );
}
@Test
diff --git a/archiva-modules/archiva-base/archiva-indexer/src/test/resources/nexus-search-test-repo/org/apache/archiva/archiva-search/1.0/archiva-search-1.0-sources.jar b/archiva-modules/archiva-base/archiva-indexer/src/test/resources/nexus-search-test-repo/org/apache/archiva/archiva-search/1.0/archiva-search-1.0-sources.jar
new file mode 100644
index 000000000..9c16c3ced
--- /dev/null
+++ b/archiva-modules/archiva-base/archiva-indexer/src/test/resources/nexus-search-test-repo/org/apache/archiva/archiva-search/1.0/archiva-search-1.0-sources.jar
Binary files differ