public interface NexusIndexer
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.IndexingContext,
IndexUpdater,
DefaultQueryCreator| Modifier and Type | Method and Description |
|---|---|
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.
|
static final String ROLE
IndexingContext addIndexingContext(String id, String repositoryId, File repository, File indexDirectory, String repositoryUrl, String indexUpdateUrl, List<? extends IndexCreator> indexers) throws IOException, UnsupportedExistingLuceneIndexException
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.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 satisfiableIndexingContext addIndexingContextForced(String id, String repositoryId, File repository, File indexDirectory, String repositoryUrl, String indexUpdateUrl, List<? extends IndexCreator> indexers) throws IOException
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.IOException - in case of some serious IO problem.IllegalArgumentException - in case the supplied list of IndexCreators are not satisfiableIndexingContext addIndexingContext(String id, String repositoryId, File repository, org.apache.lucene.store.Directory directory, String repositoryUrl, String indexUpdateUrl, List<? extends IndexCreator> indexers) throws IOException, UnsupportedExistingLuceneIndexException
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.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 satisfiableIndexingContext addIndexingContextForced(String id, String repositoryId, File repository, org.apache.lucene.store.Directory directory, String repositoryUrl, String indexUpdateUrl, List<? extends IndexCreator> indexers) throws IOException
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.IOException - in case of some serious IO problem.IllegalArgumentException - in case the supplied list of IndexCreators are not satisfiableIndexingContext addMergedIndexingContext(String id, String repositoryId, File repository, File indexDirectory, boolean searchable, Collection<IndexingContext> contexts) throws IOException
IOExceptionIndexingContext addMergedIndexingContext(String id, String repositoryId, File repository, File indexDirectory, boolean searchable, ContextMemberProvider membersProvider) throws IOException
IOExceptionIndexingContext addMergedIndexingContext(String id, String repositoryId, File repository, org.apache.lucene.store.Directory indexDirectory, boolean searchable, Collection<IndexingContext> contexts) throws IOException
IOExceptionIndexingContext addMergedIndexingContext(String id, String repositoryId, File repository, org.apache.lucene.store.Directory indexDirectory, boolean searchable, ContextMemberProvider membersProvider) throws IOException
IOExceptionvoid removeIndexingContext(IndexingContext context, boolean deleteFiles) throws IOException
context - deleteFiles - IOExceptionMap<String,IndexingContext> getIndexingContexts()
void scan(IndexingContext context) throws IOException
context - IOExceptionvoid scan(IndexingContext context, ArtifactScanningListener listener) throws IOException
context - listener - IOExceptionvoid scan(IndexingContext context, boolean update) throws IOException
context - update - if incremental reindex wanted, set true, otherwise false and full reindex will happenFIOExceptionvoid scan(IndexingContext context, ArtifactScanningListener listener, boolean update) throws IOException
context - listener - update - if incremental reindex wanted, set true, otherwise false and full reindex will happenFIOExceptionvoid scan(IndexingContext context, String fromPath, ArtifactScanningListener listener, boolean update) throws IOException
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 happenFIOExceptionvoid artifactDiscovered(ArtifactContext ac, IndexingContext context) throws IOException
IOExceptionvoid addArtifactToIndex(ArtifactContext ac, IndexingContext context) throws IOException
IOExceptionvoid addArtifactsToIndex(Collection<ArtifactContext> acs, IndexingContext context) throws IOException
IOExceptionvoid deleteArtifactFromIndex(ArtifactContext ac, IndexingContext context) throws IOException
IOExceptionvoid deleteArtifactsFromIndex(Collection<ArtifactContext> acs, IndexingContext context) throws IOException
IOExceptionFlatSearchResponse searchFlat(FlatSearchRequest request) throws IOException
request - IOExceptionIteratorSearchResponse searchIterator(IteratorSearchRequest request) throws IOException
request - IOExceptionGroupedSearchResponse searchGrouped(GroupedSearchRequest request) throws IOException
request - IOExceptionorg.apache.lucene.search.Query constructQuery(Field field, String query, SearchType type) throws IllegalArgumentException
constructQuery(Field, SearchExpression) instead.field - query - type - IllegalArgumentExceptionorg.apache.lucene.search.Query constructQuery(Field field, SearchExpression expression) throws IllegalArgumentException
field - expression - IllegalArgumentExceptionCollection<ArtifactInfo> identify(Field field, String query) throws IllegalArgumentException, IOException
IllegalArgumentExceptionIOExceptionCollection<ArtifactInfo> identify(File artifact) throws IOException
IOExceptionCollection<ArtifactInfo> identify(File artifact, Collection<IndexingContext> contexts) throws IOException
IOExceptionCollection<ArtifactInfo> identify(org.apache.lucene.search.Query query) throws IOException
IOExceptionCollection<ArtifactInfo> identify(org.apache.lucene.search.Query query, Collection<IndexingContext> contexts) throws IOException
IOExceptionCopyright © 2002-2013 The Apache Software Foundation. All Rights Reserved.