]> source.dussan.org Git - archiva.git/commitdiff
[MRM-892]
authorMaria Odea B. Ching <oching@apache.org>
Mon, 28 Jul 2008 13:35:38 +0000 (13:35 +0000)
committerMaria Odea B. Ching <oching@apache.org>
Mon, 28 Jul 2008 13:35:38 +0000 (13:35 +0000)
-changed the implementation of search by class, package or method to use specific keywords 'class:', 'package:' or 'method:' when searching
for them (ex. class:MyClass)

git-svn-id: https://svn.apache.org/repos/asf/archiva/trunk@680352 13f79535-47bb-0310-9956-ffa450edef68

archiva-modules/archiva-base/archiva-consumers/archiva-lucene-consumers/src/main/java/org/apache/maven/archiva/consumers/lucene/IndexContentConsumer.java
archiva-modules/archiva-base/archiva-consumers/archiva-lucene-consumers/src/main/java/org/apache/maven/archiva/consumers/lucene/IndexJavaPublicMethodsConsumer.java
archiva-modules/archiva-base/archiva-indexer/src/main/java/org/apache/maven/archiva/indexer/search/DefaultCrossRepositorySearch.java
archiva-modules/archiva-base/archiva-indexer/src/main/java/org/apache/maven/archiva/indexer/search/SearchResults.java
archiva-modules/archiva-base/archiva-indexer/src/test/java/org/apache/maven/archiva/indexer/search/DefaultCrossRepositorySearchTest.java
archiva-modules/archiva-web/archiva-webapp/src/main/java/org/apache/maven/archiva/web/action/SearchAction.java
archiva-modules/archiva-web/archiva-webapp/src/main/webapp/WEB-INF/jsp/include/quickSearchForm.jspf

index 77fab6ea48350a7b851cce86f38fa1d7ee4db29b..3bb2b8677f862ddb528bef86456eddd729029019 100644 (file)
@@ -171,7 +171,8 @@ public class IndexContentConsumer
             {
                 ArtifactReference ref = repository.toArtifactReference( path );
                 ArchivaArtifact artifact = new ArchivaArtifact( ref );
-                record.setArtifact( artifact );
+                artifact.getModel().setRepositoryId( repository.getId() );
+                record.setArtifact( artifact );                
             }
             catch ( LayoutException e )
             {
index 755755225faeecbeaa5703045274baad02cda814..022853a3d044b690adc9a990be6ceb1e06c32341 100644 (file)
@@ -130,8 +130,7 @@ public class IndexJavaPublicMethodsConsumer
                     file.getAbsolutePath().endsWith( ".tar.gz" ) || file.getAbsolutePath().endsWith( ".tar.bz2" ) ||
                     file.getAbsolutePath().endsWith( ".car" ) || file.getAbsolutePath().endsWith( ".sar" ) ||
                     file.getAbsolutePath().endsWith( ".mar" ) || file.getAbsolutePath().endsWith( ".rar" ) )
-            {
-            
+            {            
                 if( file.exists() )
                 {
                     List<String> files = readFilesInArchive( file );
@@ -141,6 +140,8 @@ public class IndexJavaPublicMethodsConsumer
                     // NOTE: what about public variables? should these be indexed too?
                     RepositoryContentIndex bytecodeIndex = repoIndexFactory.createBytecodeIndex( repoContent.getRepository() );
                     
+                    artifact.getModel().setRepositoryId( repoContent.getId() );
+                    
                     BytecodeRecord bytecodeRecord = new BytecodeRecord();
                     bytecodeRecord.setFilename( file.getName() );
                     bytecodeRecord.setClasses( mapOfClassesAndMethods.get( CLASSES ) );
index 8565acc46490f90c865736767dc5dd5cc7ecbd6c..ede3113468d30a11db007269f7e1a4b0b7e42de8 100644 (file)
@@ -134,9 +134,7 @@ public class DefaultCrossRepositorySearch
                                         SearchResultLimits limits, List<String> previousSearchTerms )
     {
         List<RepositoryContentIndex> indexes = getFileContentIndexes( principal, selectedRepos );
-        List<RepositoryContentIndex> bytecodeIndices = getBytecodeIndexes( principal, selectedRepos );        
-        indexes.addAll( bytecodeIndices );
-
+        
         try
         {
             QueryParser parser = new FileContentHandlers().getQueryParser();
index 6465814c39cde33f969bfa145b983ce175629954..6110374a1780642463392ef13ad1f7eb9108da5a 100644 (file)
@@ -92,6 +92,7 @@ public class SearchResults
     {
         StringBuffer key = new StringBuffer();
 
+        key.append( StringUtils.defaultString( artifact.getModel().getRepositoryId() ) ).append( ":" );
         key.append( StringUtils.defaultString( artifact.getGroupId() ) ).append( ":" );
         key.append( StringUtils.defaultString( artifact.getArtifactId() ) );
 
index 576b54481268501e02d0f16fa539758bc5ef4e26..71c872d671651759bb70c5ff82f2b01c53f28a54 100644 (file)
@@ -129,7 +129,7 @@ public class DefaultCrossRepositorySearchTest
 
     public void testSearchTerm_Org()
         throws Exception
-    {
+    {        
         CrossRepositorySearch search = lookupCrossRepositorySearch();
 
         String expectedRepos[] = new String[] {
@@ -140,12 +140,12 @@ public class DefaultCrossRepositorySearchTest
             "org","org2","org3","org4","org5","org6","org7"
         };
         
-        assertSearchResults( expectedRepos, expectedResults, search, "org", null );
+        assertSearchResults( expectedRepos, expectedResults, search, "org", null, false );
     }
 
     public void testSearchTerm_Junit()
         throws Exception
-    {
+    {        
         CrossRepositorySearch search = lookupCrossRepositorySearch();
         
         String expectedRepos[] = new String[] {
@@ -156,12 +156,12 @@ public class DefaultCrossRepositorySearchTest
             "junit","junit2","junit3"
         };
         
-        assertSearchResults( expectedRepos, expectedResults, search, "junit", null );
+        assertSearchResults( expectedRepos, expectedResults, search, "junit", null, false );
     }
 
     public void testSearchInvalidTerm()
         throws Exception
-    {
+    {        
         CrossRepositorySearch search = lookupCrossRepositorySearch();
 
         String expectedRepos[] = new String[] {
@@ -172,12 +172,12 @@ public class DefaultCrossRepositorySearchTest
             // Nothing.
         };
         
-        assertSearchResults( expectedRepos, expectedResults, search, "monosodium", null );
+        assertSearchResults( expectedRepos, expectedResults, search, "monosodium", null, false );
     }
     
     public void testSearchWithinSearchResults()
         throws Exception
-    {
+    {        
         CrossRepositorySearch search = lookupCrossRepositorySearch();
 
         String expectedRepos[] = new String[] {
@@ -189,7 +189,7 @@ public class DefaultCrossRepositorySearchTest
         };
         
         // first search
-        assertSearchResults( expectedRepos, expectedResults, search, "org", null );
+        assertSearchResults( expectedRepos, expectedResults, search, "org", null, false );
         
         List<String> previousSearchTerms = new ArrayList<String>();
         previousSearchTerms.add( "org" );        
@@ -197,12 +197,12 @@ public class DefaultCrossRepositorySearchTest
             "org.apache.maven.archiva.record", "org.apache.maven.archiva.record2",
                 "org.apache.maven.archiva.record3", "org.apache.maven.archiva.record4",
                 "org.apache.maven.archiva.record5", "org.apache.maven.archiva.record6",
-                "org.apache.maven.archiva.record7"
+                "org.apache.maven.archiva.record7" 
         };
         
         //second search
         assertSearchResults( expectedRepos, secondSearchExpectedResults, search, "org.apache.maven.archiva.record",
-                             previousSearchTerms );
+                             previousSearchTerms, false );
         
         previousSearchTerms.add( "org.apache.maven.archiva.record" );
         String thirdSearchExpectedResults[] = new String[] { 
@@ -210,11 +210,40 @@ public class DefaultCrossRepositorySearchTest
         };
         
         //third search
-        assertSearchResults( expectedRepos, thirdSearchExpectedResults, search, "junit", previousSearchTerms );        
+        assertSearchResults( expectedRepos, thirdSearchExpectedResults, search, "junit", previousSearchTerms, 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"
+        };
+        
+        // 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 );        
     }
     
     private void assertSearchResults( String expectedRepos[], String expectedResults[], CrossRepositorySearch search,
-                                      String term, List<String> previousSearchTerms )
+                                      String term, List<String> previousSearchTerms, boolean bytecode )
         throws Exception
     {
         SearchResultLimits limits = new SearchResultLimits( 0 );
@@ -226,7 +255,14 @@ public class DefaultCrossRepositorySearchTest
         SearchResults results = null;
         if( previousSearchTerms == null )
         {
-            results = search.searchForTerm( "guest", selectedRepos, term, limits );
+            if( bytecode )
+            {
+                results = search.searchForBytecode( "guest", selectedRepos, term, limits );
+            }
+            else
+            {
+                results = search.searchForTerm( "guest", selectedRepos, term, limits );
+            }
         }
         else
         {
index 92b203c847e0ef1863e7497c7767f2e0aedc7666..b2bda65fecbdac257e5541cc30a3f4662c20a72d 100644 (file)
@@ -90,6 +90,8 @@ public class SearchAction
     private String completeQueryString;
     
     private static final String COMPLETE_QUERY_STRING_SEPARATOR = ";";
+    
+    private static final String[] BYTECODE_KEYWORDS = new String[] { "class:", "package:", "method:" };
 
     public String quickSearch()
         throws MalformedURLException, RepositoryIndexException, RepositoryIndexSearchException
@@ -110,14 +112,21 @@ public class SearchAction
             return GlobalResults.ACCESS_TO_NO_REPOS;
         }
 
-        if( searchResultsOnly && !completeQueryString.equals( "" ) )
-        { 
-            results = crossRepoSearch.searchForTerm( getPrincipal(), selectedRepos, q, limits, parseCompleteQueryString() );
+        if( isBytecodeSearch( q ) )
+        {   
+            results = crossRepoSearch.searchForBytecode( getPrincipal(), selectedRepos, removeKeywords( q ), limits );
         }
         else
         {
-            completeQueryString = "";
-            results = crossRepoSearch.searchForTerm( getPrincipal(), selectedRepos, q, limits );
+            if( searchResultsOnly && !completeQueryString.equals( "" ) )
+            { 
+                results = crossRepoSearch.searchForTerm( getPrincipal(), selectedRepos, q, limits, parseCompleteQueryString() );
+            }
+            else
+            {
+                completeQueryString = "";
+                results = crossRepoSearch.searchForTerm( getPrincipal(), selectedRepos, q, limits );
+            }
         }
         
         if ( results.isEmpty() )
@@ -310,4 +319,25 @@ public class SearchAction
     {
         this.completeQueryString = completeQueryString;
     }    
+    
+    private boolean isBytecodeSearch( String queryString )
+    {
+        if( queryString.startsWith( BYTECODE_KEYWORDS[0] ) || queryString.startsWith( BYTECODE_KEYWORDS[1] ) || 
+                        queryString.startsWith( BYTECODE_KEYWORDS[2] ) )
+        {
+            return true;
+        }
+        
+        return false;
+    }
+    
+    private String removeKeywords( String queryString )
+    {  
+        String qString = StringUtils.uncapitalize( queryString );
+        qString = StringUtils.removeStart( queryString, BYTECODE_KEYWORDS[0] );
+        qString = StringUtils.removeStart( qString, BYTECODE_KEYWORDS[1] );
+        qString = StringUtils.removeStart( qString, BYTECODE_KEYWORDS[2] );
+        
+        return qString;
+    }
 }
index 71ef30ae43be40456045f21e353aa77cab9b5e98..b37f28cac2196b373485958d3c94b1019f2f9587 100644 (file)
@@ -32,7 +32,9 @@
   </script>
 
   <p>
-    Enter your search terms. A variety of data will be searched for your keywords.
+    Enter your search terms. A variety of data will be searched for your keywords.<br/>
+    To search for java classes, packages or methods, append the keywords "<i>class:</i>",
+    "<i>package:</i>" or "<i>method:</i>" before your query. Example, class:MyClass 
     <ww:actionerror/>
   </p>
 </div>
\ No newline at end of file