From 8b262c648b7864dd4f67897a7c88e7facb7858b4 Mon Sep 17 00:00:00 2001 From: "Maria Odea B. Ching" Date: Fri, 30 Jan 2009 07:32:35 +0000 Subject: [PATCH] [MRM-749] o wire search action to use nexus repository search (quick search) git-svn-id: https://svn.apache.org/repos/asf/archiva/branches/archiva-nexus-indexer@739197 13f79535-47bb-0310-9956-ffa450edef68 --- .../src/main/resources/spring-context.xml | 2 +- .../resources/META-INF/spring-context.xml | 2 +- .../archiva-base/archiva-indexer/pom.xml | 18 ++++++ .../indexer/search/NexusRepositorySearch.java | 22 ++++++-- .../resources/META-INF/plexus/components.xml | 55 +++++++++++++++++++ .../resources/META-INF/spring-context.xml | 2 +- .../search/NexusRepositorySearchTest.java | 4 +- .../archiva/web/action/SearchAction.java | 34 +++++++++++- 8 files changed, 127 insertions(+), 12 deletions(-) create mode 100644 archiva-modules/archiva-base/archiva-indexer/src/main/resources/META-INF/plexus/components.xml diff --git a/archiva-modules/archiva-base/archiva-configuration/src/main/resources/spring-context.xml b/archiva-modules/archiva-base/archiva-configuration/src/main/resources/spring-context.xml index ccb973ca4..72bac5f9f 100644 --- a/archiva-modules/archiva-base/archiva-configuration/src/main/resources/spring-context.xml +++ b/archiva-modules/archiva-base/archiva-configuration/src/main/resources/spring-context.xml @@ -4,7 +4,7 @@ xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-2.5.xsd"> - + \ No newline at end of file diff --git a/archiva-modules/archiva-base/archiva-consumers/archiva-lucene-consumers/src/main/resources/META-INF/spring-context.xml b/archiva-modules/archiva-base/archiva-consumers/archiva-lucene-consumers/src/main/resources/META-INF/spring-context.xml index ff7dac5e2..815236176 100644 --- a/archiva-modules/archiva-base/archiva-consumers/archiva-lucene-consumers/src/main/resources/META-INF/spring-context.xml +++ b/archiva-modules/archiva-base/archiva-consumers/archiva-lucene-consumers/src/main/resources/META-INF/spring-context.xml @@ -4,7 +4,7 @@ xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-2.5.xsd"> - + diff --git a/archiva-modules/archiva-base/archiva-indexer/pom.xml b/archiva-modules/archiva-base/archiva-indexer/pom.xml index a5eb3227d..54d8a7a2a 100644 --- a/archiva-modules/archiva-base/archiva-indexer/pom.xml +++ b/archiva-modules/archiva-base/archiva-indexer/pom.xml @@ -83,6 +83,24 @@ + + org.codehaus.plexus + plexus-maven-plugin + + + merge + + merge-descriptors + + + + ${basedir}/src/main/resources/META-INF/plexus/components.xml + ${project.build.directory}/generated-resources/plexus/META-INF/plexus/components.xml + + + + + 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 a878c58ad..04b035002 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 @@ -62,6 +62,9 @@ public class NexusRepositorySearch this.archivaConfig = archivaConfig; } + /** + * @see RepositorySearch#search(String, List, String, SearchResultLimits) + */ public SearchResults search( String principal, List selectedRepos, String term, SearchResultLimits limits ) throws RepositorySearchException { @@ -120,7 +123,10 @@ public class NexusRepositorySearch } } } - + + /** + * @see RepositorySearch#search(String, SearchFields, SearchResultLimits) + */ public SearchResults search( String principal, SearchFields searchFields, SearchResultLimits limits ) throws RepositorySearchException { @@ -219,13 +225,17 @@ public class NexusRepositorySearch private SearchResults paginate( SearchResultLimits limits, SearchResults results ) { - SearchResults paginated = new SearchResults(); - + SearchResults paginated = new SearchResults(); int fetchCount = limits.getPageSize(); int offset = ( limits.getSelectedPage() * limits.getPageSize() ); - + + if( fetchCount > results.getTotalHits() ) + { + fetchCount = results.getTotalHits(); + } + // Goto offset. - if ( offset <= results.getTotalHits() ) + if ( offset < results.getTotalHits() ) { // only process if the offset is within the hit count. for ( int i = 0; i < fetchCount; i++ ) @@ -236,7 +246,7 @@ public class NexusRepositorySearch break; } - SearchResultHit hit = results.getHits().get( ( offset + i ) - 1 ); + SearchResultHit hit = results.getHits().get( ( offset + i ) ); if( hit != null ) { String id = SearchUtil.getHitId( hit.getGroupId(), hit.getArtifactId() ); diff --git a/archiva-modules/archiva-base/archiva-indexer/src/main/resources/META-INF/plexus/components.xml b/archiva-modules/archiva-base/archiva-indexer/src/main/resources/META-INF/plexus/components.xml new file mode 100644 index 000000000..8e03700cc --- /dev/null +++ b/archiva-modules/archiva-base/archiva-indexer/src/main/resources/META-INF/plexus/components.xml @@ -0,0 +1,55 @@ + + + + + + + org.sonatype.nexus.index.NexusIndexer + archiva + org.sonatype.nexus.index.DefaultNexusIndexer + The default nexus indexer implementation. + per-lookup + false + + + org.sonatype.nexus.index.scan.Scanner + default + scanner + + + org.sonatype.nexus.index.search.SearchEngine + default + searcher + + + org.sonatype.nexus.index.creator.IndexerEngine + default + indexerEngine + + + org.sonatype.nexus.index.QueryCreator + default + queryCreator + + + + + + diff --git a/archiva-modules/archiva-base/archiva-indexer/src/main/resources/META-INF/spring-context.xml b/archiva-modules/archiva-base/archiva-indexer/src/main/resources/META-INF/spring-context.xml index 1befe9479..bc69c7e36 100644 --- a/archiva-modules/archiva-base/archiva-indexer/src/main/resources/META-INF/spring-context.xml +++ b/archiva-modules/archiva-base/archiva-indexer/src/main/resources/META-INF/spring-context.xml @@ -4,7 +4,7 @@ xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-2.5.xsd"> - + \ No newline at end of file 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 cbdb9c7e5..4750f0d60 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 @@ -189,7 +189,7 @@ public class NexusRepositorySearchTest selectedRepos.add( TEST_REPO_1 ); // page 1 - SearchResultLimits limits = new SearchResultLimits( 1 ); + SearchResultLimits limits = new SearchResultLimits( 0 ); limits.setPageSize( 1 ); archivaConfigControl.expectAndReturn( archivaConfig.getConfiguration(), config ); @@ -206,7 +206,7 @@ public class NexusRepositorySearchTest archivaConfigControl.reset(); // page 2 - limits = new SearchResultLimits( 2 ); + limits = new SearchResultLimits( 1 ); limits.setPageSize( 1 ); archivaConfigControl.expectAndReturn( archivaConfig.getConfiguration(), config ); 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 7db42d166..9b3cdbe22 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 @@ -25,6 +25,8 @@ import java.util.Collections; import java.util.List; import java.util.Map; +import org.apache.archiva.indexer.search.RepositorySearch; +import org.apache.archiva.indexer.search.RepositorySearchException; import org.apache.archiva.indexer.util.SearchUtil; import org.apache.commons.collections.CollectionUtils; import org.apache.commons.lang.StringUtils; @@ -49,6 +51,9 @@ import com.opensymphony.xwork2.Preparable; import org.apache.maven.archiva.common.utils.VersionUtil; import org.apache.maven.archiva.database.constraints.UniqueVersionConstraint; import org.apache.maven.archiva.indexer.search.SearchResultHit; +import org.apache.struts2.ServletActionContext; +import org.springframework.web.context.WebApplicationContext; +import org.springframework.web.context.support.WebApplicationContextUtils; /** * Search all indexed fields by the given criteria. @@ -130,6 +135,8 @@ public class SearchAction private boolean fromResultsPage; + private RepositorySearch nexusSearch; + public boolean isFromResultsPage() { return fromResultsPage; @@ -255,7 +262,16 @@ public class SearchAction else { completeQueryString = ""; - results = crossRepoSearch.searchForTerm( getPrincipal(), selectedRepos, q, limits ); + //results = crossRepoSearch.searchForTerm( getPrincipal(), selectedRepos, q, limits ); + try + { + results = getNexusSearch().search( getPrincipal(), selectedRepos, q, limits ); + } + catch ( RepositorySearchException e ) + { + addActionError( e.getMessage() ); + return ERROR; + } } } @@ -579,4 +595,20 @@ public class SearchAction { this.className = className; } + + public RepositorySearch getNexusSearch() + { + if( nexusSearch == null ) + { + WebApplicationContext wac = + WebApplicationContextUtils.getRequiredWebApplicationContext( ServletActionContext.getServletContext() ); + nexusSearch = ( RepositorySearch ) wac.getBean( "nexusSearch" ); + } + return nexusSearch; + } + + public void setNexusSearch( RepositorySearch nexusSearch ) + { + this.nexusSearch = nexusSearch; + } }