]> source.dussan.org Git - archiva.git/commitdiff
change lucene query to treat user input as scored value and version as exact value
authorOlivier Lamy <olamy@apache.org>
Fri, 24 Aug 2012 14:27:05 +0000 (14:27 +0000)
committerOlivier Lamy <olamy@apache.org>
Fri, 24 Aug 2012 14:27:05 +0000 (14:27 +0000)
git-svn-id: https://svn.apache.org/repos/asf/archiva/trunk@1376938 13f79535-47bb-0310-9956-ffa450edef68

archiva-modules/archiva-base/archiva-indexer/src/main/java/org/apache/archiva/indexer/search/NexusRepositorySearch.java

index 3d84602aeeab4b4c7590641560b12c31db76a9fa..527d9f08cdc8e03838f6b410ed9c2e63ad9ac0cb 100644 (file)
@@ -40,7 +40,9 @@ import org.apache.maven.index.OSGI;
 import org.apache.maven.index.context.IndexCreator;
 import org.apache.maven.index.context.IndexingContext;
 import org.apache.maven.index.context.UnsupportedExistingLuceneIndexException;
+import org.apache.maven.index.expr.SourcedSearchExpression;
 import org.apache.maven.index.expr.StringSearchExpression;
+import org.apache.maven.index.expr.UserInputSearchExpression;
 import org.slf4j.Logger;
 import org.slf4j.LoggerFactory;
 import org.springframework.stereotype.Service;
@@ -152,95 +154,95 @@ public class NexusRepositorySearch
         BooleanQuery q = new BooleanQuery();
         if ( StringUtils.isNotBlank( searchFields.getGroupId() ) )
         {
-            q.add( indexer.constructQuery( MAVEN.GROUP_ID, new StringSearchExpression( searchFields.getGroupId() ) ),
+            q.add( indexer.constructQuery( MAVEN.GROUP_ID, new UserInputSearchExpression( searchFields.getGroupId() ) ),
                    Occur.MUST );
         }
 
         if ( StringUtils.isNotBlank( searchFields.getArtifactId() ) )
         {
             q.add(
-                indexer.constructQuery( MAVEN.ARTIFACT_ID, new StringSearchExpression( searchFields.getArtifactId() ) ),
+                indexer.constructQuery( MAVEN.ARTIFACT_ID, new UserInputSearchExpression( searchFields.getArtifactId() ) ),
                 Occur.MUST );
         }
 
         if ( StringUtils.isNotBlank( searchFields.getVersion() ) )
         {
-            q.add( indexer.constructQuery( MAVEN.VERSION, new StringSearchExpression( searchFields.getVersion() ) ),
+            q.add( indexer.constructQuery( MAVEN.VERSION, new SourcedSearchExpression( searchFields.getVersion() ) ),
                    Occur.MUST );
         }
 
         if ( StringUtils.isNotBlank( searchFields.getPackaging() ) )
         {
-            q.add( indexer.constructQuery( MAVEN.PACKAGING, new StringSearchExpression( searchFields.getPackaging() ) ),
+            q.add( indexer.constructQuery( MAVEN.PACKAGING, new UserInputSearchExpression( searchFields.getPackaging() ) ),
                    Occur.MUST );
         }
 
         if ( StringUtils.isNotBlank( searchFields.getClassName() ) )
         {
             q.add(
-                indexer.constructQuery( MAVEN.CLASSNAMES, new StringSearchExpression( searchFields.getClassName() ) ),
+                indexer.constructQuery( MAVEN.CLASSNAMES, new UserInputSearchExpression( searchFields.getClassName() ) ),
                 Occur.MUST );
         }
 
         if ( StringUtils.isNotBlank( searchFields.getBundleSymbolicName() ) )
         {
             q.add( indexer.constructQuery( OSGI.SYMBOLIC_NAME,
-                                           new StringSearchExpression( searchFields.getBundleSymbolicName() ) ),
+                                           new UserInputSearchExpression( searchFields.getBundleSymbolicName() ) ),
                    Occur.MUST );
         }
 
         if ( StringUtils.isNotBlank( searchFields.getBundleVersion() ) )
         {
             q.add(
-                indexer.constructQuery( OSGI.VERSION, new StringSearchExpression( searchFields.getBundleVersion() ) ),
+                indexer.constructQuery( OSGI.VERSION, new UserInputSearchExpression( searchFields.getBundleVersion() ) ),
                 Occur.MUST );
         }
 
         if ( StringUtils.isNotBlank( searchFields.getBundleExportPackage() ) )
         {
             q.add( indexer.constructQuery( OSGI.EXPORT_PACKAGE,
-                                           new StringSearchExpression( searchFields.getBundleExportPackage() ) ),
+                                           new UserInputSearchExpression( searchFields.getBundleExportPackage() ) ),
                    Occur.MUST );
         }
 
         if ( StringUtils.isNotBlank( searchFields.getBundleExportService() ) )
         {
             q.add( indexer.constructQuery( OSGI.EXPORT_SERVICE,
-                                           new StringSearchExpression( searchFields.getBundleExportService() ) ),
+                                           new UserInputSearchExpression( searchFields.getBundleExportService() ) ),
                    Occur.MUST );
         }
 
         if ( StringUtils.isNotBlank( searchFields.getBundleImportPackage() ) )
         {
             q.add( indexer.constructQuery( OSGI.IMPORT_PACKAGE,
-                                           new StringSearchExpression( searchFields.getBundleImportPackage() ) ),
+                                           new UserInputSearchExpression( searchFields.getBundleImportPackage() ) ),
                    Occur.MUST );
         }
 
         if ( StringUtils.isNotBlank( searchFields.getBundleName() ) )
         {
-            q.add( indexer.constructQuery( OSGI.NAME, new StringSearchExpression( searchFields.getBundleName() ) ),
+            q.add( indexer.constructQuery( OSGI.NAME, new UserInputSearchExpression( searchFields.getBundleName() ) ),
                    Occur.MUST );
         }
 
         if ( StringUtils.isNotBlank( searchFields.getBundleImportPackage() ) )
         {
             q.add( indexer.constructQuery( OSGI.IMPORT_PACKAGE,
-                                           new StringSearchExpression( searchFields.getBundleImportPackage() ) ),
+                                           new UserInputSearchExpression( searchFields.getBundleImportPackage() ) ),
                    Occur.MUST );
         }
 
         if ( StringUtils.isNotBlank( searchFields.getBundleRequireBundle() ) )
         {
             q.add( indexer.constructQuery( OSGI.REQUIRE_BUNDLE,
-                                           new StringSearchExpression( searchFields.getBundleRequireBundle() ) ),
+                                           new UserInputSearchExpression( searchFields.getBundleRequireBundle() ) ),
                    Occur.MUST );
         }
 
         if ( StringUtils.isNotBlank( searchFields.getClassifier() ) )
         {
             q.add(
-                indexer.constructQuery( MAVEN.CLASSIFIER, new StringSearchExpression( searchFields.getClassifier() ) ),
+                indexer.constructQuery( MAVEN.CLASSIFIER, new UserInputSearchExpression( searchFields.getClassifier() ) ),
                 Occur.MUST );
         }
 
@@ -308,11 +310,11 @@ public class NexusRepositorySearch
 
     private void constructQuery( String term, BooleanQuery q )
     {
-        q.add( indexer.constructQuery( MAVEN.GROUP_ID, new StringSearchExpression( term ) ), Occur.SHOULD );
-        q.add( indexer.constructQuery( MAVEN.ARTIFACT_ID, new StringSearchExpression( term ) ), Occur.SHOULD );
-        q.add( indexer.constructQuery( MAVEN.VERSION, new StringSearchExpression( term ) ), Occur.SHOULD );
-        q.add( indexer.constructQuery( MAVEN.PACKAGING, new StringSearchExpression( term ) ), Occur.SHOULD );
-        q.add( indexer.constructQuery( MAVEN.CLASSNAMES, new StringSearchExpression( term ) ), Occur.SHOULD );
+        q.add( indexer.constructQuery( MAVEN.GROUP_ID, new UserInputSearchExpression( term ) ), Occur.SHOULD );
+        q.add( indexer.constructQuery( MAVEN.ARTIFACT_ID, new UserInputSearchExpression( term ) ), Occur.SHOULD );
+        q.add( indexer.constructQuery( MAVEN.VERSION, new UserInputSearchExpression( term ) ), Occur.SHOULD );
+        q.add( indexer.constructQuery( MAVEN.PACKAGING, new UserInputSearchExpression( term ) ), Occur.SHOULD );
+        q.add( indexer.constructQuery( MAVEN.CLASSNAMES, new UserInputSearchExpression( term ) ), Occur.SHOULD );
 
         //Query query =
         //    new WildcardQuery( new Term( MAVEN.CLASSNAMES.getFieldName(), "*" ) );