private void buildIndex ( CveDB cve ) throws IndexException { try ( Analyzer analyzer = createSearchingAnalyzer ( ) ; IndexWriter indexWriter = new IndexWriter ( index , new IndexWriterConfig ( analyzer ) ) ) { final FieldType ft = new FieldType ( TextField . TYPE_STORED ) ; //ignore term frequency ft . setIndexOptions ( IndexOptions . DOCS ) ; //ignore field length normalization ft . setOmitNorms ( true ) ; // Tip: reuse the Document and Fields for performance... // See "Re-use Document and Field instances" from // http://wiki.apache.org/lucene-java/ImproveIndexingSpeed final Document doc = new Document ( ) ; final Field v = new Field ( Fields . VENDOR , Fields . VENDOR , ft ) ; final Field p = new Field ( Fields . PRODUCT , Fields . PRODUCT , ft ) ; doc . add ( v ) ; doc . add ( p ) ; final Set < Pair < String , String > > data = cve . getVendorProductList ( ) ; for ( Pair < String , String > pair : data ) { if ( pair . getLeft ( ) != null && pair . getRight ( ) != null ) { v . setStringValue ( pair . getLeft ( ) ) ; p . setStringValue ( pair . getRight ( ) ) ; indexWriter . addDocument ( doc ) ; resetAnalyzers ( ) ; } } indexWriter . commit ( ) ; } catch ( DatabaseException ex ) { LOGGER . debug ( "" , ex ) ; throw new IndexException ( "Error reading CPE data" , ex ) ; } catch ( IOException ex ) { throw new IndexException ( "Unable to close an in-memory index" , ex ) ; } }
Builds the CPE Lucene Index based off of the data within the CveDB .