List of usage examples for org.apache.lucene.index IndexWriter IndexWriter
public IndexWriter(Directory d, IndexWriterConfig conf) throws IOException
conf
. From source file:biospectra.index.Indexer.java
License:Apache License
private void initialize(File indexPath, int kmerSize, boolean minStrandKmer, Similarity similarity, int workerThreads, int ramBufferSize) throws Exception { if (!indexPath.exists()) { indexPath.mkdirs();//from w ww . j a v a 2 s. co m } if (indexPath.exists()) { cleanUpDirectory(indexPath); } this.indexPath = indexPath; this.minStrandKmer = minStrandKmer; this.analyzer = new KmerIndexAnalyzer(kmerSize, minStrandKmer); Directory dir = new MMapDirectory(this.indexPath.toPath()); IndexWriterConfig config = new IndexWriterConfig(this.analyzer); if (similarity != null) { config.setSimilarity(similarity); } this.workerThreads = workerThreads; if (ramBufferSize > 0) { config.setRAMBufferSizeMB(ramBufferSize); } config.setOpenMode(IndexWriterConfig.OpenMode.CREATE_OR_APPEND); this.indexWriter = new IndexWriter(dir, config); this.executor = new BlockingExecutor(this.workerThreads, this.workerThreads * 2); for (int i = 0; i < this.workerThreads; i++) { Document doc = new Document(); Field filenameField = new StringField(IndexConstants.FIELD_FILENAME, "", Field.Store.YES); Field headerField = new StringField(IndexConstants.FIELD_HEADER, "", Field.Store.YES); Field sequenceDirectionField = new StringField(IndexConstants.FIELD_SEQUENCE_DIRECTION, "", Field.Store.YES); Field taxonTreeField = new StringField(IndexConstants.FIELD_TAXONOMY_TREE, "", Field.Store.YES); Field sequenceField = new TextField(IndexConstants.FIELD_SEQUENCE, "", Field.Store.NO); doc.add(filenameField); doc.add(headerField); doc.add(sequenceDirectionField); doc.add(taxonTreeField); doc.add(sequenceField); this.freeQueue.offer(doc); } }
From source file:BlockBuilding.AbstractBlockBuilding.java
License:Apache License
protected IndexWriter openWriter(Directory directory) { try {/* w ww. ja v a 2s . c o m*/ Analyzer analyzer = new SimpleAnalyzer(); IndexWriterConfig config = new IndexWriterConfig(analyzer); return new IndexWriter(directory, config); } catch (IOException ex) { LOGGER.log(Level.SEVERE, null, ex); return null; } }
From source file:BlockBuilding.AbstractIndexBasedMethod.java
License:Open Source License
protected IndexWriter openWriter(Directory directory) { try {//from w w w . j a v a2 s. c o m Analyzer analyzer = new SimpleAnalyzer(Version.LUCENE_40); IndexWriterConfig config = new IndexWriterConfig(Version.LUCENE_40, analyzer); return new IndexWriter(directory, config); } catch (IOException ex) { ex.printStackTrace(); return null; } }
From source file:book.Indexer.java
License:Apache License
public Indexer(String indexDir) throws IOException { Directory dir = FSDirectory.open(new File(indexDir).toPath()); Analyzer analyzer = new StandardAnalyzer(); IndexWriterConfig iwc = new IndexWriterConfig(analyzer); writer = new IndexWriter(dir, iwc); // 3 modified }
From source file:br.andrew.lucene.testing.IndexFiles.java
License:Apache License
/** Index all text files under a directory. */ public static void main(final String[] args) { final String usage = "java org.apache.lucene.demo.IndexFiles" + " [-index INDEX_PATH] [-docs DOCS_PATH] [-update]\n\n" + "This indexes the documents in DOCS_PATH, creating a Lucene index" + "in INDEX_PATH that can be searched with SearchFiles"; final String indexPath = "index"; final File docDir = new File("data"); final Date start = new Date(); try {/*from w w w . java 2 s .c o m*/ System.out.println("Indexing to directory '" + indexPath + "'..."); final Directory dir = FSDirectory.open(new File(indexPath)); final Analyzer analyzer = new StandardAnalyzer(Version.LUCENE_40); final IndexWriterConfig iwc = new IndexWriterConfig(Version.LUCENE_40, analyzer); iwc.setOpenMode(OpenMode.CREATE); // Optional: for better indexing performance, if you // are indexing many documents, increase the RAM // buffer. But if you do this, increase the max heap // size to the JVM (eg add -Xmx512m or -Xmx1g): // // iwc.setRAMBufferSizeMB(256.0); final IndexWriter writer = new IndexWriter(dir, iwc); IndexFiles.indexDocs(writer, docDir); // NOTE: if you want to maximize search performance, // you can optionally call forceMerge here. This can be // a terribly costly operation, so generally it's only // worth it when your index is relatively static (ie // you're done adding documents to it): // // writer.forceMerge(1); writer.close(); final Date end = new Date(); System.out.println(end.getTime() - start.getTime() + " total milliseconds"); } catch (final IOException e) { System.out.println(" caught a " + e.getClass() + "\n with message: " + e.getMessage()); } }
From source file:br.bireme.ngrams.NGIndex.java
private IndexWriter getIndexWriter(final String indexPath, final Analyzer analyzer, final boolean append) throws IOException { assert indexPath != null; assert analyzer != null; final File dir = new File(indexPath); final Directory directory = FSDirectory.open(dir.toPath()); final IndexWriterConfig cfg = new IndexWriterConfig(analyzer); if (append) { cfg.setOpenMode(IndexWriterConfig.OpenMode.APPEND); } else {/*ww w. j av a2 s .c o m*/ new File(dir, "write.lock").delete(); cfg.setOpenMode(IndexWriterConfig.OpenMode.CREATE); } return new IndexWriter(directory, cfg); }
From source file:br.com.crawlerspring.model.Searcher.java
public void prepareSearch() throws IOException { IndexWriterConfig config = new IndexWriterConfig(Version.LUCENE_40, analyzer); IndexWriter writer = new IndexWriter(index, config); for (br.com.crawlerspring.model.Document document : documentDao.getDocuments()) { addDoc(writer, document.getTitle(), document.getContent()); }/*from ww w.j a v a 2 s . c om*/ writer.close(); }
From source file:br.pucminas.ri.jsearch.queryexpansion.RocchioQueryExpansion.java
License:Open Source License
private Directory createIndex(ArrayList<Document> relevantDocs) throws CorruptIndexException, LockObtainFailedException, IOException { Directory index = new RAMDirectory(); PorterStemAnalyzer analyzer = new PorterStemAnalyzer(); IndexWriterConfig conf = new IndexWriterConfig(analyzer); try (IndexWriter idxWriter = new IndexWriter(index, conf)) { for (Document d : relevantDocs) { idxWriter.addDocument(d);/* w w w. j a v a2 s .c om*/ } } return index; }
From source file:br.ufmt.harmonizacao.generics.Indexer.java
public Indexer(Class<? extends Analyzer> cl, String path) throws Exception { Constructor<? extends Analyzer> c = cl.getConstructor(Version.class); Analyzer a = c.newInstance(new Object[] { Version.LUCENE_47 }); analyzer = a;/*w ww .j ava2 s. co m*/ dirName = analyzer.getClass().getCanonicalName(); this.path = path + dirName; dir = FSDirectory.open(new File(this.path)); IndexWriterConfig config = new IndexWriterConfig(Version.LUCENE_47, analyzer); writer = new IndexWriter(dir, config); }
From source file:br.usp.icmc.gazetteer.SemanticSearchTest.LuceneSearcher.java
License:Open Source License
public void similiaridade1() throws IOException { IndexWriterConfig conf = new IndexWriterConfig(Version.LUCENE_36, a); conf.setSimilarity(similarityltc()); writer = new IndexWriter(dir, conf); }