Refine search
private void ensureLuceneDataInstantiated() { if ( this.directory == null ) { try { this.directory = new RAMDirectory(); IndexWriterConfig writerConfig = new IndexWriterConfig( index.type.analyzer ); this.writer = new IndexWriter( directory, writerConfig ); } catch ( IOException e ) { throw new RuntimeException( e ); } } }
IndexWriterConfig config = new IndexWriterConfig(Version.LUCENE_47, analyzer).setOpenMode(OpenMode.CREATE); final IndexWriter writer = new IndexWriter(directory, config); for (Stop stop : graphIndex.stopForId.values()) { addStop(writer, stop); addCorner(writer, sv); writer.close(); long elapsedTime = System.currentTimeMillis() - startTime; LOG.info("Built Lucene index in {} msec", elapsedTime);
/** * Removes all terms from the spell check index. * @throws IOException */ public void clearIndex() throws IOException { IndexWriter writer = new IndexWriter(spellIndex, null, true); writer.close(); // COMASS: Remove closing the searcher //close the old searcher // searcher.close(); // searcher = new IndexSearcher(this.spellIndex); }
/** * Get the index writer/searcher wrapper for the given connection. * * @param conn the connection * @return the index access wrapper */ protected static IndexAccess getIndexAccess(Connection conn) throws SQLException { String path = getIndexPath(conn); synchronized (INDEX_ACCESS) { IndexAccess access = INDEX_ACCESS.get(path); if (access == null) { try { Directory indexDir = path.startsWith(IN_MEMORY_PREFIX) ? new RAMDirectory() : FSDirectory.open(new File(path)); Analyzer analyzer = new StandardAnalyzer(Version.LUCENE_30); IndexWriterConfig conf = new IndexWriterConfig(Version.LUCENE_30, analyzer); conf.setOpenMode(IndexWriterConfig.OpenMode.CREATE_OR_APPEND); IndexWriter writer = new IndexWriter(indexDir, conf); //see http://wiki.apache.org/lucene-java/NearRealtimeSearch access = new IndexAccess(writer); } catch (IOException e) { throw convertException(e); } INDEX_ACCESS.put(path, access); } return access; } }
LOGGER.log(Level.INFO, "Optimizing the index{0}", projectDetail); Analyzer analyzer = new StandardAnalyzer(); IndexWriterConfig conf = new IndexWriterConfig(analyzer); conf.setOpenMode(OpenMode.CREATE_OR_APPEND); wrt = new IndexWriter(indexDirectory, conf); wrt.forceMerge(1); // this is deprecated and not needed anymore elapsed.report(LOGGER, String.format("Done optimizing index%s", projectDetail)); if (wrt != null) { try { wrt.close(); } catch (IOException e) { if (writerException == null) {
private boolean optimizeIndex() { boolean result = false; try { IndexWriter indexWriter = new IndexWriter(directory, analyzer, false, IndexWriter.MaxFieldLength.UNLIMITED); indexWriter.optimize(); indexWriter.close(); result = true; } catch (IOException e) { //logger.error("Error while trying to optimize index."); } return result; }
private IndexWriter instantiateWriter( File folder ) { Directory dir = null; try { dir = LuceneDataSource.getDirectory( folder, identifier ); IndexWriterConfig writerConfig = new IndexWriterConfig( type.analyzer ); writerConfig.setRAMBufferSizeMB( determineGoodBufferSize( writerConfig.getRAMBufferSizeMB() ) ); return new IndexWriter( dir, writerConfig ); } catch ( IOException e ) { IOUtils.closeAllSilently( dir ); throw new RuntimeException( e ); } }
IndexWriterConfig iwc = new IndexWriterConfig(Version.LUCENE_47, analyzer); iwc.setOpenMode(OpenMode.CREATE_OR_APPEND); IndexWriter writer = new IndexWriter(dir, iwc); writer.close();
public synchronized void createIndex(String subContext, String subIndex) throws SearchEngineException { Directory dir = openDirectory(subContext, subIndex); try { IndexWriter indexWriter = new IndexWriter(dir, new StandardAnalyzer(), true); indexWriter.close(); } catch (IOException e) { throw new SearchEngineException("Failed to create index for sub index [" + subIndex + "]", e); } }
public void open() throws Exception { if ( !directory.exists() && !directory.mkdirs() ) { throw new IOException("Could not make: " + directory); } IndexWriterConfig conf = new IndexWriterConfig(Version.LUCENE_35, new KeywordAnalyzer()).setOpenMode(IndexWriterConfig.OpenMode.CREATE); niofsDirectory = new NIOFSDirectory(directory, new SingleInstanceLockFactory()); writer = new IndexWriter(niofsDirectory, conf); }
try { Analyzer analyzer = AnalyzerGuru.getAnalyzer(); IndexWriterConfig iwc = new IndexWriterConfig(analyzer); iwc.setOpenMode(OpenMode.CREATE_OR_APPEND); iwc.setRAMBufferSizeMB(env.getRamBufferSize()); writer = new IndexWriter(indexDirectory, iwc); try { if (writer != null) { writer.close();
public static void main(String[] args) { String index = args[0]; try { IndexWriter i = new IndexWriter(FSDirectory.open(new File(index)), new WhitespaceAnalyzer(), IndexWriter.MaxFieldLength.LIMITED); i.optimize(); i.close(); } catch (Exception e) { e.printStackTrace(); } } }
private IndexWriterCount createWriter(final File indexDirectory) throws IOException { final List<Closeable> closeables = new ArrayList<>(); final Directory directory = FSDirectory.open(indexDirectory); closeables.add(directory); try { final Analyzer analyzer = new StandardAnalyzer(); closeables.add(analyzer); final IndexWriterConfig config = new IndexWriterConfig(LuceneUtil.LUCENE_VERSION, analyzer); final ConcurrentMergeScheduler mergeScheduler = new ConcurrentMergeScheduler(); final int mergeThreads = repoConfig.getConcurrentMergeThreads(); mergeScheduler.setMaxMergesAndThreads(mergeThreads, mergeThreads); config.setMergeScheduler(mergeScheduler); final IndexWriter indexWriter = new IndexWriter(directory, config); final EventIndexWriter eventIndexWriter = new LuceneEventIndexWriter(indexWriter, indexDirectory); final IndexWriterCount writerCount = new IndexWriterCount(eventIndexWriter, analyzer, directory, 1, false); logger.debug("Providing new index writer for {}", indexDirectory); return writerCount; } catch (final IOException ioe) { for (final Closeable closeable : closeables) { try { closeable.close(); } catch (final IOException ioe2) { ioe.addSuppressed(ioe2); } } throw ioe; } }
public void addCorpora(List<Path> corpora, double ramBufferInMb) throws IOException { Directory dir = FSDirectory.open(indexPath); Analyzer analyzer = CustomAnalyzer.builder() .withTokenizer("standard") .addTokenFilter(LuceneLemmaFilter.Factory.class) .build(); IndexWriterConfig iwc = new IndexWriterConfig(analyzer); iwc.setOpenMode(OpenMode.CREATE_OR_APPEND); iwc.setRAMBufferSizeMB(ramBufferInMb); IndexWriter writer = new IndexWriter(dir, iwc); for (Path path : corpora) { Log.info("Adding %s", path); addDocs(writer, path); } writer.close(); }
private static synchronized void create() throws IOException { if (directory != null) { return; } final RAMDirectory ram = new RAMDirectory(); IndexWriter w = new IndexWriter(ram, Factory.get().writerConfig()); w.commit(); w.close(); directory = ram; } }
writer = new IndexWriter(dir, new IndexWriterConfig(new StandardAnalyzer()));
w.close(); IndexWriterConfig indexWriterConfig = new IndexWriterConfig(analyzer); LogDocMergePolicy logDocMergePolicy = new LogDocMergePolicy(); logDocMergePolicy.setMergeFactor(1000); indexWriterConfig.setMergePolicy(logDocMergePolicy); w = new IndexWriter(index, indexWriterConfig);
private void buildIndex() throws IOException, ParseException { IndexWriter writer = new IndexWriter(_bundle.getStopSearchIndexPath(), new StandardAnalyzer(), true, IndexWriter.MaxFieldLength.LIMITED); for (Stop stop : _dao.getAllStops()) { Document document = getStopAsDocument(stop); writer.addDocument(document); } writer.optimize(); writer.close(); _refreshService.refresh(RefreshableResources.STOP_SEARCH_DATA); }
private IndexRepositoryImpl createIndexRepo() throws IOException { ConcurrentHashMap fileAndChunkRegion = new ConcurrentHashMap(); RegionDirectory dir = new RegionDirectory(fileAndChunkRegion, fileSystemStats); IndexWriterConfig config = new IndexWriterConfig(analyzer); IndexWriter writer = new IndexWriter(dir, config); LuceneIndex index = Mockito.mock(LuceneIndex.class); Mockito.when(index.getFieldNames()).thenReturn(new String[] {"txt"}); return new IndexRepositoryImpl(region, writer, mapper, indexStats, null, null, "", index); }
IndexWriter writer = new IndexWriter(store.directory(), new IndexWriterConfig(null) .setSoftDeletesField(Lucene.SOFT_DELETES_FIELD) .setOpenMode(IndexWriterConfig.OpenMode.CREATE) .setCommitOnClose(true)); writer.close(); return;