--- /dev/null
+package org.apache.archiva.indexer.search;
+/*
+ * 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.
+ */
+
+import org.apache.maven.index.ArtifactInfo;
+
+import java.util.Map;
+
+/**
+ * @author Olivier Lamy
+ * @since 1.4
+ */
+public interface ArtifactInfoFiler
+{
+ boolean addArtifactInResult( ArtifactInfo artifact, Map<String, SearchResultHit> currentResult );
+}
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;
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 );
+
}
/**
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
{
return results;
}
- return convertToSearchResults( response, limits );
+ return convertToSearchResults( response, limits, filters );
}
catch ( IOException e )
{
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 );
}
}
- 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();
artifactInfo.packaging );
Map<String, SearchResultHit> hitsMap = results.getHitsMap();
+ if ( !applyArtifactInfoFilters( artifactInfo, artifactInfoFilers, hitsMap ) )
+ {
+ continue;
+ }
+
SearchResultHit hit = hitsMap.get( id );
if ( hit != null )
{
}
}
+ 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();
--- /dev/null
+package org.apache.archiva.indexer.search;
+/*
+ * 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.
+ */
+
+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 NoClassifierArtifactInfoFiler
+ implements ArtifactInfoFiler
+{
+ public static final NoClassifierArtifactInfoFiler INSTANCE = new NoClassifierArtifactInfoFiler();
+
+ public static final List<? extends ArtifactInfoFiler> LIST = Arrays.asList( INSTANCE );
+
+ public boolean addArtifactInResult( ArtifactInfo artifact, Map<String, SearchResultHit> currentResult )
+ {
+ return StringUtils.isBlank( artifact.classifier );
+ }
+}
//TODO: search for class & package names
}
+ @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
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;
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 )
try
{
SearchResults searchResults = repositorySearch.search( getPrincipal(), searchField, null );
- return getArtifacts( searchResults, Collections.<ArtifactFiler>emptyList() );
+ return getArtifacts( searchResults );
}
catch ( RepositorySearchException e )
{
try
{
SearchResults searchResults = repositorySearch.search( getPrincipal(), searchField, limits );
- return getArtifacts( searchResults, Collections.<ArtifactFiler>emptyList() );
+ return getArtifacts( searchResults );
}
catch ( RepositorySearchException e )
{
: redbackRequestInformation.getUser().getUsername() );
}
- protected List<Artifact> getArtifacts( SearchResults searchResults, List<ArtifactFiler> artifactFilers )
+ protected List<Artifact> getArtifacts( SearchResults searchResults )
{
if ( searchResults == null || searchResults.isEmpty() )
{
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;
- }
}
+++ /dev/null
-package org.apache.archiva.rest.services.searchfilter;
-/*
- * 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.
- */
-
-import org.apache.archiva.rest.api.model.Artifact;
-
-import java.util.List;
-
-/**
- * @author Olivier Lamy
- * @since 1.4
- */
-public interface ArtifactFiler
-{
- boolean addArtifactInResult( Artifact artifact, List<Artifact> currentResult );
-}
+++ /dev/null
-package org.apache.archiva.rest.services.searchfilter;
-/*
- * 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.
- */
-
-import com.sun.org.apache.bcel.internal.generic.INSTANCEOF;
-import org.apache.archiva.rest.api.model.Artifact;
-import org.apache.commons.lang.StringUtils;
-
-import java.util.Arrays;
-import java.util.List;
-
-/**
- * @author Olivier Lamy
- */
-public class NoClassifierArtifactFiler
- implements ArtifactFiler
-{
- public static final NoClassifierArtifactFiler INSTANCE = new NoClassifierArtifactFiler();
-
- public static final List<? extends ArtifactFiler> LIST = Arrays.asList( INSTANCE );
-
- public boolean addArtifactInResult( Artifact artifact, List<Artifact> currentResult )
- {
- return StringUtils.isBlank( artifact.getClassifier() );
- }
-}