Java Code Examples for org.apache.lucene.util.LuceneTestCase#maybeChangeLiveIndexWriterConfig()
The following examples show how to use
org.apache.lucene.util.LuceneTestCase#maybeChangeLiveIndexWriterConfig() .
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: RandomIndexWriter.java From lucene-solr with Apache License 2.0 | 6 votes |
private void maybeFlushOrCommit() throws IOException { LuceneTestCase.maybeChangeLiveIndexWriterConfig(r, config); if (docCount++ == flushAt) { if (r.nextBoolean()) { flushAllBuffersSequentially(); } else if (r.nextBoolean()) { if (LuceneTestCase.VERBOSE) { System.out.println("RIW.add/updateDocument: now doing a flush at docCount=" + docCount); } w.flush(); } else { if (LuceneTestCase.VERBOSE) { System.out.println("RIW.add/updateDocument: now doing a commit at docCount=" + docCount); } w.commit(); } flushAt += TestUtil.nextInt(r, (int) (flushAtFactor * 10), (int) (flushAtFactor * 1000)); if (flushAtFactor < 2e6) { // gradually but exponentially increase time b/w flushes flushAtFactor *= 1.05; } } }
Example 2
Source File: RandomIndexWriter.java From lucene-solr with Apache License 2.0 | 6 votes |
/** * Close this writer. * @see IndexWriter#close() */ @Override public void close() throws IOException { boolean success = false; try { if (w.isClosed() == false) { LuceneTestCase.maybeChangeLiveIndexWriterConfig(r, config); } // if someone isn't using getReader() API, we want to be sure to // forceMerge since presumably they might open a reader on the dir. if (getReaderCalled == false && r.nextInt(8) == 2 && w.isClosed() == false) { doRandomForceMerge(); if (config.getCommitOnClose() == false) { // index may have changed, must commit the changes, or otherwise they are discarded by the call to close() w.commit(); } } success = true; } finally { if (success) { IOUtils.close(w, analyzer); } else { IOUtils.closeWhileHandlingException(w, analyzer); } } }
Example 3
Source File: RandomIndexWriter.java From lucene-solr with Apache License 2.0 | 6 votes |
/** * Updates a document. * @see IndexWriter#updateDocument(Term, Iterable) */ public <T extends IndexableField> long updateDocument(Term t, final Iterable<T> doc) throws IOException { LuceneTestCase.maybeChangeLiveIndexWriterConfig(r, config); final long seqNo; if (useSoftDeletes()) { if (r.nextInt(5) == 3) { seqNo = w.softUpdateDocuments(t, Arrays.asList(doc), new NumericDocValuesField(config.getSoftDeletesField(), 1)); } else { seqNo = w.softUpdateDocument(t, doc, new NumericDocValuesField(config.getSoftDeletesField(), 1)); } } else { if (r.nextInt(5) == 3) { seqNo = w.updateDocuments(t, Arrays.asList(doc)); } else { seqNo = w.updateDocument(t, doc); } } maybeFlushOrCommit(); return seqNo; }
Example 4
Source File: RandomIndexWriter.java From lucene-solr with Apache License 2.0 | 5 votes |
public long updateDocuments(Term delTerm, Iterable<? extends Iterable<? extends IndexableField>> docs) throws IOException { LuceneTestCase.maybeChangeLiveIndexWriterConfig(r, config); long seqNo; if (useSoftDeletes()) { seqNo = w.softUpdateDocuments(delTerm, docs, new NumericDocValuesField(config.getSoftDeletesField(), 1)); } else { seqNo = w.updateDocuments(delTerm, docs); } maybeFlushOrCommit(); return seqNo; }
Example 5
Source File: RandomIndexWriter.java From lucene-solr with Apache License 2.0 | 5 votes |
public DirectoryReader getReader(boolean applyDeletions, boolean writeAllDeletes) throws IOException { LuceneTestCase.maybeChangeLiveIndexWriterConfig(r, config); getReaderCalled = true; if (r.nextInt(20) == 2) { doRandomForceMerge(); } if (!applyDeletions || r.nextBoolean()) { // if we have soft deletes we can't open from a directory if (LuceneTestCase.VERBOSE) { System.out.println("RIW.getReader: use NRT reader"); } if (r.nextInt(5) == 1) { w.commit(); } return w.getReader(applyDeletions, writeAllDeletes); } else { if (LuceneTestCase.VERBOSE) { System.out.println("RIW.getReader: open new reader"); } w.commit(); if (r.nextBoolean()) { DirectoryReader reader = DirectoryReader.open(w.getDirectory()); if (config.getSoftDeletesField() != null) { return new SoftDeletesDirectoryReaderWrapper(reader, config.getSoftDeletesField()); } else { return reader; } } else { return w.getReader(applyDeletions, writeAllDeletes); } } }
Example 6
Source File: RandomIndexWriter.java From lucene-solr with Apache License 2.0 | 4 votes |
public long updateDocValues(Term term, Field... updates) throws IOException { LuceneTestCase.maybeChangeLiveIndexWriterConfig(r, config); return w.updateDocValues(term, updates); }
Example 7
Source File: RandomIndexWriter.java From lucene-solr with Apache License 2.0 | 4 votes |
public void forceMergeDeletes() throws IOException { LuceneTestCase.maybeChangeLiveIndexWriterConfig(r, config); w.forceMergeDeletes(); }
Example 8
Source File: RandomIndexWriter.java From lucene-solr with Apache License 2.0 | 4 votes |
public void forceMergeDeletes(boolean doWait) throws IOException { LuceneTestCase.maybeChangeLiveIndexWriterConfig(r, config); w.forceMergeDeletes(doWait); }
Example 9
Source File: RandomIndexWriter.java From lucene-solr with Apache License 2.0 | 4 votes |
public DirectoryReader getReader() throws IOException { LuceneTestCase.maybeChangeLiveIndexWriterConfig(r, config); return getReader(true, false); }
Example 10
Source File: RandomIndexWriter.java From lucene-solr with Apache License 2.0 | 4 votes |
public long deleteDocuments(Query q) throws IOException { LuceneTestCase.maybeChangeLiveIndexWriterConfig(r, config); return w.deleteDocuments(q); }
Example 11
Source File: RandomIndexWriter.java From lucene-solr with Apache License 2.0 | 4 votes |
public long deleteDocuments(Term term) throws IOException { LuceneTestCase.maybeChangeLiveIndexWriterConfig(r, config); return w.deleteDocuments(term); }
Example 12
Source File: RandomIndexWriter.java From lucene-solr with Apache License 2.0 | 4 votes |
/** * Adds a Document. * @see IndexWriter#addDocument(Iterable) */ public <T extends IndexableField> long addDocument(final Iterable<T> doc) throws IOException { LuceneTestCase.maybeChangeLiveIndexWriterConfig(r, config); long seqNo; if (r.nextInt(5) == 3) { // TODO: maybe, we should simply buffer up added docs // (but we need to clone them), and only when // getReader, commit, etc. are called, we do an // addDocuments? Would be better testing. seqNo = w.addDocuments(new Iterable<Iterable<T>>() { @Override public Iterator<Iterable<T>> iterator() { return new Iterator<Iterable<T>>() { boolean done; @Override public boolean hasNext() { return !done; } @Override public void remove() { throw new UnsupportedOperationException(); } @Override public Iterable<T> next() { if (done) { throw new IllegalStateException(); } done = true; return doc; } }; } }); } else { seqNo = w.addDocument(doc); } maybeFlushOrCommit(); return seqNo; }
Example 13
Source File: RandomIndexWriter.java From lucene-solr with Apache License 2.0 | 4 votes |
public long updateBinaryDocValue(Term term, String field, BytesRef value) throws IOException { LuceneTestCase.maybeChangeLiveIndexWriterConfig(r, config); return w.updateBinaryDocValue(term, field, value); }
Example 14
Source File: RandomIndexWriter.java From lucene-solr with Apache License 2.0 | 4 votes |
public long updateNumericDocValue(Term term, String field, Long value) throws IOException { LuceneTestCase.maybeChangeLiveIndexWriterConfig(r, config); return w.updateNumericDocValue(term, field, value); }
Example 15
Source File: RandomIndexWriter.java From lucene-solr with Apache License 2.0 | 4 votes |
public long addIndexes(CodecReader... readers) throws IOException { LuceneTestCase.maybeChangeLiveIndexWriterConfig(r, config); return w.addIndexes(readers); }
Example 16
Source File: RandomIndexWriter.java From lucene-solr with Apache License 2.0 | 4 votes |
public long addIndexes(Directory... dirs) throws IOException { LuceneTestCase.maybeChangeLiveIndexWriterConfig(r, config); return w.addIndexes(dirs); }
Example 17
Source File: RandomIndexWriter.java From lucene-solr with Apache License 2.0 | 4 votes |
public long addDocuments(Iterable<? extends Iterable<? extends IndexableField>> docs) throws IOException { LuceneTestCase.maybeChangeLiveIndexWriterConfig(r, config); long seqNo = w.addDocuments(docs); maybeFlushOrCommit(); return seqNo; }
Example 18
Source File: RandomIndexWriter.java From lucene-solr with Apache License 2.0 | 2 votes |
/** * Forces a forceMerge. * <p> * NOTE: this should be avoided in tests unless absolutely necessary, * as it will result in less test coverage. * @see IndexWriter#forceMerge(int) */ public void forceMerge(int maxSegmentCount) throws IOException { LuceneTestCase.maybeChangeLiveIndexWriterConfig(r, config); w.forceMerge(maxSegmentCount); }