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-ffa450edef68archiva-nexus-indexer
@@ -4,7 +4,7 @@ | |||
xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-2.5.xsd"> | |||
<bean id="nexusRepositorySearch" class="org.apache.archiva.indexer.search.NexusRepositorySearch"> | |||
<constructor-arg ref="nexusIndexer"/> | |||
<constructor-arg ref="nexusIndexer#archiva"/> | |||
<constructor-arg ref="archivaConfiguration"/> | |||
</bean> | |||
</beans> |
@@ -4,7 +4,7 @@ | |||
xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-2.5.xsd"> | |||
<bean id="indexerConsumer" class="org.apache.archiva.consumers.lucene.NexusIndexerConsumer"> | |||
<constructor-arg ref="nexusIndexer"/> | |||
<constructor-arg ref="nexusIndexer#archiva"/> | |||
<constructor-arg ref="indexPacker"/> | |||
<constructor-arg ref="indexerEngine"/> | |||
</bean> |
@@ -83,6 +83,24 @@ | |||
</check> | |||
</configuration> | |||
</plugin> | |||
<plugin> | |||
<groupId>org.codehaus.plexus</groupId> | |||
<artifactId>plexus-maven-plugin</artifactId> | |||
<executions> | |||
<execution> | |||
<id>merge</id> | |||
<goals> | |||
<goal>merge-descriptors</goal> | |||
</goals> | |||
<configuration> | |||
<descriptors> | |||
<descriptor>${basedir}/src/main/resources/META-INF/plexus/components.xml</descriptor> | |||
<descriptor>${project.build.directory}/generated-resources/plexus/META-INF/plexus/components.xml</descriptor> | |||
</descriptors> | |||
</configuration> | |||
</execution> | |||
</executions> | |||
</plugin> | |||
</plugins> | |||
</build> | |||
</project> |
@@ -62,6 +62,9 @@ public class NexusRepositorySearch | |||
this.archivaConfig = archivaConfig; | |||
} | |||
/** | |||
* @see RepositorySearch#search(String, List, String, SearchResultLimits) | |||
*/ | |||
public SearchResults search( String principal, List<String> 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() ); |
@@ -0,0 +1,55 @@ | |||
<?xml version="1.0" ?> | |||
<!-- | |||
~ Licensed to the Apache Software Foundation (ASF) under one | |||
~ or more contributor license agreements. See the NOTICE file | |||
~ distributed with this work for additional information | |||
~ regarding copyright ownership. The ASF licenses this file | |||
~ to you under the Apache License, Version 2.0 (the | |||
~ "License"); you may not use this file except in compliance | |||
~ with the License. You may obtain a copy of the License at | |||
~ | |||
~ http://www.apache.org/licenses/LICENSE-2.0 | |||
~ | |||
~ Unless required by applicable law or agreed to in writing, | |||
~ software distributed under the License is distributed on an | |||
~ "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY | |||
~ KIND, either express or implied. See the License for the | |||
~ specific language governing permissions and limitations | |||
~ under the License. | |||
--> | |||
<component-set> | |||
<components> | |||
<component> | |||
<role>org.sonatype.nexus.index.NexusIndexer</role> | |||
<role-hint>archiva</role-hint> | |||
<implementation>org.sonatype.nexus.index.DefaultNexusIndexer</implementation> | |||
<description>The default nexus indexer implementation.</description> | |||
<instantiation-strategy>per-lookup</instantiation-strategy> | |||
<isolated-realm>false</isolated-realm> | |||
<requirements> | |||
<requirement> | |||
<role>org.sonatype.nexus.index.scan.Scanner</role> | |||
<role-hint>default</role-hint> | |||
<field-name>scanner</field-name> | |||
</requirement> | |||
<requirement> | |||
<role>org.sonatype.nexus.index.search.SearchEngine</role> | |||
<role-hint>default</role-hint> | |||
<field-name>searcher</field-name> | |||
</requirement> | |||
<requirement> | |||
<role>org.sonatype.nexus.index.creator.IndexerEngine</role> | |||
<role-hint>default</role-hint> | |||
<field-name>indexerEngine</field-name> | |||
</requirement> | |||
<requirement> | |||
<role>org.sonatype.nexus.index.QueryCreator</role> | |||
<role-hint>default</role-hint> | |||
<field-name>queryCreator</field-name> | |||
</requirement> | |||
</requirements> | |||
</component> | |||
</components> | |||
</component-set> |
@@ -4,7 +4,7 @@ | |||
xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-2.5.xsd"> | |||
<bean id="nexusSearch" class="org.apache.archiva.indexer.search.NexusRepositorySearch"> | |||
<constructor-arg ref="nexusIndexer"/> | |||
<constructor-arg ref="nexusIndexer#archiva"/> | |||
<constructor-arg ref="archivaConfiguration"/> | |||
</bean> | |||
</beans> |
@@ -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 ); |
@@ -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; | |||
} | |||
} |