Class AbstractMemoryIndex
java.lang.Object
org.owasp.dependencycheck.data.cpe.AbstractMemoryIndex
- All Implemented Interfaces:
AutoCloseable, MemoryIndex
- Direct Known Subclasses:
CpeMemoryIndex, NpmCpeMemoryIndex
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
-
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionvoidclose()Closes the CPE Index.explain(org.apache.lucene.search.Query query, int doc) Method to explain queries matches.org.apache.lucene.document.DocumentgetDocument(int documentId) Retrieves a document from the Index.protected abstract AbstractMemoryIndexinstance()Returns a reference to the instance.booleanisOpen()returns whether or not the index is open.intnumDocs()Returns the number of CPE entries stored in the index.voidCreates and loads data into an in memory index.org.apache.lucene.search.QueryparseQuery(String searchString) Parses the given string into a Lucene Query.protected voidCommon method to reset the searching analyzers.org.apache.lucene.search.TopDocsSearches the index using the given search string.org.apache.lucene.search.TopDocssearch(org.apache.lucene.search.Query query, int maxQueryResults) Searches the index using the given query.
-
Constructor Details
-
AbstractMemoryIndex
public AbstractMemoryIndex()
-
-
Method Details
-
instance
Returns a reference to the instance.- Returns:
- a reference to the instance
-
open
Creates and loads data into an in memory index.- Specified by:
openin interfaceMemoryIndex- Parameters:
data- the CPE datasettings- 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:
closein interfaceAutoCloseable- Specified by:
closein interfaceMemoryIndex
-
search
public org.apache.lucene.search.TopDocs search(String searchString, int maxQueryResults) throws org.apache.lucene.queryparser.classic.ParseException, IndexException, IOException Searches the index using the given search string.- Specified by:
searchin interfaceMemoryIndex- Parameters:
searchString- the query textmaxQueryResults- 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 invalidIndexException- thrown when there is an internal error resetting the search analyzerIOException- is thrown if there is an issue with the underlying Index
-
parseQuery
public org.apache.lucene.search.Query parseQuery(String searchString) throws org.apache.lucene.queryparser.classic.ParseException, IndexException Parses the given string into a Lucene Query.- Specified by:
parseQueryin interfaceMemoryIndex- Parameters:
searchString- the search text- Returns:
- the Query object
- Throws:
org.apache.lucene.queryparser.classic.ParseException- thrown if the search text cannot be parsedIndexException- 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, IOException Searches the index using the given query.- Specified by:
searchin interfaceMemoryIndex- Parameters:
query- the query used to search the indexmaxQueryResults- 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 corruptIOException- thrown if there is an IOException
-
getDocument
Retrieves a document from the Index.- Specified by:
getDocumentin interfaceMemoryIndex- Parameters:
documentId- the id of the document to retrieve- Returns:
- the Document
- Throws:
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
Method to explain queries matches.- Parameters:
query- the query useddoc- the document matched- Returns:
- the explanation
- Throws:
IOException- thrown if there is an index error
-
resetAnalyzers
Common method to reset the searching analyzers.- Throws:
IOException- thrown if there is an index error
-