List of usage examples for org.apache.lucene.index IndexWriterConfig setOpenMode
public IndexWriterConfig setOpenMode(OpenMode openMode)
From source file:org.dspace.search.DSIndexer.java
License:BSD License
/** * prepare index, opening writer, and wiping out existing index if necessary */// ww w . ja va 2 s . c om private static IndexWriter openIndex(boolean wipeExisting) throws IOException { Directory dir = FSDirectory.open(new File(indexDirectory)); LimitTokenCountAnalyzer decoratorAnalyzer = null; /* Set maximum number of terms to index if present in dspace.cfg */ if (maxfieldlength == -1) { decoratorAnalyzer = new LimitTokenCountAnalyzer(getAnalyzer(), Integer.MAX_VALUE); } else { decoratorAnalyzer = new LimitTokenCountAnalyzer(getAnalyzer(), maxfieldlength); } IndexWriterConfig iwc = new IndexWriterConfig(luceneVersion, decoratorAnalyzer); if (wipeExisting) { iwc.setOpenMode(IndexWriterConfig.OpenMode.CREATE); } else { iwc.setOpenMode(IndexWriterConfig.OpenMode.CREATE_OR_APPEND); } IndexWriter writer = new IndexWriter(dir, iwc); return writer; }
From source file:org.dspace.search.LuceneIndex.java
License:BSD License
/** * prepare index, opening writer, and wiping out existing index if necessary *///w w w . j a v a 2 s .com private IndexWriter openIndex(boolean wipeExisting) throws IOException { Directory dir = FSDirectory.open(new File(indexDirectory)); IndexWriterConfig iwc = new IndexWriterConfig(Version.LUCENE_36, getAnalyzer()); if (wipeExisting) { iwc.setOpenMode(IndexWriterConfig.OpenMode.CREATE); } else { iwc.setOpenMode(IndexWriterConfig.OpenMode.CREATE_OR_APPEND); } IndexWriter writer = new IndexWriter(dir, iwc); return writer; }
From source file:org.eclipse.dltk.internal.core.index.lucene.IndexContainer.java
License:Open Source License
private IndexWriter createWriter(Path path) throws IOException { Directory indexDir = new IndexDirectory(path, SimpleFSLockFactory.INSTANCE); purgeLocks(path);/*from w ww .j a va 2s . c o m*/ IndexWriterConfig config = new IndexWriterConfig(new SimpleAnalyzer()); ConcurrentMergeScheduler mergeScheduler = new ConcurrentMergeScheduler(); mergeScheduler.setDefaultMaxMergesAndThreads(true); config.setMergeScheduler(mergeScheduler); config.setOpenMode(OpenMode.CREATE_OR_APPEND); config.setWriteLockTimeout(WRITE_LOCK_TIMEOUT); config.setCommitOnClose(false); return new IndexWriter(indexDir, config); }
From source file:org.eclipse.epp.internal.logging.aeri.ui.log.ProblemsDatabaseService.java
License:Open Source License
private void createInitialIndex(Directory directory) throws IOException { IndexWriterConfig conf = new IndexWriterConfig(Version.LUCENE_35, new KeywordAnalyzer()); conf.setOpenMode(OpenMode.CREATE_OR_APPEND); try (IndexWriter writer = new IndexWriter(directory, conf)) { Document meta = new Document(); meta.add(new Field(F_VERSION, VERSION, Store.YES, Index.NO)); writer.addDocument(meta);/*from ww w.j av a 2 s.c om*/ writer.commit(); } }
From source file:org.eclipse.epp.internal.logging.aeri.ui.log.ProblemsDatabaseService.java
License:Open Source License
public void replaceContent(File tempDir) throws IOException { IndexWriterConfig conf = new IndexWriterConfig(Version.LUCENE_35, new KeywordAnalyzer()); conf.setOpenMode(OpenMode.CREATE_OR_APPEND); try (IndexWriter writer = new IndexWriter(index, conf); FSDirectory newContent = FSDirectory.open(tempDir);) { writer.deleteAll();//from ww w . j a v a2 s . co m writer.addIndexes(newContent); writer.commit(); manager.maybeReopen(); } }
From source file:org.eclipse.epp.internal.logging.aeri.ui.log.ReportHistory.java
License:Open Source License
private void createWriter() throws CorruptIndexException, LockObtainFailedException, IOException { IndexWriterConfig conf = new IndexWriterConfig(Version.LUCENE_35, new KeywordAnalyzer()); conf.setOpenMode(OpenMode.CREATE_OR_APPEND); writer = new IndexWriter(index, conf); // to build an initial index if empty: if (writer.numDocs() == 0) { buildInitialIndex();/*from w w w .ja v a 2 s . c om*/ } }
From source file:org.eclipse.rdf4j.sail.lucene.LuceneIndex.java
License:Open Source License
private void postInit() throws IOException { this.queryAnalyzer = new StandardAnalyzer(); // do some initialization for new indices if (!DirectoryReader.indexExists(directory)) { logger.debug("creating new Lucene index in directory {}", directory); IndexWriterConfig indexWriterConfig = new IndexWriterConfig(analyzer); indexWriterConfig.setOpenMode(OpenMode.CREATE); IndexWriter writer = new IndexWriter(directory, indexWriterConfig); writer.close();/*from w w w .j a v a2s. c o m*/ } }
From source file:org.eclipse.rdf4j.sail.lucene.LuceneIndex.java
License:Open Source License
/** * /*from w w w .j av a 2 s .c om*/ */ @Override public synchronized void clear() throws IOException { if (closed.get()) { throw new SailException("Index has been closed"); } // clear // the old IndexReaders/Searchers are not outdated invalidateReaders(); if (indexWriter != null) indexWriter.close(); // crate new writer IndexWriterConfig indexWriterConfig = new IndexWriterConfig(analyzer); indexWriterConfig.setOpenMode(OpenMode.CREATE); indexWriter = new IndexWriter(directory, indexWriterConfig); indexWriter.close(); indexWriter = null; }
From source file:org.eclipse.recommenders.snipmatch.FileSnippetRepository.java
License:Open Source License
private void doIndex(File[] snippetFiles) throws IOException { IndexWriterConfig config = new IndexWriterConfig(Version.LUCENE_35, analyzer); config.setOpenMode(OpenMode.CREATE); IndexWriter writer = new IndexWriter(directory, config); try {/*from ww w. ja v a 2 s. c o m*/ snippetCache.invalidateAll(); for (File snippetFile : snippetFiles) { try { ISnippet snippet = snippetCache.get(snippetFile); String path = snippetFile.getPath(); indexSnippet(writer, snippet, path); } catch (Exception e) { log.error("Failed to index snippet in " + snippetFile, e); } } } finally { writer.close(); } if (reader != null) { reader = IndexReader.openIfChanged(reader); } }
From source file:org.elasticsearch.action.termvector.AbstractTermVectorTests.java
License:Apache License
protected DirectoryReader indexDocsWithLucene(TestDoc[] testDocs) throws IOException { Map<String, Analyzer> mapping = new HashMap<String, Analyzer>(); for (TestFieldSetting field : testDocs[0].fieldSettings) { if (field.storedPayloads) { mapping.put(field.name, new Analyzer() { @Override/*from w w w. j av a 2 s. co m*/ protected TokenStreamComponents createComponents(String fieldName, Reader reader) { Tokenizer tokenizer = new StandardTokenizer(Version.CURRENT.luceneVersion, reader); TokenFilter filter = new LowerCaseFilter(Version.CURRENT.luceneVersion, tokenizer); filter = new TypeAsPayloadTokenFilter(filter); return new TokenStreamComponents(tokenizer, filter); } }); } } PerFieldAnalyzerWrapper wrapper = new PerFieldAnalyzerWrapper( new StandardAnalyzer(Version.CURRENT.luceneVersion, CharArraySet.EMPTY_SET), mapping); Directory dir = new RAMDirectory(); IndexWriterConfig conf = new IndexWriterConfig(Version.CURRENT.luceneVersion, wrapper); conf.setOpenMode(IndexWriterConfig.OpenMode.CREATE); IndexWriter writer = new IndexWriter(dir, conf); for (TestDoc doc : testDocs) { Document d = new Document(); d.add(new Field("id", doc.id, StringField.TYPE_STORED)); for (int i = 0; i < doc.fieldContent.length; i++) { FieldType type = new FieldType(TextField.TYPE_STORED); TestFieldSetting fieldSetting = doc.fieldSettings[i]; type.setStoreTermVectorOffsets(fieldSetting.storedOffset); type.setStoreTermVectorPayloads(fieldSetting.storedPayloads); type.setStoreTermVectorPositions( fieldSetting.storedPositions || fieldSetting.storedPayloads || fieldSetting.storedOffset); type.setStoreTermVectors(true); type.freeze(); d.add(new Field(fieldSetting.name, doc.fieldContent[i], type)); } writer.updateDocument(new Term("id", doc.id), d); writer.commit(); } writer.close(); return DirectoryReader.open(dir); }