Class DefaultIndexer

  • All Implemented Interfaces:
    Indexer

    @Singleton
    @Named
    public class DefaultIndexer
    extends java.lang.Object
    implements Indexer
    A default Indexer implementation.
    • Field Detail

      • DIGITS

        private static final char[] DIGITS
    • 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: Indexer
        Creates an indexing context.
        Specified by:
        createIndexingContext in interface Indexer
        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 or null if 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) or null if 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 if reclaim is true, 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: Indexer
        Creates a merged indexing context.
        Specified by:
        createMergedIndexingContext in interface Indexer
        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 - the ContextMemberProvider, 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: Indexer
        Closes the indexing context: closes it and deletes (if specified) the index files.
        Specified by:
        closeIndexingContext in interface Indexer
        Parameters:
        context - the one needed to be closed, never null.
        deleteFiles - true if all indexer related files (including Lucene index!) needs to be deleted, false otherwise.
        Throws:
        java.io.IOException
      • addArtifactToIndex

        public void addArtifactToIndex​(ArtifactContext ac,
                                       IndexingContext context)
                                throws java.io.IOException
        Description copied from interface: Indexer
        Adds the passed in artifact contexts to passed in indexing context.
        Specified by:
        addArtifactToIndex in interface Indexer
        Throws:
        java.io.IOException
      • addArtifactsToIndex

        public void addArtifactsToIndex​(java.util.Collection<ArtifactContext> ac,
                                        IndexingContext context)
                                 throws java.io.IOException
        Description copied from interface: Indexer
        Adds the passed in artifact contexts to passed in indexing context.
        Specified by:
        addArtifactsToIndex in interface Indexer
        Throws:
        java.io.IOException
      • deleteArtifactsFromIndex

        public void deleteArtifactsFromIndex​(java.util.Collection<ArtifactContext> ac,
                                             IndexingContext context)
                                      throws java.io.IOException
        Description copied from interface: Indexer
        Removes the passed in artifacts contexts from passed in indexing context.
        Specified by:
        deleteArtifactsFromIndex in interface Indexer
        Throws:
        java.io.IOException
      • searchFlat

        public FlatSearchResponse searchFlat​(FlatSearchRequest request)
                                      throws java.io.IOException
        Description copied from interface: Indexer
        Searches according the request parameters.
        Specified by:
        searchFlat in interface Indexer
        Returns:
        search response
        Throws:
        java.io.IOException
      • 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: Indexer
        Performs an "identity" search. Those are usually simple key-value queries, involving "unique" fields like MAVEN.SHA1 or such.
        Specified by:
        identify in interface Indexer
        Returns:
        collection of identified matches.
        Throws:
        java.io.IOException
      • constructQuery

        public org.apache.lucene.search.Query constructQuery​(Field field,
                                                             SearchExpression expression)
                                                      throws java.lang.IllegalArgumentException
        Description copied from interface: Indexer
        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.
        Specified by:
        constructQuery in interface Indexer
        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: Indexer
        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.
        Specified by:
        constructQuery in interface Indexer
        Returns:
        Throws:
        java.lang.IllegalArgumentException
      • encode

        private static java.lang.String encode​(byte[] digest)