Package org.apache.maven.index
Class DefaultIndexer
- java.lang.Object
-
- org.apache.maven.index.DefaultIndexer
-
-
Field Summary
Fields Modifier and Type Field Description private static char[]DIGITSprivate IndexerEngineindexerEngineprivate QueryCreatorqueryCreatorprivate SearchEnginesearcher
-
Constructor Summary
Constructors Constructor Description DefaultIndexer(SearchEngine searcher, IndexerEngine indexerEngine, QueryCreator queryCreator)
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Modifier and Type Method Description voidaddArtifactsToIndex(java.util.Collection<ArtifactContext> ac, IndexingContext context)Adds the passed in artifact contexts to passed in indexing context.voidaddArtifactToIndex(ArtifactContext ac, IndexingContext context)Adds the passed in artifact contexts to passed in indexing context.voidcloseIndexingContext(IndexingContext context, boolean deleteFiles)Closes the indexing context: closes it and deletes (if specified) the index files.org.apache.lucene.search.QueryconstructQuery(Field field, java.lang.String expression, SearchType searchType)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 search.org.apache.lucene.search.QueryconstructQuery(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 search.IndexingContextcreateIndexingContext(java.lang.String id, java.lang.String repositoryId, java.io.File repository, java.io.File indexDirectory, java.lang.String repositoryUrl, java.lang.String indexUpdateUrl, boolean searchable, boolean reclaim, java.util.List<? extends IndexCreator> indexers)Creates an indexing context.IndexingContextcreateMergedIndexingContext(java.lang.String id, java.lang.String repositoryId, java.io.File repository, java.io.File indexDirectory, boolean searchable, ContextMemberProvider membersProvider)Creates a merged indexing context.voiddeleteArtifactsFromIndex(java.util.Collection<ArtifactContext> ac, IndexingContext context)Removes the passed in artifacts contexts from passed in indexing context.private static java.lang.Stringencode(byte[] digest)java.util.Collection<ArtifactInfo>identify(java.io.File artifact, java.util.Collection<IndexingContext> contexts)Performs an "identity" search.java.util.Collection<ArtifactInfo>identify(org.apache.lucene.search.Query query, java.util.Collection<IndexingContext> contexts)Performs an "identity" search.FlatSearchResponsesearchFlat(FlatSearchRequest request)Searches according the request parameters.GroupedSearchResponsesearchGrouped(GroupedSearchRequest request)Searches according the request parameters.IteratorSearchResponsesearchIterator(IteratorSearchRequest request)Searches according to request parameters.
-
-
-
Field Detail
-
searcher
private final SearchEngine searcher
-
indexerEngine
private final IndexerEngine indexerEngine
-
queryCreator
private final QueryCreator queryCreator
-
DIGITS
private static final char[] DIGITS
-
-
Constructor Detail
-
DefaultIndexer
@Inject public DefaultIndexer(SearchEngine searcher, IndexerEngine indexerEngine, QueryCreator queryCreator)
-
-
Method Detail
-
createIndexingContext
public IndexingContext createIndexingContext(java.lang.String id, java.lang.String repositoryId, java.io.File repository, java.io.File indexDirectory, java.lang.String repositoryUrl, java.lang.String indexUpdateUrl, boolean searchable, boolean reclaim, java.util.List<? extends IndexCreator> indexers) throws java.io.IOException, ExistingLuceneIndexMismatchException, java.lang.IllegalArgumentException
Description copied from interface:IndexerCreates an indexing context.- Specified by:
createIndexingContextin interfaceIndexer- Parameters:
id- the ID of the context.repositoryId- the ID of the repository that this context represents. You might have several contexts indexing same repository ID, but on separate locations.repository- the location of the repository on FS.indexDirectory- the location of the Lucene indexes on FS.repositoryUrl- the location of the remote repository ornullif this indexing context does not need remote updates (is not a proxy).indexUpdateUrl- the alternate location of the remote repository indexes (if they are not in default place) ornullif defaults are applicable.searchable- if context should be searched in non-targeted mode.reclaim- if indexDirectory is known to contain (or should contain) valid Maven Indexer lucene index, and no checks needed to be performed, or, if we want to "stomp" over existing index (unsafe to do!).indexers- the set of indexers to apply to this context.- Returns:
- the context created.
- Throws:
java.io.IOException- in case of some serious IO problem.ExistingLuceneIndexMismatchException- 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. Never thrown ifreclaimistrue, as in that case, if Lucene index exists but any of those criteria above are not met, the existing index is overwritten, and equipped with proper descriptor silently.java.lang.IllegalArgumentException- in case the supplied list of IndexCreators are having non-satisfiable dependencies.
-
createMergedIndexingContext
public IndexingContext createMergedIndexingContext(java.lang.String id, java.lang.String repositoryId, java.io.File repository, java.io.File indexDirectory, boolean searchable, ContextMemberProvider membersProvider) throws java.io.IOException
Description copied from interface:IndexerCreates a merged indexing context.- Specified by:
createMergedIndexingContextin interfaceIndexer- Parameters:
id- the ID of the context.repositoryId- the ID of the repository that this context represents. You might have several contexts indexing same repository ID, but on separate locations.repository- the location of the repository on FS.indexDirectory- the location of the Lucene indexes on FS.searchable- if context should be searched in non-targeted mode.membersProvider- theContextMemberProvider, never null.- Returns:
- the context created.
- Throws:
java.io.IOException- in case of some serious IO problem.
-
closeIndexingContext
public void closeIndexingContext(IndexingContext context, boolean deleteFiles) throws java.io.IOException
Description copied from interface:IndexerCloses the indexing context: closes it and deletes (if specified) the index files.- Specified by:
closeIndexingContextin interfaceIndexer- Parameters:
context- the one needed to be closed, nevernull.deleteFiles-trueif all indexer related files (including Lucene index!) needs to be deleted,falseotherwise.- Throws:
java.io.IOException
-
addArtifactToIndex
public void addArtifactToIndex(ArtifactContext ac, IndexingContext context) throws java.io.IOException
Description copied from interface:IndexerAdds the passed in artifact contexts to passed in indexing context.- Specified by:
addArtifactToIndexin interfaceIndexer- Throws:
java.io.IOException
-
addArtifactsToIndex
public void addArtifactsToIndex(java.util.Collection<ArtifactContext> ac, IndexingContext context) throws java.io.IOException
Description copied from interface:IndexerAdds the passed in artifact contexts to passed in indexing context.- Specified by:
addArtifactsToIndexin interfaceIndexer- Throws:
java.io.IOException
-
deleteArtifactsFromIndex
public void deleteArtifactsFromIndex(java.util.Collection<ArtifactContext> ac, IndexingContext context) throws java.io.IOException
Description copied from interface:IndexerRemoves the passed in artifacts contexts from passed in indexing context.- Specified by:
deleteArtifactsFromIndexin interfaceIndexer- Throws:
java.io.IOException
-
searchFlat
public FlatSearchResponse searchFlat(FlatSearchRequest request) throws java.io.IOException
Description copied from interface:IndexerSearches according the request parameters.- Specified by:
searchFlatin interfaceIndexer- Returns:
- search response
- Throws:
java.io.IOException
-
searchIterator
public IteratorSearchResponse searchIterator(IteratorSearchRequest request) throws java.io.IOException
Description copied from interface:IndexerSearches according to request parameters.- Specified by:
searchIteratorin interfaceIndexer- Returns:
- search response
- Throws:
java.io.IOException
-
searchGrouped
public GroupedSearchResponse searchGrouped(GroupedSearchRequest request) throws java.io.IOException
Description copied from interface:IndexerSearches according the request parameters.- Specified by:
searchGroupedin interfaceIndexer- Returns:
- search response
- Throws:
java.io.IOException
-
identify
public java.util.Collection<ArtifactInfo> identify(java.io.File artifact, java.util.Collection<IndexingContext> contexts) throws java.io.IOException
Description copied from interface:IndexerPerforms an "identity" search. Passed inFilewill have SHA1 hash calculated, and anIndexer.identify(Query, Collection)method will be invoked searching with calculated hash theMAVEN.SHA1field. This is just a shorthand method, as these calls are simply calculating hex encoded SHA1 of the file, and invoking theIndexer.constructQuery(Field, SearchExpression)andIndexer.identify(Query, Collection)methods.
-
identify
public java.util.Collection<ArtifactInfo> identify(org.apache.lucene.search.Query query, java.util.Collection<IndexingContext> contexts) throws java.io.IOException
Description copied from interface:IndexerPerforms an "identity" search. Those are usually simple key-value queries, involving "unique" fields likeMAVEN.SHA1or such.
-
constructQuery
public org.apache.lucene.search.Query constructQuery(Field field, SearchExpression expression) throws java.lang.IllegalArgumentException
Description copied from interface:IndexerHelper 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 search.- Specified by:
constructQueryin interfaceIndexer- Returns:
- the query to be used for search.
- Throws:
java.lang.IllegalArgumentException- See Also:
SearchExpression,UserInputSearchExpression,SourcedSearchExpression
-
constructQuery
public org.apache.lucene.search.Query constructQuery(Field field, java.lang.String expression, SearchType searchType) throws java.lang.IllegalArgumentException
Description copied from interface:IndexerHelper 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 search.- Specified by:
constructQueryin interfaceIndexer- Returns:
- Throws:
java.lang.IllegalArgumentException
-
encode
private static java.lang.String encode(byte[] digest)
-
-