public NewIndexer(String indexDir2) throws IOException { // create the index if (indexWriter2 == null) { indexWriter2 = new IndexWriter( FSDirectory.open(new File("resultsList")), new IndexWriterConfig( Version.LUCENE_36, new EnglishAnalyzer(Version.LUCENE_36, StandardAnalyzer.STOP_WORDS_SET))); indexWriter2.deleteAll(); } }
// add items to index public void newIndex(NewIndexItem newIndexItem) throws IOException { // deleting the item, if already exists // indexWriter.deleteDocuments(new Term(IndexItem.SEARCHLABEL, // indexItem.getSearchLabel().toString())); Document doc = new Document(); doc.add( new Field( NewIndexItem.QUERYNUMBER, newIndexItem.getNewQueryNumber().toString(), Field.Store.YES, Field.Index.ANALYZED)); doc.add( new Field( NewIndexItem.TERMID, newIndexItem.getNewTermID().toString(), Field.Store.YES, Field.Index.ANALYZED)); doc.add( new Field( NewIndexItem.LABEL, newIndexItem.getNewLabel().toString(), Field.Store.YES, Field.Index.ANALYZED)); doc.add( new Field( NewIndexItem.SEARCHLABEL, newIndexItem.getNewSearchLabel().toString(), Field.Store.YES, Field.Index.ANALYZED)); doc.add( new Field( NewIndexItem.QUERYTERM, newIndexItem.getNewQueryTerm().toString(), Field.Store.YES, Field.Index.ANALYZED)); doc.add( new Field( NewIndexItem.NUMOFRESULTS, newIndexItem.getNewNumOfResults().toString(), Field.Store.YES, Field.Index.ANALYZED)); // add the document to the index indexWriter2.addDocument(doc); }
// Closing the index public void close() throws IOException { indexWriter2.close(); }