public <T extends IndexableField> void addDocument(final IndexDocument doc, Analyzer a) throws IOException { 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. w.addDocuments( new Iterable<IndexDocument>() { @Override public Iterator<IndexDocument> iterator() { return new Iterator<IndexDocument>() { boolean done; @Override public boolean hasNext() { return !done; } @Override public void remove() { throw new UnsupportedOperationException(); } @Override public IndexDocument next() { if (done) { throw new IllegalStateException(); } done = true; return doc; } }; } }, a); } else { w.addDocument(doc, a); } maybeCommit(); }
/** * Updates a document. * * @see IndexWriter#updateDocument(Term, org.apache.lucene.index.IndexDocument) */ public <T extends IndexableField> void updateDocument(Term t, final IndexDocument doc) throws IOException { if (r.nextInt(5) == 3) { w.updateDocuments( t, new Iterable<IndexDocument>() { @Override public Iterator<IndexDocument> iterator() { return new Iterator<IndexDocument>() { boolean done; @Override public boolean hasNext() { return !done; } @Override public void remove() { throw new UnsupportedOperationException(); } @Override public IndexDocument next() { if (done) { throw new IllegalStateException(); } done = true; return doc; } }; } }); } else { w.updateDocument(t, doc); } maybeCommit(); }
public void updateDocuments(Term delTerm, Iterable<? extends IndexDocument> docs) throws IOException { w.updateDocuments(delTerm, docs); maybeCommit(); }
public void addDocuments(Iterable<? extends IndexDocument> docs) throws IOException { w.addDocuments(docs); maybeCommit(); }