aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorOlivier Lamy <olamy@apache.org>2011-09-15 15:45:49 +0000
committerOlivier Lamy <olamy@apache.org>2011-09-15 15:45:49 +0000
commit4579f684aa761897191c06736b7fd4f12b2e1369 (patch)
treef9ec58d4aa5b4177a78ec6904e302decaeb7a4cb
parent4298c23f6d50cde1b1737454c218c597f2415042 (diff)
downloadarchiva-4579f684aa761897191c06736b7fd4f12b2e1369.tar.gz
archiva-4579f684aa761897191c06736b7fd4f12b2e1369.zip
fix quick search which returns artifacts with classifier too : hackhish solution currently as I can't find a way to say in a Lucene query this field must empty or null
git-svn-id: https://svn.apache.org/repos/asf/archiva/trunk@1171151 13f79535-47bb-0310-9956-ffa450edef68
-rw-r--r--archiva-modules/archiva-base/archiva-indexer/src/main/java/org/apache/archiva/indexer/search/ArtifactInfoFiler.java (renamed from archiva-modules/archiva-web/archiva-rest/archiva-rest-services/src/main/java/org/apache/archiva/rest/services/searchfilter/ArtifactFiler.java)10
-rw-r--r--archiva-modules/archiva-base/archiva-indexer/src/main/java/org/apache/archiva/indexer/search/NexusRepositorySearch.java44
-rw-r--r--archiva-modules/archiva-base/archiva-indexer/src/main/java/org/apache/archiva/indexer/search/NoClassifierArtifactInfoFiler.java (renamed from archiva-modules/archiva-web/archiva-rest/archiva-rest-services/src/main/java/org/apache/archiva/rest/services/searchfilter/NoClassifierArtifactFiler.java)18
-rw-r--r--archiva-modules/archiva-base/archiva-indexer/src/test/java/org/apache/archiva/indexer/search/NexusRepositorySearchTest.java43
-rw-r--r--archiva-modules/archiva-web/archiva-rest/archiva-rest-services/src/main/java/org/apache/archiva/rest/services/DefaultSearchService.java35
5 files changed, 102 insertions, 48 deletions
diff --git a/archiva-modules/archiva-web/archiva-rest/archiva-rest-services/src/main/java/org/apache/archiva/rest/services/searchfilter/ArtifactFiler.java b/archiva-modules/archiva-base/archiva-indexer/src/main/java/org/apache/archiva/indexer/search/ArtifactInfoFiler.java
index b07071ef7..432580055 100644
--- a/archiva-modules/archiva-web/archiva-rest/archiva-rest-services/src/main/java/org/apache/archiva/rest/services/searchfilter/ArtifactFiler.java
+++ b/archiva-modules/archiva-base/archiva-indexer/src/main/java/org/apache/archiva/indexer/search/ArtifactInfoFiler.java
@@ -1,4 +1,4 @@
-package org.apache.archiva.rest.services.searchfilter;
+package org.apache.archiva.indexer.search;
/*
* Licensed to the Apache Software Foundation (ASF) under one
* or more contributor license agreements. See the NOTICE file
@@ -18,15 +18,15 @@ package org.apache.archiva.rest.services.searchfilter;
* under the License.
*/
-import org.apache.archiva.rest.api.model.Artifact;
+import org.apache.maven.index.ArtifactInfo;
-import java.util.List;
+import java.util.Map;
/**
* @author Olivier Lamy
* @since 1.4
*/
-public interface ArtifactFiler
+public interface ArtifactInfoFiler
{
- boolean addArtifactInResult( Artifact artifact, List<Artifact> currentResult );
+ boolean addArtifactInResult( ArtifactInfo artifact, Map<String, SearchResultHit> currentResult );
}
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 5ffba7f88..cdc906c22 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
@@ -47,6 +47,7 @@ import javax.inject.Inject;
import java.io.File;
import java.io.IOException;
import java.util.ArrayList;
+import java.util.Collections;
import java.util.List;
import java.util.Map;
import java.util.Set;
@@ -110,7 +111,10 @@ public class NexusRepositorySearch
q.add( iQuery, Occur.MUST );
}
- return search( limits, q, indexingContextIds );
+ // we retun only artifacts without classifier in quick search, olamy cannot find a way to say with this field empty
+ // FIXME cannot find a way currently to setup this in constructQuery !!!
+ return search( limits, q, indexingContextIds, NoClassifierArtifactInfoFiler.LIST );
+
}
/**
@@ -199,10 +203,11 @@ public class NexusRepositorySearch
throw new RepositorySearchException( "No search fields set." );
}
- return search( limits, q, indexingContextIds );
+ return search( limits, q, indexingContextIds, Collections.<ArtifactInfoFiler>emptyList() );
}
- private SearchResults search( SearchResultLimits limits, BooleanQuery q, List<String> indexingContextIds )
+ private SearchResults search( SearchResultLimits limits, BooleanQuery q, List<String> indexingContextIds,
+ List<? extends ArtifactInfoFiler> filters )
throws RepositorySearchException
{
@@ -219,7 +224,7 @@ public class NexusRepositorySearch
return results;
}
- return convertToSearchResults( response, limits );
+ return convertToSearchResults( response, limits, filters );
}
catch ( IOException e )
{
@@ -275,6 +280,10 @@ public class NexusRepositorySearch
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 );
+
+ //Query query =
+ // new WildcardQuery( new Term( MAVEN.CLASSNAMES.getFieldName(), "*" ) );
+ //q.add( query, Occur.MUST_NOT );
// olamy IMHO we could set this option as at least one must match
//q.setMinimumNumberShouldMatch( 1 );
}
@@ -363,7 +372,8 @@ public class NexusRepositorySearch
}
- private SearchResults convertToSearchResults( FlatSearchResponse response, SearchResultLimits limits )
+ private SearchResults convertToSearchResults( FlatSearchResponse response, SearchResultLimits limits,
+ List<? extends ArtifactInfoFiler> artifactInfoFilers )
{
SearchResults results = new SearchResults();
Set<ArtifactInfo> artifactInfos = response.getResults();
@@ -374,6 +384,11 @@ public class NexusRepositorySearch
artifactInfo.packaging );
Map<String, SearchResultHit> hitsMap = results.getHitsMap();
+ if ( !applyArtifactInfoFilters( artifactInfo, artifactInfoFilers, hitsMap ) )
+ {
+ continue;
+ }
+
SearchResultHit hit = hitsMap.get( id );
if ( hit != null )
{
@@ -428,6 +443,25 @@ public class NexusRepositorySearch
}
}
+ private boolean applyArtifactInfoFilters( ArtifactInfo artifactInfo,
+ List<? extends ArtifactInfoFiler> artifactInfoFilers,
+ Map<String, SearchResultHit> currentResult )
+ {
+ if ( artifactInfoFilers == null || artifactInfoFilers.isEmpty() )
+ {
+ return true;
+ }
+
+ for ( ArtifactInfoFiler filter : artifactInfoFilers )
+ {
+ if ( !filter.addArtifactInResult( artifactInfo, currentResult ) )
+ {
+ return false;
+ }
+ }
+ return true;
+ }
+
private SearchResults paginate( SearchResults results )
{
SearchResultLimits limits = results.getLimits();
diff --git a/archiva-modules/archiva-web/archiva-rest/archiva-rest-services/src/main/java/org/apache/archiva/rest/services/searchfilter/NoClassifierArtifactFiler.java b/archiva-modules/archiva-base/archiva-indexer/src/main/java/org/apache/archiva/indexer/search/NoClassifierArtifactInfoFiler.java
index 7a92b124c..078970299 100644
--- a/archiva-modules/archiva-web/archiva-rest/archiva-rest-services/src/main/java/org/apache/archiva/rest/services/searchfilter/NoClassifierArtifactFiler.java
+++ b/archiva-modules/archiva-base/archiva-indexer/src/main/java/org/apache/archiva/indexer/search/NoClassifierArtifactInfoFiler.java
@@ -1,4 +1,4 @@
-package org.apache.archiva.rest.services.searchfilter;
+package org.apache.archiva.indexer.search;
/*
* Licensed to the Apache Software Foundation (ASF) under one
* or more contributor license agreements. See the NOTICE file
@@ -18,25 +18,25 @@ package org.apache.archiva.rest.services.searchfilter;
* under the License.
*/
-import com.sun.org.apache.bcel.internal.generic.INSTANCEOF;
-import org.apache.archiva.rest.api.model.Artifact;
import org.apache.commons.lang.StringUtils;
+import org.apache.maven.index.ArtifactInfo;
import java.util.Arrays;
import java.util.List;
+import java.util.Map;
/**
* @author Olivier Lamy
*/
-public class NoClassifierArtifactFiler
- implements ArtifactFiler
+public class NoClassifierArtifactInfoFiler
+ implements ArtifactInfoFiler
{
- public static final NoClassifierArtifactFiler INSTANCE = new NoClassifierArtifactFiler();
+ public static final NoClassifierArtifactInfoFiler INSTANCE = new NoClassifierArtifactInfoFiler();
- public static final List<? extends ArtifactFiler> LIST = Arrays.asList( INSTANCE );
+ public static final List<? extends ArtifactInfoFiler> LIST = Arrays.asList( INSTANCE );
- public boolean addArtifactInResult( Artifact artifact, List<Artifact> currentResult )
+ public boolean addArtifactInResult( ArtifactInfo artifact, Map<String, SearchResultHit> currentResult )
{
- return StringUtils.isBlank( artifact.getClassifier() );
+ return StringUtils.isBlank( artifact.classifier );
}
}
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 fb6f4ae0d..2f7da7585 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
@@ -132,6 +132,49 @@ public class NexusRepositorySearchTest
}
@Test
+ public void testQuickSearchNotWithClassifier()
+ throws Exception
+ {
+ createSimpleIndex( true );
+
+ List<String> selectedRepos = Arrays.asList( TEST_REPO_1 );
+
+ // search artifactId
+ archivaConfigControl.expectAndReturn( archivaConfig.getConfiguration(), config );
+
+ archivaConfigControl.replay();
+
+ SearchResults results = search.search( "user", selectedRepos, "archiva-search", null, null );
+
+ archivaConfigControl.verify();
+
+ assertNotNull( results );
+
+ SearchResultHit hit =
+ results.getSearchResultHit( SearchUtil.getHitId( "org.apache.archiva", "archiva-search", null, "jar" ) );
+ assertNotNull( "hit null in result " + results.getHits(), hit );
+ assertEquals( "org.apache.archiva", hit.getGroupId() );
+ assertEquals( "archiva-search", hit.getArtifactId() );
+ assertEquals( "1.0", hit.getVersions().get( 0 ) );
+
+ archivaConfigControl.reset();
+
+ // search groupId
+ archivaConfigControl.expectAndReturn( archivaConfig.getConfiguration(), config );
+
+ archivaConfigControl.replay();
+
+ results = search.search( "user", selectedRepos, "archiva-search", null, null );
+
+ archivaConfigControl.verify();
+
+ assertNotNull( results );
+ assertEquals( "total hints not 3 hits " + results.getHits(), 3, results.getTotalHits() );
+
+ //TODO: search for class & package names
+ }
+
+ @Test
public void testQuickSearchMultipleArtifactsSameVersion()
throws Exception
{
diff --git a/archiva-modules/archiva-web/archiva-rest/archiva-rest-services/src/main/java/org/apache/archiva/rest/services/DefaultSearchService.java b/archiva-modules/archiva-web/archiva-rest/archiva-rest-services/src/main/java/org/apache/archiva/rest/services/DefaultSearchService.java
index 744842389..3f79041d1 100644
--- a/archiva-modules/archiva-web/archiva-rest/archiva-rest-services/src/main/java/org/apache/archiva/rest/services/DefaultSearchService.java
+++ b/archiva-modules/archiva-web/archiva-rest/archiva-rest-services/src/main/java/org/apache/archiva/rest/services/DefaultSearchService.java
@@ -30,8 +30,6 @@ import org.apache.archiva.rest.api.model.Dependency;
import org.apache.archiva.rest.api.model.SearchRequest;
import org.apache.archiva.rest.api.services.ArchivaRestServiceException;
import org.apache.archiva.rest.api.services.SearchService;
-import org.apache.archiva.rest.services.searchfilter.ArtifactFiler;
-import org.apache.archiva.rest.services.searchfilter.NoClassifierArtifactFiler;
import org.apache.archiva.security.AccessDeniedException;
import org.apache.archiva.security.ArchivaSecurityException;
import org.apache.archiva.security.PrincipalNotFoundException;
@@ -80,7 +78,7 @@ public class DefaultSearchService
SearchResults searchResults =
repositorySearch.search( getPrincipal(), getObservableRepos(), queryString, limits,
Collections.<String>emptyList() );
- return getArtifacts( searchResults, new ArrayList<ArtifactFiler>( NoClassifierArtifactFiler.LIST ) );
+ return getArtifacts( searchResults);
}
catch ( RepositorySearchException e )
@@ -105,7 +103,7 @@ public class DefaultSearchService
try
{
SearchResults searchResults = repositorySearch.search( getPrincipal(), searchField, null );
- return getArtifacts( searchResults, Collections.<ArtifactFiler>emptyList() );
+ return getArtifacts( searchResults );
}
catch ( RepositorySearchException e )
{
@@ -127,7 +125,7 @@ public class DefaultSearchService
try
{
SearchResults searchResults = repositorySearch.search( getPrincipal(), searchField, limits );
- return getArtifacts( searchResults, Collections.<ArtifactFiler>emptyList() );
+ return getArtifacts( searchResults );
}
catch ( RepositorySearchException e )
{
@@ -182,7 +180,7 @@ public class DefaultSearchService
: redbackRequestInformation.getUser().getUsername() );
}
- protected List<Artifact> getArtifacts( SearchResults searchResults, List<ArtifactFiler> artifactFilers )
+ protected List<Artifact> getArtifacts( SearchResults searchResults )
{
if ( searchResults == null || searchResults.isEmpty() )
{
@@ -226,34 +224,13 @@ public class DefaultSearchService
if ( StringUtils.isNotBlank( version ) )
{
versionned.setVersion( version );
- if ( applyFiltering( versionned, artifactFilers, artifacts ) )
- {
+
artifacts.add( versionned );
- }
+
}
}
}
}
return artifacts;
}
-
- protected boolean applyFiltering( Artifact artifact, List<ArtifactFiler> artifactFilers, List<Artifact> artifacts )
- {
- if ( artifact == null )
- {
- return false;
- }
- if ( artifactFilers == null || artifactFilers.isEmpty() )
- {
- return true;
- }
- for ( ArtifactFiler filter : artifactFilers )
- {
- if ( !filter.addArtifactInResult( artifact, artifacts ) )
- {
- return false;
- }
- }
- return true;
- }
}