private IndexWriter newIndexWriter( IndexIdentifier identifier ) throws ExplicitIndexNotFoundKernelException { try { Directory indexDirectory = getIndexDirectory( identifier ); IndexType type = getType( identifier ); IndexWriterConfig writerConfig = new IndexWriterConfig( type.analyzer ); writerConfig.setIndexDeletionPolicy( new SnapshotDeletionPolicy( new KeepOnlyLastCommitDeletionPolicy() ) ); Similarity similarity = type.getSimilarity(); if ( similarity != null ) { writerConfig.setSimilarity( similarity ); } return new IndexWriter( indexDirectory, writerConfig ); } catch ( IOException e ) { throw new RuntimeException( e ); } } }
public static IndexWriterConfig standard( Analyzer analyzer ) { IndexWriterConfig writerConfig = new IndexWriterConfig( analyzer ); writerConfig.setMaxBufferedDocs( MAX_BUFFERED_DOCS ); writerConfig.setMaxBufferedDeleteTerms( MAX_BUFFERED_DELETE_TERMS ); writerConfig.setIndexDeletionPolicy( new SnapshotDeletionPolicy( new KeepOnlyLastCommitDeletionPolicy() ) ); writerConfig.setUseCompoundFile( true ); writerConfig.setRAMBufferSizeMB( STANDARD_RAM_BUFFER_SIZE_MB ); writerConfig.setCodec(new Lucene54Codec() { @Override public PostingsFormat getPostingsFormatForField( String field ) { PostingsFormat postingFormat = super.getPostingsFormatForField( field ); return CODEC_BLOCK_TREE_ORDS_POSTING_FORMAT ? blockTreeOrdsPostingsFormat : postingFormat; } }); if ( CUSTOM_MERGE_SCHEDULER ) { writerConfig.setMergeScheduler( new PooledConcurrentMergeScheduler() ); } LogByteSizeMergePolicy mergePolicy = new LogByteSizeMergePolicy(); mergePolicy.setNoCFSRatio( MERGE_POLICY_NO_CFS_RATIO ); mergePolicy.setMinMergeMB( MERGE_POLICY_MIN_MERGE_MB ); mergePolicy.setMergeFactor( MERGE_POLICY_MERGE_FACTOR ); writerConfig.setMergePolicy( mergePolicy ); return writerConfig; }
@Override protected IndexWriterConfig createIndexWriterConfig(IndexWriterConfig.OpenMode openMode) { IndexWriterConfig conf = super.createIndexWriterConfig(openMode); sdp = new SnapshotDeletionPolicy(conf.getIndexDeletionPolicy()); conf.setIndexDeletionPolicy(sdp); return conf; }
private void setUpWriterAndSearcher(Directory directory) throws LuceneException { log.info("Setting up the writer and searcher of {}", directory); try { ensureLockOnDirectory(directory); ensureCorrectIndexFormat(directory); ensureIndexExists(directory); IndexWriterConfig config = new IndexWriterConfig(BonnieConstants.LUCENE_VERSION, analyzerForIndexing); config.setIndexDeletionPolicy(new SnapshotDeletionPolicy(new KeepOnlyLastCommitDeletionPolicy())); writer = new InstrumentedIndexWriter(directory, config, metrics); snapshotter = (SnapshotDeletionPolicy) writer.getConfig().getIndexDeletionPolicy(); searcherLifetimeManager = new SearcherLifetimeManager(); searcherManager = newSearcherManager(); isClosed.set(false); writerIsClosed.set(false); } catch (IOException e) { throw new LuceneException(e); } }
public IndexWriter createWriter(File directory, boolean doUpgrade) throws Exception { Directory dir = MMapDirectory.open(directory.toPath()); Analyzer analyzer = new SimpleAnalyzer(); // Upgrade the index in place if necessary. if (doUpgrade && DirectoryReader.indexExists(dir)) { upgradeIndex(dir); } IndexWriterConfig iwc = new IndexWriterConfig(analyzer); iwc.setOpenMode(OpenMode.CREATE_OR_APPEND); iwc.setIndexDeletionPolicy(new SnapshotDeletionPolicy( new KeepOnlyLastCommitDeletionPolicy())); Long totalMBs = getHost().getServiceMemoryLimitMB(getSelfLink(), MemoryLimitType.EXACT); if (totalMBs != null) { // give half to the index, the other half we keep for service caching context totalMBs = Math.max(1, totalMBs / 2); iwc.setRAMBufferSizeMB(totalMBs); } this.writer = new IndexWriter(dir, iwc); this.writer.commit(); this.indexUpdateTimeMicros = Utils.getNowMicrosUtc(); this.indexWriterCreationTimeMicros = this.indexUpdateTimeMicros; return this.writer; }
iwc.setIndexDeletionPolicy(new SnapshotDeletionPolicy( new KeepOnlyLastCommitDeletionPolicy()));
masterDeletionPolicy = new SnapshotDeletionPolicy(new KeepOnlyLastCommitDeletionPolicy()); searchers = new ArrayList<RefreshableIndexSearcher>(); boolean transferIndex = createMasterStore();
this.codecService = new CodecService(mapperService, logger); this.warmer = warmer; this.deletionPolicy = new SnapshotDeletionPolicy(new KeepOnlyLastCommitDeletionPolicy()); this.similarityService = similarityService; Objects.requireNonNull(store, "Store must be provided to the index shard");
new SnapshotDeletionPolicy(indexWriterConfig.getIndexDeletionPolicy()); indexWriterConfig.setIndexDeletionPolicy(snapshotDeletionPolicy);