/** * Constructor over the given {@link IndexWriter}. Uses the last * {@link IndexCommit} found in the {@link Directory} managed by the given * writer. */ public IndexAndTaxonomyRevision(IndexWriter indexWriter, SnapshotDirectoryTaxonomyWriter taxoWriter) throws IOException { IndexDeletionPolicy delPolicy = indexWriter.getConfig().getIndexDeletionPolicy(); if (!(delPolicy instanceof SnapshotDeletionPolicy)) { throw new IllegalArgumentException("IndexWriter must be created with SnapshotDeletionPolicy"); } this.indexWriter = indexWriter; this.taxoWriter = taxoWriter; this.indexSDP = (SnapshotDeletionPolicy) delPolicy; this.taxoSDP = taxoWriter.getDeletionPolicy(); this.indexCommit = indexSDP.snapshot(); this.taxoCommit = taxoSDP.snapshot(); this.version = revisionVersion(indexCommit, taxoCommit); this.sourceFiles = revisionFiles(indexCommit, taxoCommit); }
public void test() throws Exception { Directory dir = null; IndexDeletionPolicy policy = new KeepOnlyLastCommitDeletionPolicy(); SnapshotDeletionPolicy snapshotter = new SnapshotDeletionPolicy(policy); IndexWriterConfig conf = new IndexWriterConfig(Version.LUCENE_41, AosAnalyser.NO_LIMIT_TOKEN_COUNT_SIMPLE_ANALYSER); conf.setIndexDeletionPolicy(snapshotter); IndexWriter writer = new IndexWriter(dir, conf); try { IndexCommit commit = snapshotter.snapshot("unique-id"); Collection<String> fileNames = commit.getFileNames(); /* <iterate over & copy files from fileNames> */ } finally { snapshotter.release("unique-id"); } }
@Override protected void configure() { bind(IndexDeletionPolicy.class) .annotatedWith(Names.named("actual")) .to(KeepOnlyLastDeletionPolicy.class) .asEagerSingleton(); bind(SnapshotDeletionPolicy.class) .asEagerSingleton(); }
public void updateIndex(Directory dir, int base, int numDocs, IndexDeletionPolicy policy) throws IOException { IndexWriter writer = new IndexWriter(dir, false, new StandardAnalyzer(), policy); writer.setMaxBufferedDocs(maxBufferedDocs); writer.setMergeFactor(1000); for (int i = 0; i < numDocs; i++) { addDoc(writer, base + i); } writer.close(); }
public static IndexDeletionPolicy getIndexDeletionPolicy(Config config) { String deletionPolicyName = config.get("deletion.policy", "org.apache.lucene.index.KeepOnlyLastCommitDeletionPolicy"); if (deletionPolicyName.equals(NoDeletionPolicy.class.getName())) { return NoDeletionPolicy.INSTANCE; } else { try { return Class.forName(deletionPolicyName).asSubclass(IndexDeletionPolicy.class).newInstance(); } catch (Exception e) { throw new RuntimeException("unable to instantiate class '" + deletionPolicyName + "' as IndexDeletionPolicy", e); } } }
/** * Constructor over the given {@link IndexWriter}. Uses the last * {@link IndexCommit} found in the {@link Directory} managed by the given * writer. */ public IndexRevision(IndexWriter writer) throws IOException { IndexDeletionPolicy delPolicy = writer.getConfig().getIndexDeletionPolicy(); if (!(delPolicy instanceof SnapshotDeletionPolicy)) { throw new IllegalArgumentException("IndexWriter must be created with SnapshotDeletionPolicy"); } this.writer = writer; this.sdp = (SnapshotDeletionPolicy) delPolicy; this.commit = sdp.snapshot(); this.version = revisionVersion(commit); this.sourceFiles = revisionFiles(commit); }
private SolrIndexWriter(String name, String path, Directory directory, boolean create, IndexSchema schema, SolrIndexConfig config, IndexDeletionPolicy delPolicy, Codec codec) throws IOException { super(directory, config.toIndexWriterConfig(schema). setOpenMode(create ? IndexWriterConfig.OpenMode.CREATE : IndexWriterConfig.OpenMode.APPEND). setIndexDeletionPolicy(delPolicy).setCodec(codec) ); log.debug("Opened Writer " + name); this.name = name; infoStream = getConfig().getInfoStream(); this.directory = directory; numOpens.incrementAndGet(); }
private void initDeletionPolicy() { PluginInfo info = solrConfig.getPluginInfo(IndexDeletionPolicy.class.getName()); IndexDeletionPolicy delPolicy = null; if(info != null){ delPolicy = createInstance(info.className,IndexDeletionPolicy.class,"Deletion Policy for SOLR"); if (delPolicy instanceof NamedListInitializedPlugin) { ((NamedListInitializedPlugin) delPolicy).init(info.initArgs); } } else { delPolicy = new SolrDeletionPolicy(); } solrDelPolicy = new IndexDeletionPolicyWrapper(delPolicy); }
private SolrIndexWriter(String name, String path, Directory directory, boolean create, IndexSchema schema, SolrIndexConfig config, IndexDeletionPolicy delPolicy, Codec codec) throws IOException { super(directory, config.toIndexWriterConfig(schema). setOpenMode(create ? IndexWriterConfig.OpenMode.CREATE : IndexWriterConfig.OpenMode.APPEND). setIndexDeletionPolicy(delPolicy).setCodec(codec).setInfoStream(toInfoStream(config)) ); log.debug("Opened Writer " + name); this.name = name; numOpens.incrementAndGet(); }
private void initDeletionPolicy() { PluginInfo info = solrConfig.getPluginInfo(IndexDeletionPolicy.class.getName()); IndexDeletionPolicy delPolicy = null; if(info != null) { delPolicy = createInstance(info.className, IndexDeletionPolicy.class, "Deletion Policy for SOLR"); if(delPolicy instanceof NamedListInitializedPlugin) { ((NamedListInitializedPlugin) delPolicy).init(info.initArgs); } } else { delPolicy = new SolrDeletionPolicy(); } solrDelPolicy = new IndexDeletionPolicyWrapper(delPolicy); }
private SolrIndexWriter(String name, String path, Directory directory, boolean create, IndexSchema schema, SolrIndexConfig config, IndexDeletionPolicy delPolicy, Codec codec) throws IOException { super(directory, config.toIndexWriterConfig(schema). setOpenMode(create ? IndexWriterConfig.OpenMode.CREATE : IndexWriterConfig.OpenMode.APPEND). setIndexDeletionPolicy(delPolicy).setCodec(codec) ); log.debug("Opened Writer " + name); this.name = name; numOpens.incrementAndGet(); }
/** * Constructs a new snapshot deletion policy that wraps the provided deletion policy. */ @Inject public SnapshotDeletionPolicy(@Named("actual") IndexDeletionPolicy primary) { super(((IndexShardComponent) primary).shardId(), ((IndexShardComponent) primary).indexSettings()); this.primary = primary; }
@Override public IndexDeletionPolicy clone() { // Lucene IW makes a clone internally but since we hold on to this instance // the clone will just be the identity. See InternalEngine recovery why we need this. return this; }
public IndexDeletionPolicyWrapper(IndexDeletionPolicy deletionPolicy) { this.deletionPolicy = deletionPolicy; }