[MRM-118] refactor the searchers into components any make them thread safe

git-svn-id: https://svn.apache.org/repos/asf/maven/repository-manager/trunk@412642 13f79535-47bb-0310-9956-ffa450edef68
This commit is contained in:
Brett Porter 2006-06-08 03:54:06 +00:00
parent 2ace38a72f
commit eba7bf274a
14 changed files with 600 additions and 613 deletions

View File

@ -20,9 +20,9 @@ import org.apache.maven.artifact.repository.ArtifactRepository;
import org.apache.maven.artifact.repository.ArtifactRepositoryFactory; import org.apache.maven.artifact.repository.ArtifactRepositoryFactory;
import org.apache.maven.artifact.repository.layout.ArtifactRepositoryLayout; import org.apache.maven.artifact.repository.layout.ArtifactRepositoryLayout;
import org.apache.maven.repository.indexing.ArtifactRepositoryIndex; import org.apache.maven.repository.indexing.ArtifactRepositoryIndex;
import org.apache.maven.repository.indexing.DefaultRepositoryIndexSearcher;
import org.apache.maven.repository.indexing.RepositoryIndexException; import org.apache.maven.repository.indexing.RepositoryIndexException;
import org.apache.maven.repository.indexing.RepositoryIndexSearchException; import org.apache.maven.repository.indexing.RepositoryIndexSearchException;
import org.apache.maven.repository.indexing.RepositoryIndexSearcher;
import org.apache.maven.repository.indexing.RepositoryIndexingFactory; import org.apache.maven.repository.indexing.RepositoryIndexingFactory;
import org.apache.maven.repository.indexing.query.SinglePhraseQuery; import org.apache.maven.repository.indexing.query.SinglePhraseQuery;
import org.codehaus.classworlds.ClassWorld; import org.codehaus.classworlds.ClassWorld;
@ -67,11 +67,11 @@ public class IndexSearcherCli
ArtifactRepositoryIndex index = ArtifactRepositoryIndex index =
indexFactory.createArtifactRepositoryIndex( new File( args[0], ".index" ).getAbsolutePath(), repository ); indexFactory.createArtifactRepositoryIndex( new File( args[0], ".index" ).getAbsolutePath(), repository );
DefaultRepositoryIndexSearcher searcher = indexFactory.createDefaultRepositoryIndexSearcher( index ); RepositoryIndexSearcher searcher = (RepositoryIndexSearcher) embedder.lookup( RepositoryIndexSearcher.ROLE );
try try
{ {
System.out.println( searcher.search( new SinglePhraseQuery( args[1], args[2] ) ) ); System.out.println( searcher.search( new SinglePhraseQuery( args[1], args[2] ), index ) );
} }
finally finally
{ {

View File

@ -32,21 +32,24 @@ import java.util.Collection;
import java.util.zip.ZipEntry; import java.util.zip.ZipEntry;
/** /**
* Abstract class for RepositoryIndexers * Abstract class for RepositoryIndexers.
* *
* @author Edwin Punzalan * @author Edwin Punzalan
*/ */
public abstract class AbstractRepositoryIndex public abstract class AbstractRepositoryIndex
implements RepositoryIndex implements RepositoryIndex
{ {
// TODO [!] can this be derived from the repository?
private String indexPath; private String indexPath;
private boolean indexOpen; private boolean indexOpen;
// TODO [!] why is the writer open for the life, but not the reader? why keep them open that length of time anyway? investigate best practices in Lucene
private IndexWriter indexWriter; private IndexWriter indexWriter;
protected ArtifactRepository repository; protected ArtifactRepository repository;
// TODO [!] is this really needed externally?
private Analyzer analyzer; private Analyzer analyzer;
/** /**
@ -155,6 +158,7 @@ public abstract class AbstractRepositoryIndex
protected IndexWriter getIndexWriter() protected IndexWriter getIndexWriter()
throws IOException throws IOException
{ {
// TODO [!] why is this allowed to be called before open()?
if ( indexWriter == null ) if ( indexWriter == null )
{ {
indexWriter = new IndexWriter( indexPath, getAnalyzer(), false ); indexWriter = new IndexWriter( indexPath, getAnalyzer(), false );
@ -220,7 +224,7 @@ public abstract class AbstractRepositoryIndex
} }
catch ( IOException ie ) catch ( IOException ie )
{ {
throw new RepositoryIndexException( indexPath + "is not a valid directory." ); throw new RepositoryIndexException( indexPath + " is not a valid directory." );
} }
finally finally
{ {

View File

@ -0,0 +1,412 @@
package org.apache.maven.repository.indexing;
/*
* Copyright 2005-2006 The Apache Software Foundation.
*
* Licensed 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.artifact.Artifact;
import org.apache.maven.artifact.factory.ArtifactFactory;
import org.apache.maven.model.Dependency;
import org.apache.maven.model.License;
import org.apache.maven.model.Model;
import org.apache.maven.model.Plugin;
import org.apache.maven.model.ReportPlugin;
import org.apache.maven.repository.indexing.query.Query;
import org.apache.maven.repository.indexing.query.SinglePhraseQuery;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.Iterator;
import java.util.List;
import java.util.Map;
import java.util.Set;
import java.util.StringTokenizer;
/**
* This class is to be invoked or called by the action class for
* general and advanced searching. It uses the DefaultRepositoryIndexSearcher
* to perform the search and constructs the search result objects to be
* returned to tha webapp action class.
*
* @plexus.component role="org.apache.maven.repository.indexing.RepositoryIndexSearchLayer"
*/
public class DefaultRepositoryIndexSearchLayer
implements RepositoryIndexSearchLayer
{
/**
* @plexus.requirement
*/
private ArtifactFactory factory;
/**
* @plexus.requirement
*/
private RepositoryIndexSearcher searcher;
public List searchGeneral( String keyword, RepositoryIndex index )
throws RepositoryIndexSearchException
{
List generalSearchResults = new ArrayList();
for ( int i = 0; i < RepositoryIndex.FIELDS.length; i++ )
{
Query qry = new SinglePhraseQuery( RepositoryIndex.FIELDS[i], keyword );
List results = searchAdvanced( qry, index );
for ( Iterator iter = results.iterator(); iter.hasNext(); )
{
SearchResult result = (SearchResult) iter.next();
Map map = result.getFieldMatches();
Set entrySet = map.entrySet();
for ( Iterator it = entrySet.iterator(); it.hasNext(); )
{
Map.Entry entry = (Map.Entry) it.next();
SearchResult result2 = createSearchResult( result.getArtifact(), map, keyword,
(String) entry.getKey(), generalSearchResults );
generalSearchResults.add( result2 );
}
}
}
return generalSearchResults;
}
public List searchAdvanced( Query qry, RepositoryIndex index )
throws RepositoryIndexSearchException
{
List searchResults = new ArrayList();
List hits = searcher.search( qry, index );
for ( Iterator it = hits.iterator(); it.hasNext(); )
{
RepositoryIndexSearchHit hit = (RepositoryIndexSearchHit) it.next();
SearchResult result = new SearchResult();
if ( hit.isHashMap() )
{
Map map = (Map) hit.getObject();
result.setArtifact( (Artifact) map.get( RepositoryIndex.ARTIFACT ) );
Map fields = new HashMap();
fields.put( RepositoryIndex.FLD_CLASSES, map.get( RepositoryIndex.FLD_CLASSES ) );
fields.put( RepositoryIndex.FLD_PACKAGES, map.get( RepositoryIndex.FLD_PACKAGES ) );
fields.put( RepositoryIndex.FLD_FILES, map.get( RepositoryIndex.FLD_FILES ) );
fields.put( RepositoryIndex.FLD_PACKAGING, map.get( RepositoryIndex.FLD_PACKAGING ) );
fields.put( RepositoryIndex.FLD_SHA1, map.get( RepositoryIndex.FLD_SHA1 ) );
fields.put( RepositoryIndex.FLD_MD5, map.get( RepositoryIndex.FLD_MD5 ) );
result.setFieldMatches( fields );
searchResults.add( result );
}
else if ( hit.isModel() )
{
Model model = (Model) hit.getObject();
for ( int i = 0; i < RepositoryIndex.MODEL_FIELDS.length; i++ )
{
result = createSearchResult( model, RepositoryIndex.MODEL_FIELDS[i], searchResults );
searchResults.add( result );
}
}
else if ( hit.isMetadata() )
{
//@todo what about metadata objects?
// RepositoryMetadata metadata = (RepositoryMetadata) hit.getObject();
}
}
return searchResults;
}
/**
* Method for checking if the artifact already exists in the search result list.
*
* @param groupId the group id of the artifact
* @param artifactId the artifact id of the artifact
* @param version the version of the artifact
* @return the int index number of the artifact in the search result
*/
private int getListIndex( String groupId, String artifactId, String version, List list )
{
int index = 0;
for ( Iterator iter = list.iterator(); iter.hasNext(); )
{
SearchResult result = (SearchResult) iter.next();
Artifact artifact = result.getArtifact();
if ( artifact.getGroupId().equals( groupId ) && artifact.getArtifactId().equals( artifactId ) &&
artifact.getVersion().equals( version ) )
{
return index;
}
index++;
}
return -1;
}
/**
* Method to create the unique artifact id to represent the artifact in the repository
*
* @param groupId the artifact groupId
* @param artifactId the artifact artifactId
* @param version the artifact version
* @return the String id to uniquely represent the artifact
*/
private String getId( String groupId, String artifactId, String version )
{
return groupId + ":" + artifactId + ":" + version;
}
/**
* Method to get the matching values (packages, classes and files) in the
* given string to be tokenized.
*
* @param tokenizeStr the string to be tokenized
* @param key the map key
* @param resultMap the map to be populated
* @param keyword the value to be matched
* @return the map that contains the matched values
*/
private Map getArtifactHits( String tokenizeStr, String key, Map resultMap, String keyword )
{
List values = new ArrayList();
StringTokenizer st = new StringTokenizer( tokenizeStr, "\n" );
while ( st.hasMoreTokens() )
{
String str = st.nextToken();
if ( str.toLowerCase().indexOf( keyword.toLowerCase() ) != -1 )
{
values.add( str );
}
}
if ( !values.isEmpty() )
{
resultMap.put( key, values );
}
return resultMap;
}
/**
* Method to create SearchResult object from a given HashMap. Used for general search results
*
* @param artifact the retrieved artifact from the index
* @param map the HashMap object that contains the values for the search result
* @param keyword the query term
* @return the SearchResult object
*/
private SearchResult createSearchResult( Artifact artifact, Map map, String keyword, String field,
List generalSearchResults )
{
int index = getListIndex( artifact.getGroupId(), artifact.getArtifactId(), artifact.getVersion(),
generalSearchResults );
SearchResult result;
Map resultMap;
if ( index > -1 )
{
result = (SearchResult) generalSearchResults.remove( index );
resultMap = result.getFieldMatches();
}
else
{
result = new SearchResult();
result.setArtifact( artifact );
resultMap = new HashMap();
}
// the searched field is either the class, package or file field
if ( field.equals( RepositoryIndex.FLD_CLASSES ) || field.equals( RepositoryIndex.FLD_PACKAGES ) ||
field.equals( RepositoryIndex.FLD_FILES ) )
{
resultMap = getArtifactHits( (String) map.get( field ), field, resultMap, keyword );
}
else if ( field.equals( RepositoryIndex.FLD_SHA1 ) ||
( field.equals( RepositoryIndex.FLD_MD5 ) || field.equals( RepositoryIndex.FLD_PACKAGING ) ) )
{
if ( map.get( field ) != null )
{
// the searched field is either the md5, sha1 or packaging field
if ( ( (String) map.get( field ) ).toLowerCase().equals( keyword.toLowerCase() ) ||
( (String) map.get( field ) ).toLowerCase().indexOf( keyword.toLowerCase() ) != -1 )
{
resultMap.put( field, map.get( field ) );
}
}
}
else if ( field.equals( RepositoryIndex.FLD_DEPENDENCIES ) ||
field.equals( RepositoryIndex.FLD_PLUGINS_BUILD ) || field.equals( RepositoryIndex.FLD_PLUGINS_REPORT ) ||
field.equals( RepositoryIndex.FLD_LICENSE_URLS ) )
{
List contents = (List) map.get( field );
List values = new ArrayList();
for ( Iterator it = contents.iterator(); it.hasNext(); )
{
String str = (String) it.next();
if ( str.toLowerCase().equals( keyword.toLowerCase() ) )
{
values.add( str );
}
}
if ( values.size() > 0 )
{
resultMap.put( field, values );
}
}
result.setFieldMatches( resultMap );
return result;
}
/**
* Method to create a SearchResult object from the given model. Used for advanced search results
*
* @param model the Model object that contains the values for the search result
* @param field the field whose value is to be retrieved
* @return a SearchResult object
*/
private SearchResult createSearchResult( Model model, String field, List searchResults )
{
int index = getListIndex( model.getGroupId(), model.getArtifactId(), model.getVersion(), searchResults );
SearchResult result;
Map map;
// the object already exists in the search result list
if ( index > -1 )
{
result = (SearchResult) searchResults.remove( index );
map = result.getFieldMatches();
}
else
{
result = new SearchResult();
result.setArtifact( factory.createBuildArtifact( model.getGroupId(), model.getArtifactId(),
model.getVersion(), model.getPackaging() ) );
map = new HashMap();
}
// get the matched value with the query term
List values = new ArrayList();
if ( field.equals( RepositoryIndex.FLD_LICENSE_URLS ) )
{
values = getLicenseUrls( model );
}
else if ( field.equals( RepositoryIndex.FLD_DEPENDENCIES ) )
{
values = getDependencies( model );
}
else if ( field.equals( RepositoryIndex.FLD_PLUGINS_BUILD ) )
{
if ( model.getBuild() != null && model.getBuild().getPlugins() != null )
{
values = getBuildPlugins( model );
}
}
else if ( field.equals( RepositoryIndex.FLD_PLUGINS_REPORT ) )
{
if ( model.getReporting() != null && model.getReporting().getPlugins() != null )
{
values = getReportPlugins( model );
}
}
else if ( field.equals( RepositoryIndex.FLD_PACKAGING ) )
{
if ( model.getPackaging() != null )
{
map.put( RepositoryIndex.FLD_PACKAGING, model.getPackaging() );
}
}
if ( !values.isEmpty() )
{
map.put( field, values );
}
result.setFieldMatches( map );
return result;
}
/**
* Method for getting the query term hits or matches in the pom's license urls.
*
* @param model the Model object that contains the pom values
* @return a List of matched license urls
*/
private List getLicenseUrls( Model model )
{
List licenseUrls = new ArrayList();
List licenseList = model.getLicenses();
for ( Iterator it = licenseList.iterator(); it.hasNext(); )
{
License license = (License) it.next();
licenseUrls.add( license.getUrl() );
}
return licenseUrls;
}
/**
* Method for getting the hits or matches in the dependencies specified in the pom
*
* @param model the Model object that contains the pom values
* @return a List of matched dependencies
*/
private List getDependencies( Model model )
{
List dependencies = new ArrayList();
List dependencyList = model.getDependencies();
for ( Iterator it = dependencyList.iterator(); it.hasNext(); )
{
Dependency dep = (Dependency) it.next();
dependencies.add( getId( dep.getGroupId(), dep.getArtifactId(), dep.getVersion() ) );
}
return dependencies;
}
/**
* Method for getting the hits or matches in the build plugins specified in the pom
*
* @param model the Model object that contains the pom values
* @return a List of matched build plugins
*/
private List getBuildPlugins( Model model )
{
List values = new ArrayList();
List plugins = model.getBuild().getPlugins();
for ( Iterator it = plugins.iterator(); it.hasNext(); )
{
Plugin plugin = (Plugin) it.next();
values.add( getId( plugin.getGroupId(), plugin.getArtifactId(), plugin.getVersion() ) );
}
return values;
}
/**
* Method for getting the hits or matches in the reporting plugins specified in the pom
*
* @param model the Model object that contains the pom values
* @return a List of matched reporting plugins
*/
private List getReportPlugins( Model model )
{
List values = new ArrayList();
List plugins = model.getReporting().getPlugins();
for ( Iterator it = plugins.iterator(); it.hasNext(); )
{
ReportPlugin plugin = (ReportPlugin) it.next();
values.add( getId( plugin.getGroupId(), plugin.getArtifactId(), plugin.getVersion() ) );
}
return values;
}
}

View File

@ -22,6 +22,7 @@ import org.apache.lucene.search.Hits;
import org.apache.lucene.search.IndexSearcher; import org.apache.lucene.search.IndexSearcher;
import org.apache.maven.artifact.Artifact; import org.apache.maven.artifact.Artifact;
import org.apache.maven.artifact.factory.ArtifactFactory; import org.apache.maven.artifact.factory.ArtifactFactory;
import org.apache.maven.artifact.repository.ArtifactRepository;
import org.apache.maven.artifact.repository.metadata.ArtifactRepositoryMetadata; import org.apache.maven.artifact.repository.metadata.ArtifactRepositoryMetadata;
import org.apache.maven.artifact.repository.metadata.GroupRepositoryMetadata; import org.apache.maven.artifact.repository.metadata.GroupRepositoryMetadata;
import org.apache.maven.artifact.repository.metadata.Metadata; import org.apache.maven.artifact.repository.metadata.Metadata;
@ -50,40 +51,24 @@ import java.util.StringTokenizer;
/** /**
* Implementation Class for searching through the index. * Implementation Class for searching through the index.
* *
* @todo this is not a component, but extends ALE, meaning logging will throw an exception! -- should be a component * @plexus.component role="org.apache.maven.repository.indexing.RepositoryIndexSearcher"
*/ */
public class DefaultRepositoryIndexSearcher public class DefaultRepositoryIndexSearcher
extends AbstractLogEnabled extends AbstractLogEnabled
implements RepositoryIndexSearcher implements RepositoryIndexSearcher
{ {
protected RepositoryIndex index; /**
* @plexus.requirement
*/
private ArtifactFactory factory; private ArtifactFactory factory;
private List artifactList; public List search( Query query, RepositoryIndex index )
/**
* Constructor
*
* @param index the index object
*/
protected DefaultRepositoryIndexSearcher( RepositoryIndex index, ArtifactFactory factory )
{
this.index = index;
this.factory = factory;
}
/**
* @see RepositoryIndexSearcher#search(org.apache.maven.repository.indexing.query.Query)
*/
public List search( Query query )
throws RepositoryIndexSearchException throws RepositoryIndexSearchException
{ {
artifactList = new ArrayList();
org.apache.lucene.search.Query luceneQuery; org.apache.lucene.search.Query luceneQuery;
try try
{ {
luceneQuery = createLuceneQuery( query ); luceneQuery = query.createLuceneQuery( index );
} }
catch ( ParseException e ) catch ( ParseException e )
{ {
@ -100,11 +85,15 @@ public class DefaultRepositoryIndexSearcher
throw new RepositoryIndexSearchException( "Unable to open index: " + e.getMessage(), e ); throw new RepositoryIndexSearchException( "Unable to open index: " + e.getMessage(), e );
} }
List docs; List docs = new ArrayList();
try try
{ {
Hits hits = searcher.search( luceneQuery ); Hits hits = searcher.search( luceneQuery );
docs = buildList( hits ); for ( int i = 0; i < hits.length(); i++ )
{
Document doc = hits.doc( i );
docs.add( createSearchedObjectFromIndexDocument( doc, index.getRepository() ) );
}
} }
catch ( MalformedURLException e ) catch ( MalformedURLException e )
{ {
@ -129,44 +118,15 @@ public class DefaultRepositoryIndexSearcher
return docs; return docs;
} }
/**
* Method to create a lucene Query object by converting a prepared Query object
*
* @param query the prepared Query object to be converted into a lucene Query object
* @return a lucene Query object to represent the passed Query object
* @throws ParseException
*/
private org.apache.lucene.search.Query createLuceneQuery( Query query )
throws ParseException
{
return query.createLuceneQuery( index );
}
/**
* Create a list of artifact objects from the result set.
*
* @param hits the search result set
* @return List
*/
private List buildList( Hits hits )
throws RepositoryIndexSearchException, IOException
{
for ( int i = 0; i < hits.length(); i++ )
{
Document doc = hits.doc( i );
artifactList.add( createSearchedObjectFromIndexDocument( doc ) );
}
return artifactList;
}
/** /**
* Method for creating the object to be returned for the search * Method for creating the object to be returned for the search
* *
* @param doc the index document where the object field values will be retrieved from * @param doc the index document where the object field values will be retrieved from
* @param repository
* @return Object * @return Object
*/ */
protected RepositoryIndexSearchHit createSearchedObjectFromIndexDocument( Document doc ) protected RepositoryIndexSearchHit createSearchedObjectFromIndexDocument( Document doc,
ArtifactRepository repository )
throws RepositoryIndexSearchException throws RepositoryIndexSearchException
{ {
RepositoryIndexSearchHit searchHit = null; RepositoryIndexSearchHit searchHit = null;
@ -180,8 +140,7 @@ public class DefaultRepositoryIndexSearcher
String packaging = doc.get( RepositoryIndex.FLD_PACKAGING ); String packaging = doc.get( RepositoryIndex.FLD_PACKAGING );
Artifact artifact = factory.createBuildArtifact( groupId, artifactId, version, packaging ); Artifact artifact = factory.createBuildArtifact( groupId, artifactId, version, packaging );
artifact.setFile( artifact.setFile( new File( repository.getBasedir(), repository.pathOf( artifact ) ) );
new File( index.getRepository().getBasedir(), index.getRepository().pathOf( artifact ) ) );
Map map = new HashMap(); Map map = new HashMap();
map.put( RepositoryIndex.ARTIFACT, artifact ); map.put( RepositoryIndex.ARTIFACT, artifact );
@ -201,7 +160,7 @@ public class DefaultRepositoryIndexSearcher
Artifact pomArtifact = factory.createProjectArtifact( groupId, artifactId, version ); Artifact pomArtifact = factory.createProjectArtifact( groupId, artifactId, version );
searchHit = new RepositoryIndexSearchHit( false, false, true ); searchHit = new RepositoryIndexSearchHit( false, false, true );
searchHit.setObject( readPom( pomArtifact ) ); searchHit.setObject( readPom( pomArtifact, repository ) );
} }
// the document is of type metadata // the document is of type metadata
else if ( doc.get( RepositoryIndex.FLD_DOCTYPE ).equals( RepositoryIndex.METADATA ) ) else if ( doc.get( RepositoryIndex.FLD_DOCTYPE ).equals( RepositoryIndex.METADATA ) )
@ -233,7 +192,7 @@ public class DefaultRepositoryIndexSearcher
repoMetadata = new GroupRepositoryMetadata( groupId ); repoMetadata = new GroupRepositoryMetadata( groupId );
} }
repoMetadata.setMetadata( readMetadata( repoMetadata ) ); repoMetadata.setMetadata( readMetadata( repoMetadata, repository ) );
searchHit = new RepositoryIndexSearchHit( false, true, false ); searchHit = new RepositoryIndexSearchHit( false, true, false );
searchHit.setObject( repoMetadata ); searchHit.setObject( repoMetadata );
@ -247,11 +206,10 @@ public class DefaultRepositoryIndexSearcher
* *
* @return RepositoryMetadata * @return RepositoryMetadata
*/ */
private Metadata readMetadata( RepositoryMetadata repoMetadata ) private Metadata readMetadata( RepositoryMetadata repoMetadata, ArtifactRepository repository )
throws RepositoryIndexSearchException throws RepositoryIndexSearchException
{ {
File file = new File( index.getRepository().getBasedir(), File file = new File( repository.getBasedir(), repository.pathOfRemoteRepositoryMetadata( repoMetadata ) );
index.getRepository().pathOfRemoteRepositoryMetadata( repoMetadata ) );
MetadataXpp3Reader metadataReader = new MetadataXpp3Reader(); MetadataXpp3Reader metadataReader = new MetadataXpp3Reader();
@ -284,10 +242,10 @@ public class DefaultRepositoryIndexSearcher
* *
* @return RepositoryMetadata * @return RepositoryMetadata
*/ */
private Model readPom( Artifact pomArtifact ) private Model readPom( Artifact pomArtifact, ArtifactRepository repository )
throws RepositoryIndexSearchException throws RepositoryIndexSearchException
{ {
File file = new File( index.getRepository().getBasedir(), index.getRepository().pathOf( pomArtifact ) ); File file = new File( repository.getBasedir(), repository.pathOf( pomArtifact ) );
MavenXpp3Reader r = new MavenXpp3Reader(); MavenXpp3Reader r = new MavenXpp3Reader();

View File

@ -23,7 +23,6 @@ import org.apache.maven.repository.digest.Digester;
/** /**
* @author Edwin Punzalan * @author Edwin Punzalan
* @plexus.component role="org.apache.maven.repository.indexing.RepositoryIndexingFactory" * @plexus.component role="org.apache.maven.repository.indexing.RepositoryIndexingFactory"
* @todo these methods should be replaced by plexus lookups of some kind!
*/ */
public class DefaultRepositoryIndexingFactory public class DefaultRepositoryIndexingFactory
implements RepositoryIndexingFactory implements RepositoryIndexingFactory
@ -65,20 +64,4 @@ public class DefaultRepositoryIndexingFactory
return new MetadataRepositoryIndex( indexPath, repository ); return new MetadataRepositoryIndex( indexPath, repository );
} }
/*
* @see RepositoryIndexingFactory#createRepositoryIndexSearchLayer(RepositoryIndex)
*/
public RepositoryIndexSearchLayer createRepositoryIndexSearchLayer( RepositoryIndex index )
{
return new RepositoryIndexSearchLayer( index, artifactFactory );
}
/**
* @see RepositoryIndexingFactory#createDefaultRepositoryIndexSearcher(RepositoryIndex)
*/
public DefaultRepositoryIndexSearcher createDefaultRepositoryIndexSearcher( RepositoryIndex index )
{
return new DefaultRepositoryIndexSearcher( index, artifactFactory );
}
} }

View File

@ -1,437 +1,60 @@
package org.apache.maven.repository.indexing; package org.apache.maven.repository.indexing;
/* /*
* Copyright 2005-2006 The Apache Software Foundation. * Copyright 2005-2006 The Apache Software Foundation.
* *
* Licensed under the Apache License, Version 2.0 (the "License"); * Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License. * you may not use this file except in compliance with the License.
* You may obtain a copy of the License at * You may obtain a copy of the License at
* *
* http://www.apache.org/licenses/LICENSE-2.0 * http://www.apache.org/licenses/LICENSE-2.0
* *
* Unless required by applicable law or agreed to in writing, software * Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS, * distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and * See the License for the specific language governing permissions and
* limitations under the License. * limitations under the License.
*/ */
import org.apache.maven.artifact.Artifact; import org.apache.maven.repository.indexing.query.Query;
import org.apache.maven.artifact.factory.ArtifactFactory;
import org.apache.maven.model.Dependency; import java.util.List;
import org.apache.maven.model.License;
import org.apache.maven.model.Model; /**
import org.apache.maven.model.Plugin; * Repository search layer.
import org.apache.maven.model.ReportPlugin; *
import org.apache.maven.repository.indexing.query.Query; * @author <a href="mailto:brett@apache.org">Brett Porter</a>
import org.apache.maven.repository.indexing.query.SinglePhraseQuery; */
public interface RepositoryIndexSearchLayer
import java.util.ArrayList; {
import java.util.HashMap; /**
import java.util.Iterator; * The Plexus component role name.
import java.util.List; */
import java.util.Map; String ROLE = RepositoryIndexSearchLayer.class.getName();
import java.util.Set;
import java.util.StringTokenizer; /**
* Method for searching the keyword in all the fields in the index. "Query everything" search.
/** * The index fields will be retrieved and query objects will be constructed using the
* <p/> * optional (OR) CompoundQuery.
* This class is to be invoked or called by the action class for *
* general and advanced searching. It uses the DefaultRepositoryIndexSearcher * @param keyword
* to perform the search and constructs the search result objects to be * @param index
* returned to tha webapp action class. * @return
*/ * @throws RepositoryIndexSearchException
public class RepositoryIndexSearchLayer *
{ */
private RepositoryIndex index; List searchGeneral( String keyword, RepositoryIndex index )
throws RepositoryIndexSearchException;
private ArtifactFactory factory;
/**
private List searchResults; * Method for "advanced search" of the index
*
private List generalSearchResults; * @param qry the query object that will be used for searching the index
* @param index
/** * @return
* Class constructor * @throws RepositoryIndexSearchException
* *
* @param index */
*/ List searchAdvanced( Query qry, RepositoryIndex index )
public RepositoryIndexSearchLayer( RepositoryIndex index, ArtifactFactory factory ) throws RepositoryIndexSearchException;
{ }
this.index = index;
this.factory = factory;
}
/**
* Method for searching the keyword in all the fields in the index. "Query everything" search.
* The index fields will be retrieved and query objects will be constructed using the
* optional (OR) CompoundQuery.
*
* @param keyword
* @return
* @throws RepositoryIndexSearchException
*/
public List searchGeneral( String keyword )
throws RepositoryIndexSearchException
{
generalSearchResults = new ArrayList();
for ( int i = 0; i < RepositoryIndex.FIELDS.length; i++ )
{
Query qry = new SinglePhraseQuery( RepositoryIndex.FIELDS[i], keyword );
List results = searchAdvanced( qry );
for ( Iterator iter = results.iterator(); iter.hasNext(); )
{
SearchResult result = (SearchResult) iter.next();
Map map = result.getFieldMatches();
Set entrySet = map.entrySet();
for ( Iterator it = entrySet.iterator(); it.hasNext(); )
{
Map.Entry entry = (Map.Entry) it.next();
SearchResult result2 =
createSearchResult( result.getArtifact(), map, keyword, (String) entry.getKey() );
generalSearchResults.add( result2 );
}
}
}
return generalSearchResults;
}
/**
* Method for "advanced search" of the index
*
* @param qry the query object that will be used for searching the index
* @return
* @throws RepositoryIndexSearchException
*/
public List searchAdvanced( Query qry )
throws RepositoryIndexSearchException
{
RepositoryIndexSearcher searcher = new DefaultRepositoryIndexSearcher( index, factory );
searchResults = new ArrayList();
List hits = searcher.search( qry );
for ( Iterator it = hits.iterator(); it.hasNext(); )
{
RepositoryIndexSearchHit hit = (RepositoryIndexSearchHit) it.next();
SearchResult result = new SearchResult();
if ( hit.isHashMap() )
{
Map map = (Map) hit.getObject();
result.setArtifact( (Artifact) map.get( RepositoryIndex.ARTIFACT ) );
Map fields = new HashMap();
fields.put( RepositoryIndex.FLD_CLASSES, map.get( RepositoryIndex.FLD_CLASSES ) );
fields.put( RepositoryIndex.FLD_PACKAGES, map.get( RepositoryIndex.FLD_PACKAGES ) );
fields.put( RepositoryIndex.FLD_FILES, map.get( RepositoryIndex.FLD_FILES ) );
fields.put( RepositoryIndex.FLD_PACKAGING, map.get( RepositoryIndex.FLD_PACKAGING ) );
fields.put( RepositoryIndex.FLD_SHA1, map.get( RepositoryIndex.FLD_SHA1 ) );
fields.put( RepositoryIndex.FLD_MD5, map.get( RepositoryIndex.FLD_MD5 ) );
result.setFieldMatches( fields );
searchResults.add( result );
}
else if ( hit.isModel() )
{
Model model = (Model) hit.getObject();
for ( int i = 0; i < RepositoryIndex.MODEL_FIELDS.length; i++ )
{
result = createSearchResult( model, RepositoryIndex.MODEL_FIELDS[i] );
searchResults.add( result );
}
}
else if ( hit.isMetadata() )
{
//@todo what about metadata objects?
// RepositoryMetadata metadata = (RepositoryMetadata) hit.getObject();
}
}
return searchResults;
}
/**
* Method for checking if the artifact already exists in the search result list.
*
* @param groupId the group id of the artifact
* @param artifactId the artifact id of the artifact
* @param version the version of the artifact
* @return the int index number of the artifact in the search result
*/
private int getListIndex( String groupId, String artifactId, String version, List list )
{
int index = 0;
for ( Iterator iter = list.iterator(); iter.hasNext(); )
{
SearchResult result = (SearchResult) iter.next();
Artifact artifact = result.getArtifact();
if ( artifact.getGroupId().equals( groupId ) && artifact.getArtifactId().equals( artifactId ) &&
artifact.getVersion().equals( version ) )
{
return index;
}
index++;
}
return -1;
}
/**
* Method to create the unique artifact id to represent the artifact in the repository
*
* @param groupId the artifact groupId
* @param artifactId the artifact artifactId
* @param version the artifact version
* @return the String id to uniquely represent the artifact
*/
private String getId( String groupId, String artifactId, String version )
{
return groupId + ":" + artifactId + ":" + version;
}
/**
* Method to get the matching values (packages, classes and files) in the
* given string to be tokenized.
*
* @param tokenizeStr the string to be tokenized
* @param key the map key
* @param resultMap the map to be populated
* @param keyword the value to be matched
* @return the map that contains the matched values
*/
private Map getArtifactHits( String tokenizeStr, String key, Map resultMap, String keyword )
{
List values = new ArrayList();
StringTokenizer st = new StringTokenizer( tokenizeStr, "\n" );
while ( st.hasMoreTokens() )
{
String str = st.nextToken();
if ( str.toLowerCase().indexOf( keyword.toLowerCase() ) != -1 )
{
values.add( str );
}
}
if ( !values.isEmpty() )
{
resultMap.put( key, values );
}
return resultMap;
}
/**
* Method to create SearchResult object from a given HashMap. Used for general search results
*
* @param artifact the retrieved artifact from the index
* @param map the HashMap object that contains the values for the search result
* @param keyword the query term
* @return the SearchResult object
*/
private SearchResult createSearchResult( Artifact artifact, Map map, String keyword, String field )
{
int index = getListIndex( artifact.getGroupId(), artifact.getArtifactId(), artifact.getVersion(),
generalSearchResults );
SearchResult result;
Map resultMap;
if ( index > -1 )
{
result = (SearchResult) generalSearchResults.get( index );
generalSearchResults.remove( index );
resultMap = result.getFieldMatches();
}
else
{
result = new SearchResult();
result.setArtifact( artifact );
resultMap = new HashMap();
}
// the searched field is either the class, package or file field
if ( field.equals( RepositoryIndex.FLD_CLASSES ) || field.equals( RepositoryIndex.FLD_PACKAGES ) ||
field.equals( RepositoryIndex.FLD_FILES ) )
{
resultMap = getArtifactHits( (String) map.get( field ), field, resultMap, keyword );
}
else if ( field.equals( RepositoryIndex.FLD_SHA1 ) ||
( field.equals( RepositoryIndex.FLD_MD5 ) || field.equals( RepositoryIndex.FLD_PACKAGING ) ) )
{
if ( map.get( field ) != null )
{
// the searched field is either the md5, sha1 or packaging field
if ( ( (String) map.get( field ) ).toLowerCase().equals( keyword.toLowerCase() ) ||
( (String) map.get( field ) ).toLowerCase().indexOf( keyword.toLowerCase() ) != -1 )
{
resultMap.put( field, map.get( field ) );
}
}
}
else if ( field.equals( RepositoryIndex.FLD_DEPENDENCIES ) ||
field.equals( RepositoryIndex.FLD_PLUGINS_BUILD ) || field.equals( RepositoryIndex.FLD_PLUGINS_REPORT ) ||
field.equals( RepositoryIndex.FLD_LICENSE_URLS ) )
{
List contents = (List) map.get( field );
List values = new ArrayList();
for ( Iterator it = contents.iterator(); it.hasNext(); )
{
String str = (String) it.next();
if ( str.toLowerCase().equals( keyword.toLowerCase() ) )
{
values.add( str );
}
}
if ( values.size() > 0 )
{
resultMap.put( field, values );
}
}
result.setFieldMatches( resultMap );
return result;
}
/**
* Method to create a SearchResult object from the given model. Used for advanced search results
*
* @param model the Model object that contains the values for the search result
* @param field the field whose value is to be retrieved
* @return a SearchResult object
*/
private SearchResult createSearchResult( Model model, String field )
{
int index = getListIndex( model.getGroupId(), model.getArtifactId(), model.getVersion(), searchResults );
SearchResult result;
Map map;
// the object already exists in the search result list
if ( index > -1 )
{
result = (SearchResult) searchResults.get( index );
searchResults.remove( index );
map = result.getFieldMatches();
}
else
{
result = new SearchResult();
result.setArtifact( factory.createBuildArtifact( model.getGroupId(), model.getArtifactId(),
model.getVersion(), model.getPackaging() ) );
map = new HashMap();
}
// get the matched value with the query term
List values = new ArrayList();
if ( field.equals( RepositoryIndex.FLD_LICENSE_URLS ) )
{
values = getLicenseUrls( model );
}
else if ( field.equals( RepositoryIndex.FLD_DEPENDENCIES ) )
{
values = getDependencies( model );
}
else if ( field.equals( RepositoryIndex.FLD_PLUGINS_BUILD ) )
{
if ( model.getBuild() != null && model.getBuild().getPlugins() != null )
{
values = getBuildPlugins( model );
}
}
else if ( field.equals( RepositoryIndex.FLD_PLUGINS_REPORT ) )
{
if ( model.getReporting() != null && model.getReporting().getPlugins() != null )
{
values = getReportPlugins( model );
}
}
else if ( field.equals( RepositoryIndex.FLD_PACKAGING ) )
{
if ( model.getPackaging() != null )
{
map.put( RepositoryIndex.FLD_PACKAGING, model.getPackaging() );
}
}
if ( !values.isEmpty() )
{
map.put( field, values );
}
result.setFieldMatches( map );
return result;
}
/**
* Method for getting the query term hits or matches in the pom's license urls.
*
* @param model the Model object that contains the pom values
* @return a List of matched license urls
*/
private List getLicenseUrls( Model model )
{
List licenseUrls = new ArrayList();
List licenseList = model.getLicenses();
for ( Iterator it = licenseList.iterator(); it.hasNext(); )
{
License license = (License) it.next();
licenseUrls.add( license.getUrl() );
}
return licenseUrls;
}
/**
* Method for getting the hits or matches in the dependencies specified in the pom
*
* @param model the Model object that contains the pom values
* @return a List of matched dependencies
*/
private List getDependencies( Model model )
{
List dependencies = new ArrayList();
List dependencyList = model.getDependencies();
for ( Iterator it = dependencyList.iterator(); it.hasNext(); )
{
Dependency dep = (Dependency) it.next();
dependencies.add( getId( dep.getGroupId(), dep.getArtifactId(), dep.getVersion() ) );
}
return dependencies;
}
/**
* Method for getting the hits or matches in the build plugins specified in the pom
*
* @param model the Model object that contains the pom values
* @return a List of matched build plugins
*/
private List getBuildPlugins( Model model )
{
List values = new ArrayList();
List plugins = model.getBuild().getPlugins();
for ( Iterator it = plugins.iterator(); it.hasNext(); )
{
Plugin plugin = (Plugin) it.next();
values.add( getId( plugin.getGroupId(), plugin.getArtifactId(), plugin.getVersion() ) );
}
return values;
}
/**
* Method for getting the hits or matches in the reporting plugins specified in the pom
*
* @param model the Model object that contains the pom values
* @return a List of matched reporting plugins
*/
private List getReportPlugins( Model model )
{
List values = new ArrayList();
List plugins = model.getReporting().getPlugins();
for ( Iterator it = plugins.iterator(); it.hasNext(); )
{
ReportPlugin plugin = (ReportPlugin) it.next();
values.add( getId( plugin.getGroupId(), plugin.getArtifactId(), plugin.getVersion() ) );
}
return values;
}
}

View File

@ -25,14 +25,20 @@ import java.util.List;
*/ */
public interface RepositoryIndexSearcher public interface RepositoryIndexSearcher
{ {
/**
* Plexus component role name.
*/
String ROLE = RepositoryIndexSearcher.class.getName();
/** /**
* Search the artifact based on the search criteria specified in the query object. Returns a list of * Search the artifact based on the search criteria specified in the query object. Returns a list of
* artifact objects. * artifact objects.
* *
* @param query The query object that contains the search criteria. * @param query The query object that contains the search criteria.
* @param index
* @return List * @return List
* @throws RepositoryIndexSearchException * @throws RepositoryIndexSearchException
*/ */
List search( Query query ) List search( Query query, RepositoryIndex index )
throws RepositoryIndexSearchException; throws RepositoryIndexSearchException;
} }

View File

@ -59,19 +59,4 @@ public interface RepositoryIndexingFactory
MetadataRepositoryIndex createMetadataRepositoryIndex( String indexPath, ArtifactRepository repository ) MetadataRepositoryIndex createMetadataRepositoryIndex( String indexPath, ArtifactRepository repository )
throws RepositoryIndexException; throws RepositoryIndexException;
/**
* Method to create an instance of RepositoryIndexSearchLayer
*
* @param index the RepositoryIndex object where the query string will be searched
* @return the RepositoryIndexSearchLayer instance
*/
RepositoryIndexSearchLayer createRepositoryIndexSearchLayer( RepositoryIndex index );
/**
* Method to create an instance of DefaultRepositoryIndexSearcher
*
* @param index the RepositoryIndex object where the query string will be searched
* @return the DefaultRepositoryIndexSearcher instance
*/
DefaultRepositoryIndexSearcher createDefaultRepositoryIndexSearcher( RepositoryIndex index );
} }

View File

@ -161,12 +161,14 @@ public class ArtifactRepositoryIndexingTest
createTestIndex(); createTestIndex();
RepositoryIndexingFactory factory = (RepositoryIndexingFactory) lookup( RepositoryIndexingFactory.ROLE ); RepositoryIndexingFactory factory = (RepositoryIndexingFactory) lookup( RepositoryIndexingFactory.ROLE );
RepositoryIndexSearchLayer repoSearchLayer =
(RepositoryIndexSearchLayer) lookup( RepositoryIndexSearchLayer.ROLE );
ArtifactRepositoryIndex indexer = factory.createArtifactRepositoryIndex( indexPath, repository ); ArtifactRepositoryIndex indexer = factory.createArtifactRepositoryIndex( indexPath, repository );
RepositoryIndexSearchLayer repoSearchLayer = factory.createRepositoryIndexSearchLayer( indexer );
// search version // search version
Query qry = new SinglePhraseQuery( RepositoryIndex.FLD_VERSION, "1.0" ); Query qry = new SinglePhraseQuery( RepositoryIndex.FLD_VERSION, "1.0" );
List artifacts = repoSearchLayer.searchAdvanced( qry ); List artifacts = repoSearchLayer.searchAdvanced( qry, indexer );
assertEquals( 1, artifacts.size() ); assertEquals( 1, artifacts.size() );
for ( Iterator iter = artifacts.iterator(); iter.hasNext(); ) for ( Iterator iter = artifacts.iterator(); iter.hasNext(); )
{ {
@ -177,7 +179,7 @@ public class ArtifactRepositoryIndexingTest
// search classes // search classes
qry = new SinglePhraseQuery( RepositoryIndex.FLD_CLASSES, "App" ); qry = new SinglePhraseQuery( RepositoryIndex.FLD_CLASSES, "App" );
artifacts = repoSearchLayer.searchAdvanced( qry ); artifacts = repoSearchLayer.searchAdvanced( qry, indexer );
assertEquals( 1, artifacts.size() ); assertEquals( 1, artifacts.size() );
for ( Iterator iter = artifacts.iterator(); iter.hasNext(); ) for ( Iterator iter = artifacts.iterator(); iter.hasNext(); )
{ {
@ -188,7 +190,7 @@ public class ArtifactRepositoryIndexingTest
// search packages // search packages
qry = new SinglePhraseQuery( RepositoryIndex.FLD_PACKAGES, "groupId" ); qry = new SinglePhraseQuery( RepositoryIndex.FLD_PACKAGES, "groupId" );
artifacts = repoSearchLayer.searchAdvanced( qry ); artifacts = repoSearchLayer.searchAdvanced( qry, indexer );
assertEquals( 1, artifacts.size() ); assertEquals( 1, artifacts.size() );
for ( Iterator iter = artifacts.iterator(); iter.hasNext(); ) for ( Iterator iter = artifacts.iterator(); iter.hasNext(); )
{ {
@ -199,7 +201,7 @@ public class ArtifactRepositoryIndexingTest
// search files // search files
qry = new SinglePhraseQuery( RepositoryIndex.FLD_FILES, "pom.xml" ); qry = new SinglePhraseQuery( RepositoryIndex.FLD_FILES, "pom.xml" );
artifacts = repoSearchLayer.searchAdvanced( qry ); artifacts = repoSearchLayer.searchAdvanced( qry, indexer );
assertEquals( 3, artifacts.size() ); assertEquals( 3, artifacts.size() );
Iterator iter = artifacts.iterator(); Iterator iter = artifacts.iterator();
if ( iter.hasNext() ) if ( iter.hasNext() )
@ -211,7 +213,7 @@ public class ArtifactRepositoryIndexingTest
// search group id // search group id
qry = new SinglePhraseQuery( RepositoryIndex.FLD_GROUPID, "org.apache.maven" ); qry = new SinglePhraseQuery( RepositoryIndex.FLD_GROUPID, "org.apache.maven" );
artifacts = repoSearchLayer.searchAdvanced( qry ); artifacts = repoSearchLayer.searchAdvanced( qry, indexer );
assertEquals( 2, artifacts.size() ); assertEquals( 2, artifacts.size() );
iter = artifacts.iterator(); iter = artifacts.iterator();
if ( iter.hasNext() ) if ( iter.hasNext() )
@ -223,7 +225,7 @@ public class ArtifactRepositoryIndexingTest
// search artifact id // search artifact id
qry = new SinglePhraseQuery( RepositoryIndex.FLD_ARTIFACTID, "maven-artifact" ); qry = new SinglePhraseQuery( RepositoryIndex.FLD_ARTIFACTID, "maven-artifact" );
artifacts = repoSearchLayer.searchAdvanced( qry ); artifacts = repoSearchLayer.searchAdvanced( qry, indexer );
assertEquals( 1, artifacts.size() ); assertEquals( 1, artifacts.size() );
for ( iter = artifacts.iterator(); iter.hasNext(); ) for ( iter = artifacts.iterator(); iter.hasNext(); )
{ {
@ -234,7 +236,7 @@ public class ArtifactRepositoryIndexingTest
// search version // search version
qry = new SinglePhraseQuery( RepositoryIndex.FLD_VERSION, "2" ); qry = new SinglePhraseQuery( RepositoryIndex.FLD_VERSION, "2" );
artifacts = repoSearchLayer.searchAdvanced( qry ); artifacts = repoSearchLayer.searchAdvanced( qry, indexer );
assertEquals( 2, artifacts.size() ); assertEquals( 2, artifacts.size() );
for ( iter = artifacts.iterator(); iter.hasNext(); ) for ( iter = artifacts.iterator(); iter.hasNext(); )
{ {
@ -250,7 +252,7 @@ public class ArtifactRepositoryIndexingTest
String sha1 = digester.createChecksum( artifact.getFile(), Digester.SHA1 ); String sha1 = digester.createChecksum( artifact.getFile(), Digester.SHA1 );
qry = new SinglePhraseQuery( RepositoryIndex.FLD_SHA1, sha1.trim() ); qry = new SinglePhraseQuery( RepositoryIndex.FLD_SHA1, sha1.trim() );
artifacts = repoSearchLayer.searchAdvanced( qry ); artifacts = repoSearchLayer.searchAdvanced( qry, indexer );
assertEquals( 1, artifacts.size() ); assertEquals( 1, artifacts.size() );
for ( iter = artifacts.iterator(); iter.hasNext(); ) for ( iter = artifacts.iterator(); iter.hasNext(); )
{ {
@ -263,7 +265,7 @@ public class ArtifactRepositoryIndexingTest
// search md5 checksum // search md5 checksum
String md5 = digester.createChecksum( artifact.getFile(), Digester.MD5 ); String md5 = digester.createChecksum( artifact.getFile(), Digester.MD5 );
qry = new SinglePhraseQuery( RepositoryIndex.FLD_MD5, md5.trim() ); qry = new SinglePhraseQuery( RepositoryIndex.FLD_MD5, md5.trim() );
artifacts = repoSearchLayer.searchAdvanced( qry ); artifacts = repoSearchLayer.searchAdvanced( qry, indexer );
assertEquals( 1, artifacts.size() ); assertEquals( 1, artifacts.size() );
for ( iter = artifacts.iterator(); iter.hasNext(); ) for ( iter = artifacts.iterator(); iter.hasNext(); )
{ {
@ -287,9 +289,9 @@ public class ArtifactRepositoryIndexingTest
createTestIndex(); createTestIndex();
RepositoryIndexingFactory factory = (RepositoryIndexingFactory) lookup( RepositoryIndexingFactory.ROLE ); RepositoryIndexingFactory factory = (RepositoryIndexingFactory) lookup( RepositoryIndexingFactory.ROLE );
RepositoryIndexSearchLayer repoSearchLayer =
(RepositoryIndexSearchLayer) lookup( RepositoryIndexSearchLayer.ROLE );
ArtifactRepositoryIndex indexer = factory.createArtifactRepositoryIndex( indexPath, repository ); ArtifactRepositoryIndex indexer = factory.createArtifactRepositoryIndex( indexPath, repository );
//RepositoryIndexSearcher repoSearchLayer = factory.createDefaultRepositoryIndexSearcher( indexer );
RepositoryIndexSearchLayer repoSearchLayer = factory.createRepositoryIndexSearchLayer( indexer );
// Criteria 1: required query // Criteria 1: required query
// ex. artifactId=maven-artifact AND groupId=org.apache.maven // ex. artifactId=maven-artifact AND groupId=org.apache.maven
@ -299,7 +301,7 @@ public class ArtifactRepositoryIndexingTest
rQry.and( qry1 ); rQry.and( qry1 );
rQry.and( qry2 ); rQry.and( qry2 );
List artifacts = repoSearchLayer.searchAdvanced( rQry ); List artifacts = repoSearchLayer.searchAdvanced( rQry, indexer );
for ( Iterator iter = artifacts.iterator(); iter.hasNext(); ) for ( Iterator iter = artifacts.iterator(); iter.hasNext(); )
{ {
SearchResult result = (SearchResult) iter.next(); SearchResult result = (SearchResult) iter.next();
@ -316,7 +318,7 @@ public class ArtifactRepositoryIndexingTest
oQry.or( rQry ); oQry.or( rQry );
oQry.or( qry3 ); oQry.or( qry3 );
artifacts = repoSearchLayer.searchAdvanced( oQry ); artifacts = repoSearchLayer.searchAdvanced( oQry, indexer );
for ( Iterator iter = artifacts.iterator(); iter.hasNext(); ) for ( Iterator iter = artifacts.iterator(); iter.hasNext(); )
{ {
SearchResult result = (SearchResult) iter.next(); SearchResult result = (SearchResult) iter.next();
@ -345,7 +347,7 @@ public class ArtifactRepositoryIndexingTest
rQry2.and( rQry ); rQry2.and( rQry );
rQry2.or( oQry5 ); rQry2.or( oQry5 );
artifacts = repoSearchLayer.searchAdvanced( rQry2 ); artifacts = repoSearchLayer.searchAdvanced( rQry2, indexer );
for ( Iterator iter = artifacts.iterator(); iter.hasNext(); ) for ( Iterator iter = artifacts.iterator(); iter.hasNext(); )
{ {
SearchResult result = (SearchResult) iter.next(); SearchResult result = (SearchResult) iter.next();
@ -369,7 +371,7 @@ public class ArtifactRepositoryIndexingTest
oQry2.and( rQry2 ); oQry2.and( rQry2 );
oQry2.and( rQry3 ); oQry2.and( rQry3 );
artifacts = repoSearchLayer.searchAdvanced( oQry2 ); artifacts = repoSearchLayer.searchAdvanced( oQry2, indexer );
for ( Iterator iter = artifacts.iterator(); iter.hasNext(); ) for ( Iterator iter = artifacts.iterator(); iter.hasNext(); )
{ {
SearchResult result = (SearchResult) iter.next(); SearchResult result = (SearchResult) iter.next();
@ -392,7 +394,7 @@ public class ArtifactRepositoryIndexingTest
rQry4.and( qry8 ); rQry4.and( qry8 );
oQry2.and( rQry4 ); oQry2.and( rQry4 );
artifacts = repoSearchLayer.searchAdvanced( oQry2 ); artifacts = repoSearchLayer.searchAdvanced( oQry2, indexer );
for ( Iterator iter = artifacts.iterator(); iter.hasNext(); ) for ( Iterator iter = artifacts.iterator(); iter.hasNext(); )
{ {
SearchResult result = (SearchResult) iter.next(); SearchResult result = (SearchResult) iter.next();
@ -415,14 +417,15 @@ public class ArtifactRepositoryIndexingTest
createTestIndex(); createTestIndex();
RepositoryIndexingFactory factory = (RepositoryIndexingFactory) lookup( RepositoryIndexingFactory.ROLE ); RepositoryIndexingFactory factory = (RepositoryIndexingFactory) lookup( RepositoryIndexingFactory.ROLE );
RepositoryIndexSearchLayer repoSearchLayer =
(RepositoryIndexSearchLayer) lookup( RepositoryIndexSearchLayer.ROLE );
ArtifactRepositoryIndex indexer = factory.createArtifactRepositoryIndex( indexPath, repository ); ArtifactRepositoryIndex indexer = factory.createArtifactRepositoryIndex( indexPath, repository );
// RepositoryIndexSearcher repoSearchLayer = factory.createDefaultRepositoryIndexSearcher( indexer );
RepositoryIndexSearchLayer repoSearchLayer = factory.createRepositoryIndexSearchLayer( indexer );
try try
{ {
Query qry = new SinglePhraseQuery( RepositoryIndex.FLD_VERSION, "~~~~~" ); Query qry = new SinglePhraseQuery( RepositoryIndex.FLD_VERSION, "~~~~~" );
repoSearchLayer.searchAdvanced( qry ); repoSearchLayer.searchAdvanced( qry, indexer );
fail( "Must throw an exception on unparseable query." ); fail( "Must throw an exception on unparseable query." );
} }
catch ( RepositoryIndexSearchException re ) catch ( RepositoryIndexSearchException re )
@ -431,12 +434,11 @@ public class ArtifactRepositoryIndexingTest
} }
indexer = factory.createArtifactRepositoryIndex( "target/index/sample", repository ); indexer = factory.createArtifactRepositoryIndex( "target/index/sample", repository );
repoSearchLayer = factory.createRepositoryIndexSearchLayer( indexer );
try try
{ {
Query qry = new SinglePhraseQuery( RepositoryIndex.FLD_VERSION, "1.0" ); Query qry = new SinglePhraseQuery( RepositoryIndex.FLD_VERSION, "1.0" );
repoSearchLayer.searchAdvanced( qry ); repoSearchLayer.searchAdvanced( qry, indexer );
fail( "Must throw an exception on invalid index location." ); fail( "Must throw an exception on invalid index location." );
} }
catch ( RepositoryIndexSearchException re ) catch ( RepositoryIndexSearchException re )
@ -457,15 +459,16 @@ public class ArtifactRepositoryIndexingTest
createTestIndex(); createTestIndex();
RepositoryIndexingFactory factory = (RepositoryIndexingFactory) lookup( RepositoryIndexingFactory.ROLE ); RepositoryIndexingFactory factory = (RepositoryIndexingFactory) lookup( RepositoryIndexingFactory.ROLE );
RepositoryIndexSearcher repoSearcher = (RepositoryIndexSearcher) lookup( RepositoryIndexSearcher.ROLE );
ArtifactRepositoryIndex indexer = factory.createArtifactRepositoryIndex( indexPath, repository ); ArtifactRepositoryIndex indexer = factory.createArtifactRepositoryIndex( indexPath, repository );
Artifact artifact = getArtifact( "org.apache.maven", "maven-artifact", "2.0.1" ); Artifact artifact = getArtifact( "org.apache.maven", "maven-artifact", "2.0.1" );
artifact.setFile( new File( repository.getBasedir(), repository.pathOf( artifact ) ) ); artifact.setFile( new File( repository.getBasedir(), repository.pathOf( artifact ) ) );
indexer.deleteDocument( RepositoryIndex.FLD_ID, RepositoryIndex.ARTIFACT + artifact.getId() ); indexer.deleteDocument( RepositoryIndex.FLD_ID, RepositoryIndex.ARTIFACT + artifact.getId() );
RepositoryIndexSearcher repoSearcher = factory.createDefaultRepositoryIndexSearcher( indexer );
Query qry = new SinglePhraseQuery( RepositoryIndex.FLD_ID, RepositoryIndex.ARTIFACT + artifact.getId() ); Query qry = new SinglePhraseQuery( RepositoryIndex.FLD_ID, RepositoryIndex.ARTIFACT + artifact.getId() );
List artifacts = repoSearcher.search( qry ); List artifacts = repoSearcher.search( qry, indexer );
assertEquals( 0, artifacts.size() ); assertEquals( 0, artifacts.size() );
} }

View File

@ -137,13 +137,14 @@ public class MetadataRepositoryIndexingTest
createTestIndex(); createTestIndex();
RepositoryIndexingFactory factory = (RepositoryIndexingFactory) lookup( RepositoryIndexingFactory.ROLE ); RepositoryIndexingFactory factory = (RepositoryIndexingFactory) lookup( RepositoryIndexingFactory.ROLE );
RepositoryIndexSearchLayer repoSearchLayer =
(RepositoryIndexSearchLayer) lookup( RepositoryIndexSearchLayer.ROLE );
MetadataRepositoryIndex indexer = factory.createMetadataRepositoryIndex( indexPath, repository ); MetadataRepositoryIndex indexer = factory.createMetadataRepositoryIndex( indexPath, repository );
//RepositoryIndexSearcher repoSearchLayer = factory.createDefaultRepositoryIndexSearcher( indexer );
RepositoryIndexSearchLayer repoSearchLayer = factory.createRepositoryIndexSearchLayer( indexer );
// search last update // search last update
Query qry = new SinglePhraseQuery( RepositoryIndex.FLD_LASTUPDATE, "20051212044643" ); Query qry = new SinglePhraseQuery( RepositoryIndex.FLD_LASTUPDATE, "20051212044643" );
List metadataList = repoSearchLayer.searchAdvanced( qry ); List metadataList = repoSearchLayer.searchAdvanced( qry, indexer );
//assertEquals( 1, metadataList.size() ); //assertEquals( 1, metadataList.size() );
for ( Iterator iter = metadataList.iterator(); iter.hasNext(); ) for ( Iterator iter = metadataList.iterator(); iter.hasNext(); )
{ {
@ -159,7 +160,7 @@ public class MetadataRepositoryIndexingTest
// search plugin prefix // search plugin prefix
qry = new SinglePhraseQuery( RepositoryIndex.FLD_PLUGINPREFIX, "org.apache.maven" ); qry = new SinglePhraseQuery( RepositoryIndex.FLD_PLUGINPREFIX, "org.apache.maven" );
metadataList = repoSearchLayer.searchAdvanced( qry ); metadataList = repoSearchLayer.searchAdvanced( qry, indexer );
//assertEquals( 1, metadataList.size() ); //assertEquals( 1, metadataList.size() );
for ( Iterator iter = metadataList.iterator(); iter.hasNext(); ) for ( Iterator iter = metadataList.iterator(); iter.hasNext(); )
{ {
@ -184,7 +185,7 @@ public class MetadataRepositoryIndexingTest
rQry.addQuery( qry1 ); rQry.addQuery( qry1 );
rQry.addQuery( qry2 ); rQry.addQuery( qry2 );
metadataList = repoSearchLayer.searchAdvanced( rQry ); metadataList = repoSearchLayer.searchAdvanced( rQry, indexer );
for ( Iterator iter = metadataList.iterator(); iter.hasNext(); ) for ( Iterator iter = metadataList.iterator(); iter.hasNext(); )
{ {
RepositoryIndexSearchHit hit = (RepositoryIndexSearchHit) iter.next(); RepositoryIndexSearchHit hit = (RepositoryIndexSearchHit) iter.next();
@ -204,7 +205,7 @@ public class MetadataRepositoryIndexingTest
rQry.addQuery( qry1 ); rQry.addQuery( qry1 );
rQry.addQuery( qry2 ); rQry.addQuery( qry2 );
metadataList = repoSearchLayer.searchAdvanced( rQry ); metadataList = repoSearchLayer.searchAdvanced( rQry, indexer );
assertEquals( 0, metadataList.size() ); assertEquals( 0, metadataList.size() );
indexer.close(); indexer.close();
@ -256,15 +257,16 @@ public class MetadataRepositoryIndexingTest
createTestIndex(); createTestIndex();
RepositoryIndexingFactory factory = (RepositoryIndexingFactory) lookup( RepositoryIndexingFactory.ROLE ); RepositoryIndexingFactory factory = (RepositoryIndexingFactory) lookup( RepositoryIndexingFactory.ROLE );
RepositoryIndexSearcher repoSearcher = (RepositoryIndexSearcher) lookup( RepositoryIndexSearcher.ROLE );
MetadataRepositoryIndex indexer = factory.createMetadataRepositoryIndex( indexPath, repository ); MetadataRepositoryIndex indexer = factory.createMetadataRepositoryIndex( indexPath, repository );
RepositoryMetadata repoMetadata = new GroupRepositoryMetadata( "org.apache.maven" ); RepositoryMetadata repoMetadata = new GroupRepositoryMetadata( "org.apache.maven" );
repoMetadata.setMetadata( readMetadata( repoMetadata ) ); repoMetadata.setMetadata( readMetadata( repoMetadata ) );
indexer.deleteDocument( RepositoryIndex.FLD_ID, (String) repoMetadata.getKey() ); indexer.deleteDocument( RepositoryIndex.FLD_ID, (String) repoMetadata.getKey() );
RepositoryIndexSearcher repoSearcher = factory.createDefaultRepositoryIndexSearcher( indexer );
Query qry = new SinglePhraseQuery( RepositoryIndex.FLD_ID, (String) repoMetadata.getKey() ); Query qry = new SinglePhraseQuery( RepositoryIndex.FLD_ID, (String) repoMetadata.getKey() );
List metadataList = repoSearcher.search( qry ); List metadataList = repoSearcher.search( qry, indexer );
assertEquals( 0, metadataList.size() ); assertEquals( 0, metadataList.size() );
} }

View File

@ -122,13 +122,14 @@ public class PomRepositoryIndexingTest
createTestIndex(); createTestIndex();
RepositoryIndexingFactory factory = (RepositoryIndexingFactory) lookup( RepositoryIndexingFactory.ROLE ); RepositoryIndexingFactory factory = (RepositoryIndexingFactory) lookup( RepositoryIndexingFactory.ROLE );
RepositoryIndexSearchLayer repoSearchLayer =
(RepositoryIndexSearchLayer) lookup( RepositoryIndexSearchLayer.ROLE );
PomRepositoryIndex indexer = factory.createPomRepositoryIndex( indexPath, repository ); PomRepositoryIndex indexer = factory.createPomRepositoryIndex( indexPath, repository );
//RepositoryIndexSearcher repoSearchLayer = factory.createDefaultRepositoryIndexSearcher( indexer );
RepositoryIndexSearchLayer repoSearchLayer = factory.createRepositoryIndexSearchLayer( indexer );
// search version // search version
Query qry = new SinglePhraseQuery( RepositoryIndex.FLD_VERSION, "1.0" ); Query qry = new SinglePhraseQuery( RepositoryIndex.FLD_VERSION, "1.0" );
List artifactList = repoSearchLayer.searchAdvanced( qry ); List artifactList = repoSearchLayer.searchAdvanced( qry, indexer );
assertEquals( 1, artifactList.size() ); assertEquals( 1, artifactList.size() );
for ( Iterator iter = artifactList.iterator(); iter.hasNext(); ) for ( Iterator iter = artifactList.iterator(); iter.hasNext(); )
{ {
@ -139,7 +140,7 @@ public class PomRepositoryIndexingTest
// search group id // search group id
qry = new SinglePhraseQuery( RepositoryIndex.FLD_GROUPID, "org.apache.maven" ); qry = new SinglePhraseQuery( RepositoryIndex.FLD_GROUPID, "org.apache.maven" );
artifactList = repoSearchLayer.searchAdvanced( qry ); artifactList = repoSearchLayer.searchAdvanced( qry, indexer );
assertEquals( 2, artifactList.size() ); assertEquals( 2, artifactList.size() );
Iterator artifacts = artifactList.iterator(); Iterator artifacts = artifactList.iterator();
if ( artifacts.hasNext() ) if ( artifacts.hasNext() )
@ -151,7 +152,7 @@ public class PomRepositoryIndexingTest
// search artifact id // search artifact id
qry = new SinglePhraseQuery( RepositoryIndex.FLD_ARTIFACTID, "maven-artifact" ); qry = new SinglePhraseQuery( RepositoryIndex.FLD_ARTIFACTID, "maven-artifact" );
artifactList = repoSearchLayer.searchAdvanced( qry ); artifactList = repoSearchLayer.searchAdvanced( qry, indexer );
assertEquals( 1, artifactList.size() ); assertEquals( 1, artifactList.size() );
for ( artifacts = artifactList.iterator(); artifacts.hasNext(); ) for ( artifacts = artifactList.iterator(); artifacts.hasNext(); )
{ {
@ -162,7 +163,7 @@ public class PomRepositoryIndexingTest
// search version // search version
qry = new SinglePhraseQuery( RepositoryIndex.FLD_VERSION, "2" ); qry = new SinglePhraseQuery( RepositoryIndex.FLD_VERSION, "2" );
artifactList = repoSearchLayer.searchAdvanced( qry ); artifactList = repoSearchLayer.searchAdvanced( qry, indexer );
assertEquals( 2, artifactList.size() ); assertEquals( 2, artifactList.size() );
for ( artifacts = artifactList.iterator(); artifacts.hasNext(); ) for ( artifacts = artifactList.iterator(); artifacts.hasNext(); )
{ {
@ -173,7 +174,7 @@ public class PomRepositoryIndexingTest
// search packaging // search packaging
qry = new SinglePhraseQuery( RepositoryIndex.FLD_PACKAGING, "jar" ); qry = new SinglePhraseQuery( RepositoryIndex.FLD_PACKAGING, "jar" );
artifactList = repoSearchLayer.searchAdvanced( qry ); artifactList = repoSearchLayer.searchAdvanced( qry, indexer );
assertEquals( 3, artifactList.size() ); assertEquals( 3, artifactList.size() );
for ( artifacts = artifactList.iterator(); artifacts.hasNext(); ) for ( artifacts = artifactList.iterator(); artifacts.hasNext(); )
{ {
@ -186,7 +187,7 @@ public class PomRepositoryIndexingTest
//search license url //search license url
qry = qry =
new SinglePhraseQuery( RepositoryIndex.FLD_LICENSE_URLS, "http://www.apache.org/licenses/LICENSE-2.0.txt" ); new SinglePhraseQuery( RepositoryIndex.FLD_LICENSE_URLS, "http://www.apache.org/licenses/LICENSE-2.0.txt" );
artifactList = repoSearchLayer.searchAdvanced( qry ); artifactList = repoSearchLayer.searchAdvanced( qry, indexer );
assertEquals( 2, artifactList.size() ); assertEquals( 2, artifactList.size() );
for ( artifacts = artifactList.iterator(); artifacts.hasNext(); ) for ( artifacts = artifactList.iterator(); artifacts.hasNext(); )
{ {
@ -201,7 +202,7 @@ public class PomRepositoryIndexingTest
//search dependencies //search dependencies
qry = new SinglePhraseQuery( RepositoryIndex.FLD_DEPENDENCIES, "org.codehaus.plexus:plexus-utils:1.0.5" ); qry = new SinglePhraseQuery( RepositoryIndex.FLD_DEPENDENCIES, "org.codehaus.plexus:plexus-utils:1.0.5" );
artifactList = repoSearchLayer.searchAdvanced( qry ); artifactList = repoSearchLayer.searchAdvanced( qry, indexer );
assertEquals( 2, artifactList.size() ); assertEquals( 2, artifactList.size() );
for ( artifacts = artifactList.iterator(); artifacts.hasNext(); ) for ( artifacts = artifactList.iterator(); artifacts.hasNext(); )
{ {
@ -225,7 +226,7 @@ public class PomRepositoryIndexingTest
//search build plugin //search build plugin
qry = qry =
new SinglePhraseQuery( RepositoryIndex.FLD_PLUGINS_BUILD, "org.codehaus.modello:modello-maven-plugin:2.0" ); new SinglePhraseQuery( RepositoryIndex.FLD_PLUGINS_BUILD, "org.codehaus.modello:modello-maven-plugin:2.0" );
artifactList = repoSearchLayer.searchAdvanced( qry ); artifactList = repoSearchLayer.searchAdvanced( qry, indexer );
assertEquals( 1, artifactList.size() ); assertEquals( 1, artifactList.size() );
for ( artifacts = artifactList.iterator(); artifacts.hasNext(); ) for ( artifacts = artifactList.iterator(); artifacts.hasNext(); )
{ {
@ -249,7 +250,7 @@ public class PomRepositoryIndexingTest
//search reporting plugin //search reporting plugin
qry = new SinglePhraseQuery( RepositoryIndex.FLD_PLUGINS_REPORT, qry = new SinglePhraseQuery( RepositoryIndex.FLD_PLUGINS_REPORT,
"org.apache.maven.plugins:maven-checkstyle-plugin:2.0" ); "org.apache.maven.plugins:maven-checkstyle-plugin:2.0" );
artifactList = repoSearchLayer.searchAdvanced( qry ); artifactList = repoSearchLayer.searchAdvanced( qry, indexer );
assertEquals( 1, artifactList.size() ); assertEquals( 1, artifactList.size() );
for ( artifacts = artifactList.iterator(); artifacts.hasNext(); ) for ( artifacts = artifactList.iterator(); artifacts.hasNext(); )
{ {
@ -276,7 +277,7 @@ public class PomRepositoryIndexingTest
String sha1 = digester.createChecksum( artifact.getFile(), Digester.SHA1 ); String sha1 = digester.createChecksum( artifact.getFile(), Digester.SHA1 );
qry = new SinglePhraseQuery( RepositoryIndex.FLD_SHA1, sha1.trim() ); qry = new SinglePhraseQuery( RepositoryIndex.FLD_SHA1, sha1.trim() );
artifactList = repoSearchLayer.searchAdvanced( qry ); artifactList = repoSearchLayer.searchAdvanced( qry, indexer );
assertEquals( 1, artifactList.size() ); assertEquals( 1, artifactList.size() );
for ( artifacts = artifactList.iterator(); artifacts.hasNext(); ) for ( artifacts = artifactList.iterator(); artifacts.hasNext(); )
{ {
@ -289,7 +290,7 @@ public class PomRepositoryIndexingTest
// search md5 checksum // search md5 checksum
String md5 = digester.createChecksum( getPomFile( artifact ), Digester.MD5 ); String md5 = digester.createChecksum( getPomFile( artifact ), Digester.MD5 );
qry = new SinglePhraseQuery( RepositoryIndex.FLD_MD5, md5.trim() ); qry = new SinglePhraseQuery( RepositoryIndex.FLD_MD5, md5.trim() );
artifactList = repoSearchLayer.searchAdvanced( qry ); artifactList = repoSearchLayer.searchAdvanced( qry, indexer );
assertEquals( 1, artifactList.size() ); assertEquals( 1, artifactList.size() );
for ( artifacts = artifactList.iterator(); artifacts.hasNext(); ) for ( artifacts = artifactList.iterator(); artifacts.hasNext(); )
{ {
@ -313,9 +314,10 @@ public class PomRepositoryIndexingTest
createTestIndex(); createTestIndex();
RepositoryIndexingFactory factory = (RepositoryIndexingFactory) lookup( RepositoryIndexingFactory.ROLE ); RepositoryIndexingFactory factory = (RepositoryIndexingFactory) lookup( RepositoryIndexingFactory.ROLE );
RepositoryIndexSearchLayer repoSearchLayer =
(RepositoryIndexSearchLayer) lookup( RepositoryIndexSearchLayer.ROLE );
PomRepositoryIndex indexer = factory.createPomRepositoryIndex( indexPath, repository ); PomRepositoryIndex indexer = factory.createPomRepositoryIndex( indexPath, repository );
//RepositoryIndexSearcher repoSearchLayer = factory.createDefaultRepositoryIndexSearcher( indexer );
RepositoryIndexSearchLayer repoSearchLayer = factory.createRepositoryIndexSearchLayer( indexer );
// Criteria 1: required query // Criteria 1: required query
// ex. artifactId=maven-artifact AND groupId=org.apache.maven // ex. artifactId=maven-artifact AND groupId=org.apache.maven
@ -325,7 +327,7 @@ public class PomRepositoryIndexingTest
rQry.and( qry1 ); rQry.and( qry1 );
rQry.and( qry2 ); rQry.and( qry2 );
List artifacts = repoSearchLayer.searchAdvanced( rQry ); List artifacts = repoSearchLayer.searchAdvanced( rQry, indexer );
for ( Iterator iter = artifacts.iterator(); iter.hasNext(); ) for ( Iterator iter = artifacts.iterator(); iter.hasNext(); )
{ {
SearchResult result = (SearchResult) iter.next(); SearchResult result = (SearchResult) iter.next();
@ -342,7 +344,7 @@ public class PomRepositoryIndexingTest
oQry.and( rQry ); oQry.and( rQry );
oQry.or( qry3 ); oQry.or( qry3 );
artifacts = repoSearchLayer.searchAdvanced( oQry ); artifacts = repoSearchLayer.searchAdvanced( oQry, indexer );
for ( Iterator iter = artifacts.iterator(); iter.hasNext(); ) for ( Iterator iter = artifacts.iterator(); iter.hasNext(); )
{ {
SearchResult result = (SearchResult) iter.next(); SearchResult result = (SearchResult) iter.next();
@ -373,7 +375,7 @@ public class PomRepositoryIndexingTest
rQry2.and( rQry ); rQry2.and( rQry );
rQry2.and( oQry5 ); rQry2.and( oQry5 );
artifacts = repoSearchLayer.searchAdvanced( rQry2 ); artifacts = repoSearchLayer.searchAdvanced( rQry2, indexer );
for ( Iterator iter = artifacts.iterator(); iter.hasNext(); ) for ( Iterator iter = artifacts.iterator(); iter.hasNext(); )
{ {
SearchResult result = (SearchResult) iter.next(); SearchResult result = (SearchResult) iter.next();
@ -397,7 +399,7 @@ public class PomRepositoryIndexingTest
oQry2.and( rQry2 ); oQry2.and( rQry2 );
oQry2.and( rQry3 ); oQry2.and( rQry3 );
artifacts = repoSearchLayer.searchAdvanced( oQry2 ); artifacts = repoSearchLayer.searchAdvanced( oQry2, indexer );
for ( Iterator iter = artifacts.iterator(); iter.hasNext(); ) for ( Iterator iter = artifacts.iterator(); iter.hasNext(); )
{ {
SearchResult result = (SearchResult) iter.next(); SearchResult result = (SearchResult) iter.next();
@ -420,7 +422,7 @@ public class PomRepositoryIndexingTest
rQry4.and( qry8 ); rQry4.and( qry8 );
oQry2.and( rQry4 ); oQry2.and( rQry4 );
artifacts = repoSearchLayer.searchAdvanced( oQry2 ); artifacts = repoSearchLayer.searchAdvanced( oQry2, indexer );
for ( Iterator iter = artifacts.iterator(); iter.hasNext(); ) for ( Iterator iter = artifacts.iterator(); iter.hasNext(); )
{ {
SearchResult result = (SearchResult) iter.next(); SearchResult result = (SearchResult) iter.next();
@ -477,13 +479,15 @@ public class PomRepositoryIndexingTest
createTestIndex(); createTestIndex();
RepositoryIndexingFactory factory = (RepositoryIndexingFactory) lookup( RepositoryIndexingFactory.ROLE ); RepositoryIndexingFactory factory = (RepositoryIndexingFactory) lookup( RepositoryIndexingFactory.ROLE );
RepositoryIndexSearcher repoSearcher = (RepositoryIndexSearcher) lookup( RepositoryIndexSearcher.ROLE );
PomRepositoryIndex indexer = factory.createPomRepositoryIndex( indexPath, repository ); PomRepositoryIndex indexer = factory.createPomRepositoryIndex( indexPath, repository );
Model pom = getPom( "org.apache.maven", "maven-artifact", "2.0.1" ); Model pom = getPom( "org.apache.maven", "maven-artifact", "2.0.1" );
indexer.deleteDocument( RepositoryIndex.FLD_ID, RepositoryIndex.POM + pom.getId() ); indexer.deleteDocument( RepositoryIndex.FLD_ID, RepositoryIndex.POM + pom.getId() );
RepositoryIndexSearcher repoSearcher = factory.createDefaultRepositoryIndexSearcher( indexer );
Query qry = new SinglePhraseQuery( RepositoryIndex.FLD_ID, RepositoryIndex.POM + pom.getId() ); Query qry = new SinglePhraseQuery( RepositoryIndex.FLD_ID, RepositoryIndex.POM + pom.getId() );
List artifactList = repoSearcher.search( qry ); List artifactList = repoSearcher.search( qry, indexer );
assertEquals( 0, artifactList.size() ); assertEquals( 0, artifactList.size() );
} }

View File

@ -169,10 +169,11 @@ public class RepositoryIndexSearchLayerTest
{ {
createTestIndex(); createTestIndex();
RepositoryIndexingFactory factory = (RepositoryIndexingFactory) lookup( RepositoryIndexingFactory.ROLE ); RepositoryIndexingFactory factory = (RepositoryIndexingFactory) lookup( RepositoryIndexingFactory.ROLE );
ArtifactRepositoryIndex indexer = factory.createArtifactRepositoryIndex( indexPath, repository ); RepositoryIndexSearchLayer searchLayer = (RepositoryIndexSearchLayer) lookup( RepositoryIndexSearchLayer.ROLE );
RepositoryIndexSearchLayer searchLayer = factory.createRepositoryIndexSearchLayer( indexer );
List returnList = searchLayer.searchGeneral( "org.apache.maven" ); ArtifactRepositoryIndex indexer = factory.createArtifactRepositoryIndex( indexPath, repository );
List returnList = searchLayer.searchGeneral( "org.apache.maven", indexer );
for ( Iterator iter = returnList.iterator(); iter.hasNext(); ) for ( Iterator iter = returnList.iterator(); iter.hasNext(); )
{ {
SearchResult result = (SearchResult) iter.next(); SearchResult result = (SearchResult) iter.next();
@ -193,7 +194,7 @@ public class RepositoryIndexSearchLayerTest
} }
//POM license urls //POM license urls
returnList = searchLayer.searchGeneral( "http://www.apache.org/licenses/LICENSE-2.0.txt" ); returnList = searchLayer.searchGeneral( "http://www.apache.org/licenses/LICENSE-2.0.txt", indexer );
for ( Iterator iter = returnList.iterator(); iter.hasNext(); ) for ( Iterator iter = returnList.iterator(); iter.hasNext(); )
{ {
SearchResult result = (SearchResult) iter.next(); SearchResult result = (SearchResult) iter.next();
@ -214,7 +215,7 @@ public class RepositoryIndexSearchLayerTest
} }
//POM dependency //POM dependency
returnList = searchLayer.searchGeneral( "org.codehaus.plexus:plexus-utils:1.0.5" ); returnList = searchLayer.searchGeneral( "org.codehaus.plexus:plexus-utils:1.0.5", indexer );
for ( Iterator iter = returnList.iterator(); iter.hasNext(); ) for ( Iterator iter = returnList.iterator(); iter.hasNext(); )
{ {
SearchResult result = (SearchResult) iter.next(); SearchResult result = (SearchResult) iter.next();
@ -235,7 +236,7 @@ public class RepositoryIndexSearchLayerTest
} }
// POM reporting plugin // POM reporting plugin
returnList = searchLayer.searchGeneral( "org.apache.maven.plugins:maven-checkstyle-plugin:2.0" ); returnList = searchLayer.searchGeneral( "org.apache.maven.plugins:maven-checkstyle-plugin:2.0", indexer );
for ( Iterator iter = returnList.iterator(); iter.hasNext(); ) for ( Iterator iter = returnList.iterator(); iter.hasNext(); )
{ {
SearchResult result = (SearchResult) iter.next(); SearchResult result = (SearchResult) iter.next();
@ -257,7 +258,7 @@ public class RepositoryIndexSearchLayerTest
} }
// POM build plugin // POM build plugin
returnList = searchLayer.searchGeneral( "org.codehaus.modello:modello-maven-plugin:2.0" ); returnList = searchLayer.searchGeneral( "org.codehaus.modello:modello-maven-plugin:2.0", indexer );
for ( Iterator iter = returnList.iterator(); iter.hasNext(); ) for ( Iterator iter = returnList.iterator(); iter.hasNext(); )
{ {
SearchResult result = (SearchResult) iter.next(); SearchResult result = (SearchResult) iter.next();
@ -278,7 +279,7 @@ public class RepositoryIndexSearchLayerTest
} }
//maven-artifact-2.0.1.jar MD5 checksum //maven-artifact-2.0.1.jar MD5 checksum
returnList = searchLayer.searchGeneral( "F5A934ABBBC70A33136D89A996B9D5C09F652766" ); returnList = searchLayer.searchGeneral( "F5A934ABBBC70A33136D89A996B9D5C09F652766", indexer );
for ( Iterator iter = returnList.iterator(); iter.hasNext(); ) for ( Iterator iter = returnList.iterator(); iter.hasNext(); )
{ {
SearchResult result = (SearchResult) iter.next(); SearchResult result = (SearchResult) iter.next();
@ -296,7 +297,7 @@ public class RepositoryIndexSearchLayerTest
} }
//maven-artifact-2.0.1.jar SHA1 checksum //maven-artifact-2.0.1.jar SHA1 checksum
returnList = searchLayer.searchGeneral( "AE55D9B5720E11B6CF19FE1E31A42E51" ); returnList = searchLayer.searchGeneral( "AE55D9B5720E11B6CF19FE1E31A42E51", indexer );
for ( Iterator iter = returnList.iterator(); iter.hasNext(); ) for ( Iterator iter = returnList.iterator(); iter.hasNext(); )
{ {
SearchResult result = (SearchResult) iter.next(); SearchResult result = (SearchResult) iter.next();
@ -313,7 +314,7 @@ public class RepositoryIndexSearchLayerTest
} }
//packaging jar //packaging jar
returnList = searchLayer.searchGeneral( "jar" ); returnList = searchLayer.searchGeneral( "jar", indexer );
for ( Iterator iter = returnList.iterator(); iter.hasNext(); ) for ( Iterator iter = returnList.iterator(); iter.hasNext(); )
{ {
SearchResult result = (SearchResult) iter.next(); SearchResult result = (SearchResult) iter.next();
@ -329,14 +330,14 @@ public class RepositoryIndexSearchLayerTest
} }
} }
returnList = searchLayer.searchGeneral( "test" ); returnList = searchLayer.searchGeneral( "test", indexer );
for ( Iterator iter = returnList.iterator(); iter.hasNext(); ) for ( Iterator iter = returnList.iterator(); iter.hasNext(); )
{ {
SearchResult result = (SearchResult) iter.next(); SearchResult result = (SearchResult) iter.next();
assertEquals( "test", result.getArtifact().getGroupId() ); assertEquals( "test", result.getArtifact().getGroupId() );
} }
returnList = searchLayer.searchGeneral( "test-artifactId" ); returnList = searchLayer.searchGeneral( "test-artifactId", indexer );
for ( Iterator iter = returnList.iterator(); iter.hasNext(); ) for ( Iterator iter = returnList.iterator(); iter.hasNext(); )
{ {
SearchResult result = (SearchResult) iter.next(); SearchResult result = (SearchResult) iter.next();

View File

@ -47,6 +47,11 @@ public class GeneralSearchAction
*/ */
private RepositoryIndexingFactory factory; private RepositoryIndexingFactory factory;
/**
* @plexus.requirement
*/
private RepositoryIndexSearchLayer searchLayer;
/** /**
* @plexus.requirement * @plexus.requirement
*/ */
@ -74,9 +79,7 @@ public class GeneralSearchAction
ArtifactRepositoryIndex index = factory.createArtifactRepositoryIndex( indexPath, repository ); ArtifactRepositoryIndex index = factory.createArtifactRepositoryIndex( indexPath, repository );
RepositoryIndexSearchLayer searchLayer = factory.createRepositoryIndexSearchLayer( index ); searchResult = searchLayer.searchGeneral( searchString, index );
searchResult = searchLayer.searchGeneral( searchString );
return SUCCESS; return SUCCESS;
} }

View File

@ -57,6 +57,11 @@ public class PackageSearchAction
*/ */
private ArtifactRepositoryFactory repositoryFactory; private ArtifactRepositoryFactory repositoryFactory;
/**
* @plexus.requirement
*/
private RepositoryIndexSearchLayer searchLayer;
/** /**
* @plexus.requirement * @plexus.requirement
*/ */
@ -94,9 +99,7 @@ public class PackageSearchAction
ArtifactRepositoryIndex index = factory.createArtifactRepositoryIndex( indexPath, repository ); ArtifactRepositoryIndex index = factory.createArtifactRepositoryIndex( indexPath, repository );
RepositoryIndexSearchLayer searchLayer = factory.createRepositoryIndexSearchLayer( index ); searchResult = searchLayer.searchAdvanced( new SinglePhraseQuery( key, searchTerm ), index );
searchResult = searchLayer.searchAdvanced( new SinglePhraseQuery( key, searchTerm ) );
return SUCCESS; return SUCCESS;
} }