]> source.dussan.org Git - archiva.git/commitdiff
[MRM-749]
authorMaria Odea B. Ching <oching@apache.org>
Mon, 2 Feb 2009 08:04:40 +0000 (08:04 +0000)
committerMaria Odea B. Ching <oching@apache.org>
Mon, 2 Feb 2009 08:04:40 +0000 (08:04 +0000)
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

archiva-modules/archiva-base/archiva-indexer/src/main/java/org/apache/archiva/indexer/search/NexusRepositorySearch.java
archiva-modules/archiva-base/archiva-indexer/src/main/java/org/apache/archiva/indexer/search/RepositorySearch.java
archiva-modules/archiva-base/archiva-indexer/src/test/java/org/apache/archiva/indexer/search/NexusRepositorySearchTest.java
archiva-modules/archiva-web/archiva-webapp/src/main/java/org/apache/maven/archiva/web/action/SearchAction.java

index 04b035002927322316cea52922ec1d321c629c69..3d054eddff69764a32ecf04bdef2a98cf8044164 100644 (file)
@@ -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<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 );
@@ -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)
index 407ca3802d5469381e6cdeb078e3f2567ae825d1..7e20f0892dc7a256c9904febdf6d702f463529c9 100644 (file)
@@ -33,9 +33,11 @@ public interface RepositorySearch
      * @param selectedRepos
      * @param term
      * @param limits
+     * @param previousSearchTerms 
      * @return
      */
-    SearchResults search( String principal, List<String> selectedRepos, String term, SearchResultLimits limits )
+    SearchResults search( String principal, List<String> selectedRepos, String term, SearchResultLimits limits,
+                          List<String> previousSearchTerms )
         throws RepositorySearchException;
     
     /**
index 4750f0d601a3811e0aff3f2768f192fda80b4c94..ef15bb2441a1c8df89e973f5f854d0ecfe913b93 100644 (file)
@@ -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<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()
index 9b3cdbe22a70e062a2339fda64b9da1b10d2d696..940708b02ee9571998c567427c89c282a60d7edc 100644 (file)
@@ -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 )
                 {