]> source.dussan.org Git - archiva.git/commitdiff
[MRM-749]
authorMaria Odea B. Ching <oching@apache.org>
Fri, 30 Jan 2009 07:32:35 +0000 (07:32 +0000)
committerMaria Odea B. Ching <oching@apache.org>
Fri, 30 Jan 2009 07:32:35 +0000 (07:32 +0000)
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-modules/archiva-base/archiva-configuration/src/main/resources/spring-context.xml
archiva-modules/archiva-base/archiva-consumers/archiva-lucene-consumers/src/main/resources/META-INF/spring-context.xml
archiva-modules/archiva-base/archiva-indexer/pom.xml
archiva-modules/archiva-base/archiva-indexer/src/main/java/org/apache/archiva/indexer/search/NexusRepositorySearch.java
archiva-modules/archiva-base/archiva-indexer/src/main/resources/META-INF/plexus/components.xml [new file with mode: 0644]
archiva-modules/archiva-base/archiva-indexer/src/main/resources/META-INF/spring-context.xml
archiva-modules/archiva-base/archiva-indexer/src/test/java/org/apache/archiva/indexer/search/NexusRepositorySearchTest.java
archiva-modules/archiva-web/archiva-webapp/src/main/java/org/apache/maven/archiva/web/action/SearchAction.java

index ccb973ca4c64434956ef24d72761120cfee0ae38..72bac5f9f1098302b1c42340d6946999dac78aa2 100644 (file)
@@ -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>
\ No newline at end of file
index ff7dac5e24f78956ca9626d179725f24f81c7234..8152361766284de9a56aa4a4b8d0fdd81624f2d3 100644 (file)
@@ -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>
index a5eb3227d78c9037b4c33219fc876bf134a39d38..54d8a7a2a2105b77836885a4623f283bbbb02de7 100644 (file)
           </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>
index a878c58adadb21ecca8030c8712dba8da8922255..04b035002927322316cea52922ec1d321c629c69 100644 (file)
@@ -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() );
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 (file)
index 0000000..8e03700
--- /dev/null
@@ -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>
index 1befe9479e464966dc4ea46517d71401de44ecc8..bc69c7e36827ba3e1c68be8fea568597cad6aa81 100644 (file)
@@ -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>
\ No newline at end of file
index cbdb9c7e52fcf561c43d23f2ec03b3c371411733..4750f0d601a3811e0aff3f2768f192fda80b4c94 100644 (file)
@@ -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 );
index 7db42d166831cbb370c06a610466dcb66f1a799b..9b3cdbe22a70e062a2339fda64b9da1b10d2d696 100644 (file)
@@ -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;
+    }
 }