org.apache.maven.index
Interface NexusIndexer

All Known Implementing Classes:
DefaultNexusIndexer

public interface NexusIndexer

The Nexus indexer is a statefull facade that maintains state of indexing contexts.

The following code snippet shows how to register indexing context, which should be done once on the application startup and Nexus indexer instance should be reused after that.

 NexusIndexer indexer;
 
 IndexingContext context = indexer.addIndexingContext( indexId, // index id (usually the same as repository id)
     repositoryId, // repository id
     directory, // Lucene directory where index is stored
     repositoryDir, // local repository dir or null for remote repo
     repositoryUrl, // repository url, used by index updater
     indexUpdateUrl, // index update url or null if derived from repositoryUrl
     false, false );
 
An indexing context could be populated using one of scan(IndexingContext), addArtifactToIndex(ArtifactContext, IndexingContext) or deleteArtifactFromIndex(ArtifactContext, IndexingContext) methods.

An IndexUpdater could be used to fetch indexes from remote repositories. These indexers could be created using the NexusIndexerCli command line tool or IndexPacker API.

Once index is populated you can perform search queries using field names declared in the ArtifactInfo:

   // run search query
   BooleanQuery q = new BooleanQuery();
   q.add(indexer.constructQuery(ArtifactInfo.GROUP_ID, term), Occur.SHOULD);
   q.add(indexer.constructQuery(ArtifactInfo.ARTIFACT_ID, term), Occur.SHOULD);
   q.add(new PrefixQuery(new Term(ArtifactInfo.SHA1, term)), Occur.SHOULD);
   
   FlatSearchRequest request = new FlatSearchRequest(q);
   FlatSearchResponse response = indexer.searchFlat(request);
   ...
 
Query could be also constructed using a convenience constructQuery(Field, SearchExpression) method that handles creation of the wildcard queries. Also see DefaultQueryCreator for more details on supported queries.

Author:
Jason van Zyl, Tamas Cservenak, Eugene Kuleshov
See Also:
IndexingContext, IndexUpdater, DefaultQueryCreator

Field Summary
static String ROLE
           
 
Method Summary
 void addArtifactsToIndex(Collection<ArtifactContext> acs, IndexingContext context)
           
 void addArtifactToIndex(ArtifactContext ac, IndexingContext context)
           
 IndexingContext addIndexingContext(String id, String repositoryId, File repository, org.apache.lucene.store.Directory directory, String repositoryUrl, String indexUpdateUrl, List<? extends IndexCreator> indexers)
          Adds an indexing context to Nexus indexer.
 IndexingContext addIndexingContext(String id, String repositoryId, File repository, File indexDirectory, String repositoryUrl, String indexUpdateUrl, List<? extends IndexCreator> indexers)
          Adds an indexing context to Nexus indexer.
 IndexingContext addIndexingContextForced(String id, String repositoryId, File repository, org.apache.lucene.store.Directory directory, String repositoryUrl, String indexUpdateUrl, List<? extends IndexCreator> indexers)
          Adds an indexing context to Nexus indexer.
 IndexingContext addIndexingContextForced(String id, String repositoryId, File repository, File indexDirectory, String repositoryUrl, String indexUpdateUrl, List<? extends IndexCreator> indexers)
          Adds an indexing context to Nexus indexer.
 IndexingContext addMergedIndexingContext(String id, String repositoryId, File repository, org.apache.lucene.store.Directory indexDirectory, boolean searchable, Collection<IndexingContext> contexts)
           
 IndexingContext addMergedIndexingContext(String id, String repositoryId, File repository, org.apache.lucene.store.Directory indexDirectory, boolean searchable, ContextMemberProvider membersProvider)
           
 IndexingContext addMergedIndexingContext(String id, String repositoryId, File repository, File indexDirectory, boolean searchable, Collection<IndexingContext> contexts)
           
 IndexingContext addMergedIndexingContext(String id, String repositoryId, File repository, File indexDirectory, boolean searchable, ContextMemberProvider membersProvider)
           
 void artifactDiscovered(ArtifactContext ac, IndexingContext context)
           
 org.apache.lucene.search.Query constructQuery(Field field, SearchExpression expression)
          Helper method to construct Lucene query for given field without need for knowledge (on caller side) HOW is a field indexed, and WHAT query is needed to achieve that.
 org.apache.lucene.search.Query constructQuery(Field field, String query, SearchType type)
          Deprecated. Use constructQuery(Field, SearchExpression) instead.
 void deleteArtifactFromIndex(ArtifactContext ac, IndexingContext context)
           
 void deleteArtifactsFromIndex(Collection<ArtifactContext> acs, IndexingContext context)
           
 Map<String,IndexingContext> getIndexingContexts()
          Returns the map of indexing contexts keyed by their ID.
 Collection<ArtifactInfo> identify(Field field, String query)
           
 Collection<ArtifactInfo> identify(File artifact)
           
 Collection<ArtifactInfo> identify(File artifact, Collection<IndexingContext> contexts)
           
 Collection<ArtifactInfo> identify(org.apache.lucene.search.Query query)
           
 Collection<ArtifactInfo> identify(org.apache.lucene.search.Query query, Collection<IndexingContext> contexts)
           
 void removeIndexingContext(IndexingContext context, boolean deleteFiles)
          Removes the indexing context from Nexus indexer, closes it and deletes (if specified) the index files.
 void scan(IndexingContext context)
          Performs full scan (reindex) for the local repository belonging to supplied context.
 void scan(IndexingContext context, ArtifactScanningListener listener)
          Performs full scan (reindex) for the local repository belonging to supplied context.
 void scan(IndexingContext context, ArtifactScanningListener listener, boolean update)
          Performs optionally incremental scan (reindex) for the local repository, with listener.
 void scan(IndexingContext context, boolean update)
          Performs optionally incremental scan (reindex/full reindex) for the local repository belonging to the supplied context.
 void scan(IndexingContext context, String fromPath, ArtifactScanningListener listener, boolean update)
          Performs optionally incremental scan (reindex) for the local repository.
 FlatSearchResponse searchFlat(FlatSearchRequest request)
          Searches according the request parameters.
 GroupedSearchResponse searchGrouped(GroupedSearchRequest request)
          Searches according the request parameters.
 IteratorSearchResponse searchIterator(IteratorSearchRequest request)
          Searches according to request parameters.
 

Field Detail

ROLE

static final String ROLE
Method Detail

addIndexingContext

IndexingContext addIndexingContext(String id,
                                   String repositoryId,
                                   File repository,
                                   File indexDirectory,
                                   String repositoryUrl,
                                   String indexUpdateUrl,
                                   List<? extends IndexCreator> indexers)
                                   throws IOException,
                                          UnsupportedExistingLuceneIndexException
Adds an indexing context to Nexus indexer.

Parameters:
id - the ID of the context.
repositoryId - the ID of the repository that this context represents.
repository - the location of the repository.
indexDirectory - the location of the Lucene indexes.
repositoryUrl - the location of the remote repository.
indexUpdateUrl - the alternate location of the remote repository indexes (if they are not in default place).
indexers - the set of indexers to apply to this context.
Returns:
Throws:
IOException - in case of some serious IO problem.
UnsupportedExistingLuceneIndexException - if a Lucene index already exists where location is specified, but it has no Nexus descriptor record or it has, but the embedded repoId differs from the repoId specified from the supplied one.
IllegalArgumentException - in case the supplied list of IndexCreators are not satisfiable

addIndexingContextForced

IndexingContext addIndexingContextForced(String id,
                                         String repositoryId,
                                         File repository,
                                         File indexDirectory,
                                         String repositoryUrl,
                                         String indexUpdateUrl,
                                         List<? extends IndexCreator> indexers)
                                         throws IOException
Adds an indexing context to Nexus indexer. It "forces" this operation, thus no UnsupportedExistingLuceneIndexException is thrown. If it founds an existing lucene index, it will simply stomp-over and rewrite (or add) the Nexus index descriptor.

Parameters:
id - the ID of the context.
repositoryId - the ID of the repository that this context represents.
repository - the location of the repository.
indexDirectory - the location of the Lucene indexes.
repositoryUrl - the location of the remote repository.
indexUpdateUrl - the alternate location of the remote repository indexes (if they are not in default place).
indexers - the set of indexers to apply to this context.
Returns:
Throws:
IOException - in case of some serious IO problem.
IllegalArgumentException - in case the supplied list of IndexCreators are not satisfiable

addIndexingContext

IndexingContext addIndexingContext(String id,
                                   String repositoryId,
                                   File repository,
                                   org.apache.lucene.store.Directory directory,
                                   String repositoryUrl,
                                   String indexUpdateUrl,
                                   List<? extends IndexCreator> indexers)
                                   throws IOException,
                                          UnsupportedExistingLuceneIndexException
Adds an indexing context to Nexus indexer.

Parameters:
id - the ID of the context.
repositoryId - the ID of the repository that this context represents.
repository - the location of the repository.
directory - the location of the Lucene indexes.
repositoryUrl - the location of the remote repository.
indexUpdateUrl - the alternate location of the remote repository indexes (if they are not in default place).
indexers - the set of indexers to apply to this context.
Returns:
Throws:
IOException - in case of some serious IO problem.
UnsupportedExistingLuceneIndexException - if a Lucene index already exists where location is specified, but it has no Nexus descriptor record or it has, but the embedded repoId differs from the repoId specified from the supplied one.
IllegalArgumentException - in case the supplied list of IndexCreators are not satisfiable

addIndexingContextForced

IndexingContext addIndexingContextForced(String id,
                                         String repositoryId,
                                         File repository,
                                         org.apache.lucene.store.Directory directory,
                                         String repositoryUrl,
                                         String indexUpdateUrl,
                                         List<? extends IndexCreator> indexers)
                                         throws IOException
Adds an indexing context to Nexus indexer. It "forces" this operation, thus no UnsupportedExistingLuceneIndexException is thrown. If it founds an existing lucene index, it will simply stomp-over and rewrite (or add) the Nexus index descriptor.

Parameters:
id - the ID of the context.
repositoryId - the ID of the repository that this context represents.
repository - the location of the repository.
directory - the location of the Lucene indexes.
repositoryUrl - the location of the remote repository.
indexUpdateUrl - the alternate location of the remote repository indexes (if they are not in default place).
indexers - the set of indexers to apply to this context.
Returns:
Throws:
IOException - in case of some serious IO problem.
IllegalArgumentException - in case the supplied list of IndexCreators are not satisfiable

addMergedIndexingContext

IndexingContext addMergedIndexingContext(String id,
                                         String repositoryId,
                                         File repository,
                                         File indexDirectory,
                                         boolean searchable,
                                         Collection<IndexingContext> contexts)
                                         throws IOException
Throws:
IOException

addMergedIndexingContext

IndexingContext addMergedIndexingContext(String id,
                                         String repositoryId,
                                         File repository,
                                         File indexDirectory,
                                         boolean searchable,
                                         ContextMemberProvider membersProvider)
                                         throws IOException
Throws:
IOException

addMergedIndexingContext

IndexingContext addMergedIndexingContext(String id,
                                         String repositoryId,
                                         File repository,
                                         org.apache.lucene.store.Directory indexDirectory,
                                         boolean searchable,
                                         Collection<IndexingContext> contexts)
                                         throws IOException
Throws:
IOException

addMergedIndexingContext

IndexingContext addMergedIndexingContext(String id,
                                         String repositoryId,
                                         File repository,
                                         org.apache.lucene.store.Directory indexDirectory,
                                         boolean searchable,
                                         ContextMemberProvider membersProvider)
                                         throws IOException
Throws:
IOException

removeIndexingContext

void removeIndexingContext(IndexingContext context,
                           boolean deleteFiles)
                           throws IOException
Removes the indexing context from Nexus indexer, closes it and deletes (if specified) the index files.

Parameters:
context -
deleteFiles -
Throws:
IOException

getIndexingContexts

Map<String,IndexingContext> getIndexingContexts()
Returns the map of indexing contexts keyed by their ID.


scan

void scan(IndexingContext context)
          throws IOException
Performs full scan (reindex) for the local repository belonging to supplied context.

Parameters:
context -
Throws:
IOException

scan

void scan(IndexingContext context,
          ArtifactScanningListener listener)
          throws IOException
Performs full scan (reindex) for the local repository belonging to supplied context. ArtifactListener is used during that process.

Parameters:
context -
listener -
Throws:
IOException

scan

void scan(IndexingContext context,
          boolean update)
          throws IOException
Performs optionally incremental scan (reindex/full reindex) for the local repository belonging to the supplied context.

Parameters:
context -
update - if incremental reindex wanted, set true, otherwise false and full reindex will happenF
Throws:
IOException

scan

void scan(IndexingContext context,
          ArtifactScanningListener listener,
          boolean update)
          throws IOException
Performs optionally incremental scan (reindex) for the local repository, with listener.

Parameters:
context -
listener -
update - if incremental reindex wanted, set true, otherwise false and full reindex will happenF
Throws:
IOException

scan

void scan(IndexingContext context,
          String fromPath,
          ArtifactScanningListener listener,
          boolean update)
          throws IOException
Performs optionally incremental scan (reindex) for the local repository.

Parameters:
context -
fromPath - a path segment if you want "sub-path" reindexing (ie. reindex just a given subfolder of a repository, ot whole repository from root.
listener -
update - if incremental reindex wanted, set true, otherwise false and full reindex will happenF
Throws:
IOException

artifactDiscovered

void artifactDiscovered(ArtifactContext ac,
                        IndexingContext context)
                        throws IOException
Throws:
IOException

addArtifactToIndex

void addArtifactToIndex(ArtifactContext ac,
                        IndexingContext context)
                        throws IOException
Throws:
IOException

addArtifactsToIndex

void addArtifactsToIndex(Collection<ArtifactContext> acs,
                         IndexingContext context)
                         throws IOException
Throws:
IOException

deleteArtifactFromIndex

void deleteArtifactFromIndex(ArtifactContext ac,
                             IndexingContext context)
                             throws IOException
Throws:
IOException

deleteArtifactsFromIndex

void deleteArtifactsFromIndex(Collection<ArtifactContext> acs,
                              IndexingContext context)
                              throws IOException
Throws:
IOException

searchFlat

FlatSearchResponse searchFlat(FlatSearchRequest request)
                              throws IOException
Searches according the request parameters.

Parameters:
request -
Returns:
Throws:
IOException

searchIterator

IteratorSearchResponse searchIterator(IteratorSearchRequest request)
                                      throws IOException
Searches according to request parameters.

Parameters:
request -
Returns:
Throws:
IOException

searchGrouped

GroupedSearchResponse searchGrouped(GroupedSearchRequest request)
                                    throws IOException
Searches according the request parameters.

Parameters:
request -
Returns:
Throws:
IOException

constructQuery

org.apache.lucene.search.Query constructQuery(Field field,
                                              String query,
                                              SearchType type)
                                              throws IllegalArgumentException
Deprecated. Use constructQuery(Field, SearchExpression) instead.

Helper method to construct Lucene query for given field without need for knowledge (on caller side) HOW is a field indexed, and WHAT query is needed to achieve that.

Parameters:
field -
query -
type -
Returns:
Throws:
IllegalArgumentException

constructQuery

org.apache.lucene.search.Query constructQuery(Field field,
                                              SearchExpression expression)
                                              throws IllegalArgumentException
Helper method to construct Lucene query for given field without need for knowledge (on caller side) HOW is a field indexed, and WHAT query is needed to achieve that.

Parameters:
field -
expression -
Returns:
Throws:
IllegalArgumentException

identify

Collection<ArtifactInfo> identify(Field field,
                                  String query)
                                  throws IllegalArgumentException,
                                         IOException
Throws:
IllegalArgumentException
IOException

identify

Collection<ArtifactInfo> identify(File artifact)
                                  throws IOException
Throws:
IOException

identify

Collection<ArtifactInfo> identify(File artifact,
                                  Collection<IndexingContext> contexts)
                                  throws IOException
Throws:
IOException

identify

Collection<ArtifactInfo> identify(org.apache.lucene.search.Query query)
                                  throws IOException
Throws:
IOException

identify

Collection<ArtifactInfo> identify(org.apache.lucene.search.Query query,
                                  Collection<IndexingContext> contexts)
                                  throws IOException
Throws:
IOException


Copyright © 2002-2012 The Apache Software Foundation. All Rights Reserved.