From: Maria Odea B. Ching Date: Mon, 2 Feb 2009 08:04:40 +0000 (+0000) Subject: [MRM-749] X-Git-Url: https://source.dussan.org/?a=commitdiff_plain;h=66caf5f56ef749a6f87c837bb8e0e762b2fc12ab;p=archiva.git [MRM-749] o implement search within search results in nexus impl of search git-svn-id: https://svn.apache.org/repos/asf/archiva/branches/archiva-nexus-indexer@739939 13f79535-47bb-0310-9956-ffa450edef68 --- 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 04b035002..3d054eddf 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 @@ -63,9 +63,10 @@ public class NexusRepositorySearch } /** - * @see RepositorySearch#search(String, List, String, SearchResultLimits) + * @see RepositorySearch#search(String, List, String, SearchResultLimits, List) */ - public SearchResults search( String principal, List selectedRepos, String term, SearchResultLimits limits ) + public SearchResults search( String principal, List selectedRepos, String term, SearchResultLimits limits, + List previousSearchTerms ) throws RepositorySearchException { addIndexingContexts( selectedRepos ); @@ -75,15 +76,27 @@ public class NexusRepositorySearch // - 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 ); @@ -123,6 +136,15 @@ public class NexusRepositorySearch } } } + + 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) diff --git a/archiva-modules/archiva-base/archiva-indexer/src/main/java/org/apache/archiva/indexer/search/RepositorySearch.java b/archiva-modules/archiva-base/archiva-indexer/src/main/java/org/apache/archiva/indexer/search/RepositorySearch.java index 407ca3802..7e20f0892 100644 --- a/archiva-modules/archiva-base/archiva-indexer/src/main/java/org/apache/archiva/indexer/search/RepositorySearch.java +++ b/archiva-modules/archiva-base/archiva-indexer/src/main/java/org/apache/archiva/indexer/search/RepositorySearch.java @@ -33,9 +33,11 @@ public interface RepositorySearch * @param selectedRepos * @param term * @param limits + * @param previousSearchTerms * @return */ - SearchResults search( String principal, List selectedRepos, String term, SearchResultLimits limits ) + SearchResults search( String principal, List selectedRepos, String term, SearchResultLimits limits, + List previousSearchTerms ) throws RepositorySearchException; /** 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 4750f0d60..ef15bb244 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 @@ -153,7 +153,7 @@ public class NexusRepositorySearchTest archivaConfigControl.replay(); - SearchResults results = search.search( "user", selectedRepos, "archiva-search", null ); + SearchResults results = search.search( "user", selectedRepos, "archiva-search", null, null ); archivaConfigControl.verify(); @@ -164,7 +164,7 @@ public class NexusRepositorySearchTest assertEquals( "org.apache.archiva", hit.getGroupId() ); assertEquals( "archiva-search", hit.getArtifactId() ); assertEquals( "1.0", hit.getVersions().get( 0 ) ); - + archivaConfigControl.reset(); // search groupId @@ -172,7 +172,7 @@ public class NexusRepositorySearchTest archivaConfigControl.replay(); - results = search.search( "user", selectedRepos, "org.apache.archiva", null ); + results = search.search( "user", selectedRepos, "org.apache.archiva", null, null ); archivaConfigControl.verify(); @@ -196,7 +196,7 @@ public class NexusRepositorySearchTest archivaConfigControl.replay(); - SearchResults results = search.search( "user", selectedRepos, "org", limits ); + SearchResults results = search.search( "user", selectedRepos, "org", limits, null ); archivaConfigControl.verify(); @@ -213,7 +213,7 @@ public class NexusRepositorySearchTest archivaConfigControl.replay(); - results = search.search( "user", selectedRepos, "org", limits ); + results = search.search( "user", selectedRepos, "org", limits, null ); archivaConfigControl.verify(); @@ -241,7 +241,7 @@ public class NexusRepositorySearchTest archivaConfigControl.replay(); - SearchResults results = search.search( "user", selectedRepos, "archiva-search", null ); + SearchResults results = search.search( "user", selectedRepos, "archiva-search", null, null ); archivaConfigControl.verify(); @@ -273,7 +273,7 @@ public class NexusRepositorySearchTest archivaConfigControl.replay(); - SearchResults results = search.search( "user", selectedRepos, "dfghdfkweriuasndsaie", null ); + SearchResults results = search.search( "user", selectedRepos, "dfghdfkweriuasndsaie", null, null ); archivaConfigControl.verify(); @@ -291,7 +291,7 @@ public class NexusRepositorySearchTest 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() ); @@ -301,7 +301,28 @@ public class NexusRepositorySearchTest public void testSearchWithinSearchResults() throws Exception { - + List selectedRepos = new ArrayList(); + selectedRepos.add( TEST_REPO_1 ); + + List previousSearchTerms = new ArrayList(); + 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() diff --git a/archiva-modules/archiva-web/archiva-webapp/src/main/java/org/apache/maven/archiva/web/action/SearchAction.java b/archiva-modules/archiva-web/archiva-webapp/src/main/java/org/apache/maven/archiva/web/action/SearchAction.java index 9b3cdbe22..940708b02 100644 --- a/archiva-modules/archiva-web/archiva-webapp/src/main/java/org/apache/maven/archiva/web/action/SearchAction.java +++ b/archiva-modules/archiva-web/archiva-webapp/src/main/java/org/apache/maven/archiva/web/action/SearchAction.java @@ -265,7 +265,7 @@ public class SearchAction //results = crossRepoSearch.searchForTerm( getPrincipal(), selectedRepos, q, limits ); try { - results = getNexusSearch().search( getPrincipal(), selectedRepos, q, limits ); + results = getNexusSearch().search( getPrincipal(), selectedRepos, q, limits, null ); } catch ( RepositorySearchException e ) {