}
/**
- * @see RepositorySearch#search(String, List, String, SearchResultLimits)
+ * @see RepositorySearch#search(String, List, String, SearchResultLimits, List)
*/
- public SearchResults search( String principal, List<String> selectedRepos, String term, SearchResultLimits limits )
+ public SearchResults search( String principal, List<String> selectedRepos, String term, SearchResultLimits limits,
+ List<String> previousSearchTerms )
throws RepositorySearchException
{
addIndexingContexts( selectedRepos );
// - regular search
// - searching within search results
// 3. multiple repositories
-
+
BooleanQuery q = new BooleanQuery();
- q.add( indexer.constructQuery( ArtifactInfo.GROUP_ID, term ), Occur.SHOULD );
- q.add( indexer.constructQuery( ArtifactInfo.ARTIFACT_ID, term ), Occur.SHOULD );
- q.add( indexer.constructQuery( ArtifactInfo.VERSION, term ), Occur.SHOULD );
- q.add( indexer.constructQuery( ArtifactInfo.PACKAGING, term ), Occur.SHOULD );
+ if( previousSearchTerms == null || previousSearchTerms.isEmpty() )
+ {
+ constructQuery( term, q );
+ }
+ else
+ {
+ for( String previousTerm : previousSearchTerms )
+ {
+ BooleanQuery iQuery = new BooleanQuery();
+ constructQuery( previousTerm, iQuery );
- // TODO: what about class & package?
-
+ q.add( iQuery, Occur.MUST );
+ }
+
+ BooleanQuery iQuery = new BooleanQuery();
+ constructQuery( term, iQuery );
+ q.add( iQuery, Occur.MUST );
+ }
+
try
{
FlatSearchRequest request = new FlatSearchRequest( q );
}
}
}
+
+ private void constructQuery( String term, BooleanQuery q )
+ {
+ q.add( indexer.constructQuery( ArtifactInfo.GROUP_ID, term ), Occur.SHOULD );
+ q.add( indexer.constructQuery( ArtifactInfo.ARTIFACT_ID, term ), Occur.SHOULD );
+ q.add( indexer.constructQuery( ArtifactInfo.VERSION, term ), Occur.SHOULD );
+ q.add( indexer.constructQuery( ArtifactInfo.PACKAGING, term ), Occur.SHOULD );
+ q.add( indexer.constructQuery( ArtifactInfo.NAMES, term ), Occur.SHOULD );
+ }
/**
* @see RepositorySearch#search(String, SearchFields, SearchResultLimits)
archivaConfigControl.replay();
- SearchResults results = search.search( "user", selectedRepos, "archiva-search", null );
+ SearchResults results = search.search( "user", selectedRepos, "archiva-search", null, null );
archivaConfigControl.verify();
assertEquals( "org.apache.archiva", hit.getGroupId() );
assertEquals( "archiva-search", hit.getArtifactId() );
assertEquals( "1.0", hit.getVersions().get( 0 ) );
-
+
archivaConfigControl.reset();
// search groupId
archivaConfigControl.replay();
- results = search.search( "user", selectedRepos, "org.apache.archiva", null );
+ results = search.search( "user", selectedRepos, "org.apache.archiva", null, null );
archivaConfigControl.verify();
archivaConfigControl.replay();
- SearchResults results = search.search( "user", selectedRepos, "org", limits );
+ SearchResults results = search.search( "user", selectedRepos, "org", limits, null );
archivaConfigControl.verify();
archivaConfigControl.replay();
- results = search.search( "user", selectedRepos, "org", limits );
+ results = search.search( "user", selectedRepos, "org", limits, null );
archivaConfigControl.verify();
archivaConfigControl.replay();
- SearchResults results = search.search( "user", selectedRepos, "archiva-search", null );
+ SearchResults results = search.search( "user", selectedRepos, "archiva-search", null, null );
archivaConfigControl.verify();
archivaConfigControl.replay();
- SearchResults results = search.search( "user", selectedRepos, "dfghdfkweriuasndsaie", null );
+ SearchResults results = search.search( "user", selectedRepos, "dfghdfkweriuasndsaie", null, null );
archivaConfigControl.verify();
archivaConfigControl.replay();
- SearchResults results = search.search( "user", selectedRepos, "org.apache.archiva", null );
+ SearchResults results = search.search( "user", selectedRepos, "org.apache.archiva", null, null );
assertNotNull( results );
assertEquals( 0, results.getTotalHits() );
public void testSearchWithinSearchResults()
throws Exception
{
-
+ List<String> selectedRepos = new ArrayList<String>();
+ selectedRepos.add( TEST_REPO_1 );
+
+ List<String> previousSearchTerms = new ArrayList<String>();
+ previousSearchTerms.add( "archiva-test" );
+
+ archivaConfigControl.expectAndReturn( archivaConfig.getConfiguration(), config );
+
+ archivaConfigControl.replay();
+
+ SearchResults results = search.search( "user", selectedRepos, "1.0", null, previousSearchTerms );
+
+ archivaConfigControl.verify();
+
+ assertNotNull( results );
+ assertEquals( 1, results.getTotalHits() );
+
+ SearchResultHit hit = results.getHits().get( 0 );
+ assertEquals( "org.apache.archiva", hit.getGroupId() );
+ assertEquals( "archiva-test", hit.getArtifactId() );
+ assertEquals( 1, hit.getVersions().size() );
+ assertEquals( "1.0", hit.getVersions().get( 0 ) );
}
public void testAdvancedSearch()