mirror of https://github.com/apache/lucene.git
LUCENE-289 - added IndexReader.deleteDocument/.deleteDocuments and deprecated .delete(int)/.delete(Term).
CHANGES.txt already mentions deprecated methods sufficiently, so nothing further to note for this change. git-svn-id: https://svn.apache.org/repos/asf/lucene/java/trunk@354917 13f79535-47bb-0310-9956-ffa450edef68
This commit is contained in:
parent
ad9e9bceb4
commit
331748b8c3
|
@ -477,7 +477,20 @@ public abstract class IndexReader {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/** Deletes the document numbered <code>docNum</code>. Once a document is
|
||||||
|
* deleted it will not appear in TermDocs or TermPostitions enumerations.
|
||||||
|
* Attempts to read its field with the {@link #document}
|
||||||
|
* method will result in an error. The presence of this document may still be
|
||||||
|
* reflected in the {@link #docFreq} statistic, though
|
||||||
|
* this will be corrected eventually as the index is further modified.
|
||||||
|
*
|
||||||
|
* @deprecated Use {@link #deleteDocument(int docNum)} instead.
|
||||||
|
*/
|
||||||
|
public final synchronized void delete(int docNum) throws IOException {
|
||||||
|
deleteDocument(docNum);
|
||||||
|
}
|
||||||
|
|
||||||
/** Deletes the document numbered <code>docNum</code>. Once a document is
|
/** Deletes the document numbered <code>docNum</code>. Once a document is
|
||||||
* deleted it will not appear in TermDocs or TermPostitions enumerations.
|
* deleted it will not appear in TermDocs or TermPostitions enumerations.
|
||||||
* Attempts to read its field with the {@link #document}
|
* Attempts to read its field with the {@link #document}
|
||||||
|
@ -485,18 +498,34 @@ public abstract class IndexReader {
|
||||||
* reflected in the {@link #docFreq} statistic, though
|
* reflected in the {@link #docFreq} statistic, though
|
||||||
* this will be corrected eventually as the index is further modified.
|
* this will be corrected eventually as the index is further modified.
|
||||||
*/
|
*/
|
||||||
public final synchronized void delete(int docNum) throws IOException {
|
public final synchronized void deleteDocument(int docNum) throws IOException {
|
||||||
if(directoryOwner)
|
if(directoryOwner)
|
||||||
aquireWriteLock();
|
aquireWriteLock();
|
||||||
doDelete(docNum);
|
doDelete(docNum);
|
||||||
hasChanges = true;
|
hasChanges = true;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
/** Implements deletion of the document numbered <code>docNum</code>.
|
/** Implements deletion of the document numbered <code>docNum</code>.
|
||||||
* Applications should call {@link #delete(int)} or {@link #delete(Term)}.
|
* Applications should call {@link #delete(int)} or {@link #delete(Term)}.
|
||||||
*/
|
*/
|
||||||
protected abstract void doDelete(int docNum) throws IOException;
|
protected abstract void doDelete(int docNum) throws IOException;
|
||||||
|
|
||||||
|
/** Deletes all documents containing <code>term</code>.
|
||||||
|
* This is useful if one uses a document field to hold a unique ID string for
|
||||||
|
* the document. Then to delete such a document, one merely constructs a
|
||||||
|
* term with the appropriate field and the unique ID string as its text and
|
||||||
|
* passes it to this method.
|
||||||
|
* See {@link #delete(int)} for information about when this deletion will
|
||||||
|
* become effective.
|
||||||
|
* @return the number of documents deleted
|
||||||
|
*
|
||||||
|
* @deprecated Use {@link #deleteDocuments(Term term)} instead.
|
||||||
|
*/
|
||||||
|
public final int delete(Term term) throws IOException {
|
||||||
|
return deleteDocuments(term);
|
||||||
|
}
|
||||||
|
|
||||||
/** Deletes all documents containing <code>term</code>.
|
/** Deletes all documents containing <code>term</code>.
|
||||||
* This is useful if one uses a document field to hold a unique ID string for
|
* This is useful if one uses a document field to hold a unique ID string for
|
||||||
* the document. Then to delete such a document, one merely constructs a
|
* the document. Then to delete such a document, one merely constructs a
|
||||||
|
@ -506,13 +535,13 @@ public abstract class IndexReader {
|
||||||
* become effective.
|
* become effective.
|
||||||
* @return the number of documents deleted
|
* @return the number of documents deleted
|
||||||
*/
|
*/
|
||||||
public final int delete(Term term) throws IOException {
|
public final int deleteDocuments(Term term) throws IOException {
|
||||||
TermDocs docs = termDocs(term);
|
TermDocs docs = termDocs(term);
|
||||||
if (docs == null) return 0;
|
if (docs == null) return 0;
|
||||||
int n = 0;
|
int n = 0;
|
||||||
try {
|
try {
|
||||||
while (docs.next()) {
|
while (docs.next()) {
|
||||||
delete(docs.doc());
|
deleteDocument(docs.doc());
|
||||||
n++;
|
n++;
|
||||||
}
|
}
|
||||||
} finally {
|
} finally {
|
||||||
|
|
Loading…
Reference in New Issue