소스 검색

[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
archiva-nexus-indexer
Maria Odea B. Ching 15 년 전
부모
커밋
8b262c648b

+ 1
- 1
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">

<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>

+ 1
- 1
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">

<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>

+ 18
- 0
archiva-modules/archiva-base/archiva-indexer/pom.xml 파일 보기

@@ -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>

+ 16
- 6
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<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() );

+ 55
- 0
archiva-modules/archiva-base/archiva-indexer/src/main/resources/META-INF/plexus/components.xml 파일 보기

@@ -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>

+ 1
- 1
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">

<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>

+ 2
- 2
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 );

+ 33
- 1
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;
}
}

Loading…
취소
저장