summaryrefslogtreecommitdiffstats
path: root/archiva-modules
diff options
context:
space:
mode:
authorMaria Odea B. Ching <oching@apache.org>2008-07-28 13:35:38 +0000
committerMaria Odea B. Ching <oching@apache.org>2008-07-28 13:35:38 +0000
commit23392d13f374728bd0c690eba3bdc86f4200cd87 (patch)
tree1f45a4a7304fa8b6dc438ea283d3ac346c4ca457 /archiva-modules
parent6a85861b8abcedfc1de1d5e3fe3bfd3d70604def (diff)
downloadarchiva-23392d13f374728bd0c690eba3bdc86f4200cd87.tar.gz
archiva-23392d13f374728bd0c690eba3bdc86f4200cd87.zip
[MRM-892]
-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
Diffstat (limited to 'archiva-modules')
-rw-r--r--archiva-modules/archiva-base/archiva-consumers/archiva-lucene-consumers/src/main/java/org/apache/maven/archiva/consumers/lucene/IndexContentConsumer.java3
-rw-r--r--archiva-modules/archiva-base/archiva-consumers/archiva-lucene-consumers/src/main/java/org/apache/maven/archiva/consumers/lucene/IndexJavaPublicMethodsConsumer.java5
-rw-r--r--archiva-modules/archiva-base/archiva-indexer/src/main/java/org/apache/maven/archiva/indexer/search/DefaultCrossRepositorySearch.java4
-rw-r--r--archiva-modules/archiva-base/archiva-indexer/src/main/java/org/apache/maven/archiva/indexer/search/SearchResults.java1
-rw-r--r--archiva-modules/archiva-base/archiva-indexer/src/test/java/org/apache/maven/archiva/indexer/search/DefaultCrossRepositorySearchTest.java62
-rw-r--r--archiva-modules/archiva-web/archiva-webapp/src/main/java/org/apache/maven/archiva/web/action/SearchAction.java40
-rw-r--r--archiva-modules/archiva-web/archiva-webapp/src/main/webapp/WEB-INF/jsp/include/quickSearchForm.jspf4
7 files changed, 94 insertions, 25 deletions
diff --git a/archiva-modules/archiva-base/archiva-consumers/archiva-lucene-consumers/src/main/java/org/apache/maven/archiva/consumers/lucene/IndexContentConsumer.java b/archiva-modules/archiva-base/archiva-consumers/archiva-lucene-consumers/src/main/java/org/apache/maven/archiva/consumers/lucene/IndexContentConsumer.java
index 77fab6ea4..3bb2b8677 100644
--- a/archiva-modules/archiva-base/archiva-consumers/archiva-lucene-consumers/src/main/java/org/apache/maven/archiva/consumers/lucene/IndexContentConsumer.java
+++ b/archiva-modules/archiva-base/archiva-consumers/archiva-lucene-consumers/src/main/java/org/apache/maven/archiva/consumers/lucene/IndexContentConsumer.java
@@ -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 )
{
diff --git a/archiva-modules/archiva-base/archiva-consumers/archiva-lucene-consumers/src/main/java/org/apache/maven/archiva/consumers/lucene/IndexJavaPublicMethodsConsumer.java b/archiva-modules/archiva-base/archiva-consumers/archiva-lucene-consumers/src/main/java/org/apache/maven/archiva/consumers/lucene/IndexJavaPublicMethodsConsumer.java
index 755755225..022853a3d 100644
--- a/archiva-modules/archiva-base/archiva-consumers/archiva-lucene-consumers/src/main/java/org/apache/maven/archiva/consumers/lucene/IndexJavaPublicMethodsConsumer.java
+++ b/archiva-modules/archiva-base/archiva-consumers/archiva-lucene-consumers/src/main/java/org/apache/maven/archiva/consumers/lucene/IndexJavaPublicMethodsConsumer.java
@@ -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 ) );
diff --git a/archiva-modules/archiva-base/archiva-indexer/src/main/java/org/apache/maven/archiva/indexer/search/DefaultCrossRepositorySearch.java b/archiva-modules/archiva-base/archiva-indexer/src/main/java/org/apache/maven/archiva/indexer/search/DefaultCrossRepositorySearch.java
index 8565acc46..ede311346 100644
--- a/archiva-modules/archiva-base/archiva-indexer/src/main/java/org/apache/maven/archiva/indexer/search/DefaultCrossRepositorySearch.java
+++ b/archiva-modules/archiva-base/archiva-indexer/src/main/java/org/apache/maven/archiva/indexer/search/DefaultCrossRepositorySearch.java
@@ -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();
diff --git a/archiva-modules/archiva-base/archiva-indexer/src/main/java/org/apache/maven/archiva/indexer/search/SearchResults.java b/archiva-modules/archiva-base/archiva-indexer/src/main/java/org/apache/maven/archiva/indexer/search/SearchResults.java
index 6465814c3..6110374a1 100644
--- a/archiva-modules/archiva-base/archiva-indexer/src/main/java/org/apache/maven/archiva/indexer/search/SearchResults.java
+++ b/archiva-modules/archiva-base/archiva-indexer/src/main/java/org/apache/maven/archiva/indexer/search/SearchResults.java
@@ -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() ) );
diff --git a/archiva-modules/archiva-base/archiva-indexer/src/test/java/org/apache/maven/archiva/indexer/search/DefaultCrossRepositorySearchTest.java b/archiva-modules/archiva-base/archiva-indexer/src/test/java/org/apache/maven/archiva/indexer/search/DefaultCrossRepositorySearchTest.java
index 576b54481..71c872d67 100644
--- a/archiva-modules/archiva-base/archiva-indexer/src/test/java/org/apache/maven/archiva/indexer/search/DefaultCrossRepositorySearchTest.java
+++ b/archiva-modules/archiva-base/archiva-indexer/src/test/java/org/apache/maven/archiva/indexer/search/DefaultCrossRepositorySearchTest.java
@@ -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
{
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 92b203c84..b2bda65fe 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
@@ -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;
+ }
}
diff --git a/archiva-modules/archiva-web/archiva-webapp/src/main/webapp/WEB-INF/jsp/include/quickSearchForm.jspf b/archiva-modules/archiva-web/archiva-webapp/src/main/webapp/WEB-INF/jsp/include/quickSearchForm.jspf
index 71ef30ae4..b37f28cac 100644
--- a/archiva-modules/archiva-web/archiva-webapp/src/main/webapp/WEB-INF/jsp/include/quickSearchForm.jspf
+++ b/archiva-modules/archiva-web/archiva-webapp/src/main/webapp/WEB-INF/jsp/include/quickSearchForm.jspf
@@ -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