[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
This commit is contained in:
Brett Porter 2011-06-28 07:31:13 +00:00
parent 2db95ef56d
commit 23e2f88dfb
4 changed files with 54 additions and 18 deletions

View File

@ -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 );

View File

@ -125,11 +125,6 @@ public class SearchResultHit
public void addVersion( String version )
{
if( versions == null )
{
versions = new ArrayList<String>();
}
versions.add( version );
}

View File

@ -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