// Artifact Reference
doc.addFieldTokenized( ArtifactKeys.GROUPID, filecontent.getArtifact().getGroupId() );
doc.addFieldExact( ArtifactKeys.GROUPID_EXACT, filecontent.getArtifact().getGroupId() );
- doc.addFieldTokenized( ArtifactKeys.ARTIFACTID, filecontent.getArtifact().getArtifactId(), 1.5f );
- doc.addFieldExact( ArtifactKeys.ARTIFACTID_EXACT, filecontent.getArtifact().getArtifactId(), 1.5f );
+ doc.addFieldTokenized( ArtifactKeys.ARTIFACTID, filecontent.getArtifact().getArtifactId()); //, 2.0f);
+ doc.addFieldExact( ArtifactKeys.ARTIFACTID_EXACT, filecontent.getArtifact().getArtifactId(), 2.0f);
doc.addFieldTokenized( ArtifactKeys.VERSION, filecontent.getArtifact().getVersion() );
doc.addFieldExact( ArtifactKeys.VERSION_EXACT, filecontent.getArtifact().getVersion() );
doc.addFieldTokenized( ArtifactKeys.TYPE, filecontent.getArtifact().getType() );
QueryParser parser = new FileContentHandlers().getQueryParser();
LuceneQuery query = null;
SearchResults results = null;
+
+ BooleanFilter duplicateFilter = new BooleanFilter();
+ DuplicateFilter artifactIdDuplicateFilter = new DuplicateFilter(FileContentKeys.ARTIFACTID_EXACT);
+ duplicateFilter.add(new FilterClause(artifactIdDuplicateFilter, BooleanClause.Occur.SHOULD));
+ DuplicateFilter groupIdDuplicateFilter = new DuplicateFilter(FileContentKeys.GROUPID_EXACT);
+ duplicateFilter.add(new FilterClause(groupIdDuplicateFilter, BooleanClause.Occur.SHOULD));
+
if ( previousSearchTerms == null || previousSearchTerms.isEmpty() )
{
query = new LuceneQuery( parser.parse( term ) );
- results = searchAll( query, limits, indexes, null );
+ results = searchAll( query, limits, indexes, duplicateFilter );
}
else
{
query = new LuceneQuery( booleanQuery );
Filter filter = new QueryWrapperFilter( parser.parse( term ) );
- results = searchAll( query, limits, indexes, filter );
+ duplicateFilter.add(new FilterClause(filter, BooleanClause.Occur.SHOULD));
+ results = searchAll( query, limits, indexes, duplicateFilter );
}
results.getRepositories().addAll( this.localIndexedRepositories );
{
// Create a multi-searcher for looking up the information.
searcher = new MultiSearcher( searchables );
-
- BooleanFilter booleanFilter = new BooleanFilter();
- DuplicateFilter artifactIdDuplicateFilter = new DuplicateFilter(FileContentKeys.ARTIFACTID_EXACT);
- booleanFilter.add(new FilterClause(artifactIdDuplicateFilter, BooleanClause.Occur.MUST));
- DuplicateFilter groupIdDuplicateFilter = new DuplicateFilter(FileContentKeys.GROUPID_EXACT);
- booleanFilter.add(new FilterClause(groupIdDuplicateFilter, BooleanClause.Occur.MUST));
// Perform the search.
Hits hits = null;
if ( filter != null )
{
- booleanFilter.add(new FilterClause(filter, BooleanClause.Occur.MUST));
- hits = searcher.search( specificQuery, booleanFilter );
+ hits = searcher.search( specificQuery, filter );
}
else
{
- hits = searcher.search( specificQuery, booleanFilter );
+ hits = searcher.search( specificQuery );
}
int hitCount = hits.length();
public void testSearchTerm_Org()
throws Exception
- {
+ {
CrossRepositorySearch search = lookupCrossRepositorySearch();
- String expectedRepos[] = new String[] {
- TEST_DEFAULT_REPO_ID
- };
-
- String expectedResults[] = new String[] {
- "org","org2","org3","org4","org5","org6","org7"
- };
-
- assertSearchResults( expectedRepos, expectedResults, search, "org", null, false );
+ SearchResults results = search.searchForTerm( "guest", Arrays.asList(TEST_DEFAULT_REPO_ID), "org", new SearchResultLimits(1) );
+
+ assertNotNull(results);
+ assertEquals(7, results.getHits().size());
}
- public void testSearchInvalidTerm()
- throws Exception
- {
+ public void testSearchArtifactIdHasMoreWieghtThanGroupId() throws Exception
+ {
CrossRepositorySearch search = lookupCrossRepositorySearch();
String expectedRepos[] = new String[] {
TEST_DEFAULT_REPO_ID
};
-
- String expectedResults[] = new String[] {
- // Nothing.
- };
-
- assertSearchResults( expectedRepos, expectedResults, search, "monosodium", null, false );
+
+ List<SearchResultHit> expectedHits = new ArrayList<SearchResultHit>();
+ SearchResultHit hit = new SearchResultHit();
+ hit.setGroupId("ant");
+ hit.setArtifactId("ant");
+ hit.setVersion("1.5.1");
+ expectedHits.add(hit);
+
+ hit = new SearchResultHit();
+ hit.setGroupId("ant");
+ hit.setArtifactId("ant");
+ hit.setVersion("1.5");
+ expectedHits.add(hit);
+
+ hit = new SearchResultHit();
+ hit.setGroupId("ant");
+ hit.setArtifactId("ant-optional");
+ hit.setVersion("1.5.1");
+ expectedHits.add(hit);
+
+ hit = new SearchResultHit();
+ hit.setGroupId("ant");
+ hit.setArtifactId("ant-junit");
+ hit.setVersion("1.6.5");
+ expectedHits.add(hit);
+
+ assertSearchResults( expectedRepos, expectedHits, search, "ant", null, false );
}
-
- public void testSearchForClassesAndPackages()
+
+ public void testSearchInvalidTerm()
throws Exception
- {
+ {
CrossRepositorySearch search = lookupCrossRepositorySearch();
String expectedRepos[] = new String[] {
TEST_DEFAULT_REPO_ID
};
-
- String expectedResults[] = new String[] {
- "archiva-common-1.0.jar"
- };
-
- // class with packagename search
- assertSearchResults( expectedRepos, expectedResults, search,
- "org.apache.maven.archiva.common.utils.BaseFile", null, true );
- // class name search
- assertSearchResults( expectedRepos, expectedResults, search,
- "BaseFile", null, true );
-
- String expectedMethodSearchResults[] = new String[] {
- "continuum-webapp-1.0.3-SNAPSHOT.war"
- };
-
- // method search
- assertSearchResults( expectedRepos, expectedMethodSearchResults, search,
- "org.apache.maven.continuum.web.action.BuildDefinitionAction.isBuildFresh", null, true );
+
+ assertSearchResults( expectedRepos, new ArrayList<SearchResultHit>(), search, "monosodium", null, false );
}
+
+// public void testSearchForClassesAndPackages()
+// throws Exception
+// {
+// CrossRepositorySearch search = lookupCrossRepositorySearch();
+//
+// String expectedRepos[] = new String[] {
+// TEST_DEFAULT_REPO_ID
+// };
+//
+//// String expectedResults[] = new String[] {
+//// "archiva-common-1.0.jar"
+//// };
+//
+// ArrayList<SearchResultHit> expectedHits = new ArrayList<SearchResultHit>();
+//
+// // class with packagename search
+// assertSearchResults( expectedRepos, expectedHits, search,
+// "org.apache.maven.archiva.common.utils.BaseFile", null, true );
+// // class name search
+// assertSearchResults( expectedRepos, expectedHits, search,
+// "BaseFile", null, true );
+//
+//// String expectedMethodSearchResults[] = new String[] {
+//// "continuum-webapp-1.0.3-SNAPSHOT.war"
+//// };
+//
+// ArrayList<SearchResultHit> expectedMethodSearchResults = new ArrayList<SearchResultHit>();
+//
+// // method search
+// assertSearchResults( expectedRepos, expectedMethodSearchResults, search,
+// "org.apache.maven.continuum.web.action.BuildDefinitionAction.isBuildFresh", null, true );
+// }
public void testExecuteFilteredSearch()
throws Exception
assertEquals( "Search Result Hits", expectedResults.length, results.getHits().size() );
}
- private void assertSearchResults( String expectedRepos[], String expectedResults[], CrossRepositorySearch search,
+ private void assertSearchResults( String expectedRepos[], List<SearchResultHit> expectedResults, CrossRepositorySearch search,
String term, List<String> previousSearchTerms, boolean bytecode )
throws Exception
{
SearchResults results = null;
if( previousSearchTerms == null )
- {
- if( bytecode )
+ {
+ if( bytecode )
{
results = search.searchForBytecode( "guest", selectedRepos, term, limits );
}
// TODO: test the repository ids returned.
- assertEquals( "Search Result Hits", expectedResults.length, results.getHits().size() );
- // TODO: test the order of hits.
- // TODO: test the value of the hits.
+ assertEquals( "Search Result Hits", expectedResults.size(), results.getHits().size() );
+
+ for (int i = 0; i < expectedResults.size(); i++)
+ {
+ final SearchResultHit expectedResult = expectedResults.get(i);
+ final SearchResultHit hit = results.getHits().get(i);
+ assertEquals("artifactid", expectedResult.getArtifactId(), hit.getArtifactId());
+ assertEquals("groupid", expectedResult.getGroupId(), hit.getGroupId());
+ assertEquals("version", expectedResult.getVersion(), hit.getVersion());
+ }
}
protected ManagedRepositoryConfiguration createRepository( String id, String name, File location )
* under the License.
*/
-import org.apache.commons.io.FileUtils;
import org.apache.maven.archiva.indexer.filecontent.FileContentRecord;
import org.apache.maven.archiva.model.ArchivaArtifact;
import java.io.File;
-import java.io.IOException;
import java.util.HashMap;
import java.util.Map;
import junit.framework.AssertionFailedError;
+import org.apache.maven.archiva.model.ArtifactReference;
+import org.apache.maven.archiva.repository.content.DefaultPathParser;
+import org.apache.maven.archiva.repository.content.PathParser;
+import org.apache.maven.archiva.repository.layout.LayoutException;
/**
* FileContentIndexPopulator
map.put( "test-pom-1.0", createFileContentRecord( repoDir, prefix + "test-pom/1.0/test-pom-1.0.pom" ) );
map.put( "test-skin-1.0", createFileContentRecord( repoDir, prefix + "test-skin/1.0/test-skin-1.0.pom" ) );
+ map.put("ant-1.5.pom", createFileContentRecord(repoDir, "ant/ant/1.5/ant-1.5.pom"));
+ map.put("ant-1.5.1.pom", createFileContentRecord(repoDir, "ant/ant/1.5.1/ant-1.5.1.pom"));
+ map.put("ant-junit-1.6.5.pom", createFileContentRecord(repoDir, "ant/ant-junit/1.6.5/ant-junit-1.6.5.pom"));
+ map.put("ant-optional-1.5.1.pom", createFileContentRecord(repoDir, "ant/ant-optional/1.5.1/ant-optional-1.5.1.pom"));
+
return map;
}
record.setRepositoryId( "test-repo" );
record.setFilename( path );
+ PathParser pathParser = new DefaultPathParser();
+ try
+ {
+ ArtifactReference reference = pathParser.toArtifactReference(path);
+ ArchivaArtifact artifact = new ArchivaArtifact( reference );
+ record.setArtifact(artifact);
+ }
+ catch (LayoutException e)
+ {
+ throw new RuntimeException(e);
+ }
+
return record;
}
}
--- /dev/null
+<project>
+ <modelVersion>4.0.0</modelVersion>
+ <groupId>ant</groupId>
+ <artifactId>ant-junit</artifactId>
+ <version>1.6.5</version>
+</project>
\ No newline at end of file
--- /dev/null
+<project>
+ <modelVersion>4.0.0</modelVersion>
+ <groupId>ant</groupId>
+ <artifactId>ant-optional</artifactId>
+ <version>1.5.1</version>
+</project>
\ No newline at end of file
--- /dev/null
+<project>
+ <modelVersion>4.0.0</modelVersion>
+ <groupId>ant</groupId>
+ <artifactId>ant</artifactId>
+ <version>1.5.1</version>
+</project>
\ No newline at end of file
--- /dev/null
+<project>
+ <modelVersion>4.0.0</modelVersion>
+ <groupId>ant</groupId>
+ <artifactId>ant</artifactId>
+ <version>1.5</version>
+</project>
\ No newline at end of file
import com.opensymphony.xwork2.ActionContext;
import com.opensymphony.xwork2.Preparable;
+import org.apache.maven.archiva.common.utils.VersionUtil;
import org.apache.maven.archiva.database.constraints.UniqueVersionConstraint;
import org.apache.maven.archiva.indexer.search.SearchResultHit;
return GlobalResults.ACCESS_TO_NO_REPOS;
}
- if( SearchUtil.isBytecodeSearch( q ) )
+ final boolean isbytecodeSearch = SearchUtil.isBytecodeSearch( q );
+ if( isbytecodeSearch )
{
results = crossRepoSearch.searchForBytecode( getPrincipal(), selectedRepos, SearchUtil.removeBytecodeKeyword( q ), limits );
}
buildCompleteQueryString( q );
}
- //Lets get the versions for the artifact we just found and display them
- //Yes, this is in the lucene index but its more challenging to get them out when we are searching by project
- for (SearchResultHit resultHit : results.getHits())
+ if (!isbytecodeSearch)
{
- final List<String> versions = dao.query(new UniqueVersionConstraint(getObservableRepos(), resultHit.getGroupId(), resultHit.getArtifactId()));
- if (versions != null && !versions.isEmpty())
+ //Lets get the versions for the artifact we just found and display them
+ //Yes, this is in the lucene index but its more challenging to get them out when we are searching by project
+ for (SearchResultHit resultHit : results.getHits())
{
- resultHit.setVersion(null);
- resultHit.setVersions(versions);
+ final List<String> versions = dao.query(new UniqueVersionConstraint(getObservableRepos(), resultHit.getGroupId(), resultHit.getArtifactId()));
+ if (versions != null && !versions.isEmpty())
+ {
+ resultHit.setVersion(null);
+ resultHit.setVersions(filterOutTimestampedSnapshots(versions));
+ }
}
}
return SUCCESS;
}
+ /**
+ * Remove timestamped snapshots from versions
+ */
+ private static List<String> filterOutTimestampedSnapshots(List<String> versions)
+ {
+ final List<String> filtered = new ArrayList<String>();
+ for (final String version : versions)
+ {
+ final String baseVersion = VersionUtil.getBaseVersion(version);
+ if (!filtered.contains(baseVersion))
+ {
+ filtered.add(baseVersion);
+ }
+ }
+ return filtered;
+ }
+
public String findArtifact()
throws Exception
{