Class AbstractMemoryIndex

  • All Implemented Interfaces:
    java.lang.AutoCloseable, MemoryIndex
    Direct Known Subclasses:
    CpeMemoryIndex, NpmCpeMemoryIndex

    @ThreadSafe
    public abstract class AbstractMemoryIndex
    extends java.lang.Object
    implements MemoryIndex

    An in memory Lucene index that contains the vendor/product combinations from the CPE (application) identifiers within the NVD CVE data.

    This is the last remaining singleton in dependency-check-core; The use of this singleton - while it may not technically be thread-safe (one database used to build this index may not have the same entries as another) the risk of this is currently believed to be small. As this memory index consumes a large amount of memory we will remain using the singleton pattern for now.
    Author:
    Jeremy Long
    • Method Summary

      All Methods Instance Methods Abstract Methods Concrete Methods 
      Modifier and Type Method Description
      void close()
      Closes the CPE Index.
      java.lang.String explain​(org.apache.lucene.search.Query query, int doc)
      Method to explain queries matches.
      org.apache.lucene.document.Document getDocument​(int documentId)
      Retrieves a document from the Index.
      protected abstract AbstractMemoryIndex instance()
      Returns a reference to the instance.
      boolean isOpen()
      returns whether or not the index is open.
      int numDocs()
      Returns the number of CPE entries stored in the index.
      void open​(java.util.Set<Pair<java.lang.String,​java.lang.String>> data, Settings settings)
      Creates and loads data into an in memory index.
      org.apache.lucene.search.Query parseQuery​(java.lang.String searchString)
      Parses the given string into a Lucene Query.
      protected void resetAnalyzers()
      Common method to reset the searching analyzers.
      org.apache.lucene.search.TopDocs search​(java.lang.String searchString, int maxQueryResults)
      Searches the index using the given search string.
      org.apache.lucene.search.TopDocs search​(org.apache.lucene.search.Query query, int maxQueryResults)
      Searches the index using the given query.
      • Methods inherited from class java.lang.Object

        clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
    • Constructor Detail

      • AbstractMemoryIndex

        public AbstractMemoryIndex()
    • Method Detail

      • instance

        protected abstract AbstractMemoryIndex instance()
        Returns a reference to the instance.
        Returns:
        a reference to the instance
      • open

        public void open​(java.util.Set<Pair<java.lang.String,​java.lang.String>> data,
                         Settings settings)
                  throws IndexException
        Creates and loads data into an in memory index.
        Specified by:
        open in interface MemoryIndex
        Parameters:
        data - the CPE data
        settings - a reference to the dependency-check settings
        Throws:
        IndexException - thrown if there is an error creating the index
      • isOpen

        public boolean isOpen()
        returns whether or not the index is open.
        Returns:
        whether or not the index is open
      • close

        public void close()
        Closes the CPE Index.
        Specified by:
        close in interface java.lang.AutoCloseable
        Specified by:
        close in interface MemoryIndex
      • search

        public org.apache.lucene.search.TopDocs search​(java.lang.String searchString,
                                                       int maxQueryResults)
                                                throws org.apache.lucene.queryparser.classic.ParseException,
                                                       IndexException,
                                                       java.io.IOException
        Searches the index using the given search string.
        Specified by:
        search in interface MemoryIndex
        Parameters:
        searchString - the query text
        maxQueryResults - the maximum number of documents to return
        Returns:
        the TopDocs found by the search
        Throws:
        org.apache.lucene.queryparser.classic.ParseException - thrown when the searchString is invalid
        IndexException - thrown when there is an internal error resetting the search analyzer
        java.io.IOException - is thrown if there is an issue with the underlying Index
      • parseQuery

        public org.apache.lucene.search.Query parseQuery​(java.lang.String searchString)
                                                  throws org.apache.lucene.queryparser.classic.ParseException,
                                                         IndexException
        Parses the given string into a Lucene Query.
        Specified by:
        parseQuery in interface MemoryIndex
        Parameters:
        searchString - the search text
        Returns:
        the Query object
        Throws:
        org.apache.lucene.queryparser.classic.ParseException - thrown if the search text cannot be parsed
        IndexException - thrown if there is an error resetting the analyzers
      • search

        public org.apache.lucene.search.TopDocs search​(org.apache.lucene.search.Query query,
                                                       int maxQueryResults)
                                                throws org.apache.lucene.index.CorruptIndexException,
                                                       java.io.IOException
        Searches the index using the given query.
        Specified by:
        search in interface MemoryIndex
        Parameters:
        query - the query used to search the index
        maxQueryResults - the max number of results to return
        Returns:
        the TopDocs found be the query
        Throws:
        org.apache.lucene.index.CorruptIndexException - thrown if the Index is corrupt
        java.io.IOException - thrown if there is an IOException
      • getDocument

        public org.apache.lucene.document.Document getDocument​(int documentId)
                                                        throws java.io.IOException
        Retrieves a document from the Index.
        Specified by:
        getDocument in interface MemoryIndex
        Parameters:
        documentId - the id of the document to retrieve
        Returns:
        the Document
        Throws:
        java.io.IOException - thrown if there is an IOException
      • numDocs

        public int numDocs()
        Returns the number of CPE entries stored in the index.
        Returns:
        the number of CPE entries stored in the index
      • explain

        public java.lang.String explain​(org.apache.lucene.search.Query query,
                                        int doc)
                                 throws java.io.IOException
        Method to explain queries matches.
        Parameters:
        query - the query used
        doc - the document matched
        Returns:
        the explanation
        Throws:
        java.io.IOException - thrown if there is an index error
      • resetAnalyzers

        protected void resetAnalyzers()
                               throws java.io.IOException
        Common method to reset the searching analyzers.
        Throws:
        java.io.IOException - thrown if there is an index error