Skip to content

armgit / solr

Public Imported from GitHub
0

Apache Solr open-source search software

Likewise rename the delete methods for IndexModifier, deprecating the old (though not strictly necessary since IndexModifier was added after 1.4.3)

Erik Hatchercf4c00556ce8
diff --git a/src/java/org/apache/lucene/index/IndexModifier.java b/src/java/org/apache/lucene/index/IndexModifier.java
index 03edb88798c..e5400e48f9b 100644
--- a/src/java/org/apache/lucene/index/IndexModifier.java
+++ b/src/java/org/apache/lucene/index/IndexModifier.java
@@ -58,7 +58,7 @@ import org.apache.lucene.store.FSDirectory;
<font color="#ffffff">&nbsp;&nbsp;&nbsp;&nbsp;</font><font color="#000000">indexModifier.flush</font><font color="#000000">()</font><font color="#000000">;</font><br/>
<font color="#ffffff">&nbsp;&nbsp;&nbsp;&nbsp;</font><font color="#000000">System.out.println</font><font color="#000000">(</font><font color="#000000">indexModifier.docCount</font><font color="#000000">()&nbsp;</font><font color="#000000">+&nbsp;</font><font color="#2a00ff">&#34;&nbsp;docs&nbsp;in&nbsp;index&#34;</font><font color="#000000">)</font><font color="#000000">;</font><br/>
<font color="#ffffff">&nbsp;&nbsp;&nbsp;&nbsp;</font><font color="#000000">indexModifier.close</font><font color="#000000">()</font><font color="#000000">;</font></code>
-
+
</td>
<!-- end source code -->
</tr>
@@ -67,31 +67,31 @@ import org.apache.lucene.store.FSDirectory;
<!-- = END of automatically generated HTML code = -->
<!-- ======================================================== -->
*
- * <p>Not all methods of IndexReader and IndexWriter are offered by this
- * class. If you need access to additional methods, either use those classes
+ * <p>Not all methods of IndexReader and IndexWriter are offered by this
+ * class. If you need access to additional methods, either use those classes
* directly or implement your own class that extends <code>IndexModifier</code>.
- *
+ *
* <p>Although an instance of this class can be used from more than one
- * thread, you will not get the best performance. You might want to use
- * IndexReader and IndexWriter directly for that (but you will need to
+ * thread, you will not get the best performance. You might want to use
+ * IndexReader and IndexWriter directly for that (but you will need to
* care about synchronization yourself then).
- *
+ *
* <p>While you can freely mix calls to add() and delete() using this class,
* you should batch you calls for best performance. For example, if you
* want to update 20 documents, you should first delete all those documents,
* then add all the new documents.
- *
+ *
* @author Daniel Naber
*/
public class IndexModifier {
-
+
protected IndexWriter indexWriter = null;
protected IndexReader indexReader = null;
-
+
protected Directory directory = null;
protected Analyzer analyzer = null;
protected boolean open = false;
-
+
// Lucene defaults:
protected PrintStream infoStream = null;
protected boolean useCompoundFile = true;
@@ -101,7 +101,7 @@ public class IndexModifier {
/**
* Open an index with write access.
- *
+ *
* @param directory the index directory
* @param analyzer the analyzer to use for adding new documents
* @param create <code>true</code> to create the index or overwrite the existing one;
@@ -113,7 +113,7 @@ public class IndexModifier {
/**
* Open an index with write access.
- *
+ *
* @param dirName the index directory
* @param analyzer the analyzer to use for adding new documents
* @param create <code>true</code> to create the index or overwrite the existing one;
@@ -123,10 +123,10 @@ public class IndexModifier {
Directory dir = FSDirectory.getDirectory(dirName, create);
init(dir, analyzer, create);
}
-
+
/**
* Open an index with write access.
- *
+ *
* @param file the index directory
* @param analyzer the analyzer to use for adding new documents
* @param create <code>true</code> to create the index or overwrite the existing one;
@@ -249,29 +249,54 @@ public class IndexModifier {
* term with the appropriate field and the unique ID string as its text and
* passes it to this method. Returns the number of documents deleted.
* @return the number of documents deleted
- * @see IndexReader#delete(Term)
+ * @see IndexReader#deleteDocuments(Term)
* @throws IllegalStateException if the index is closed
*/
- public int delete(Term term) throws IOException {
+ public int deleteDocuments(Term term) throws IOException {
synchronized(directory) {
assureOpen();
createIndexReader();
- return indexReader.delete(term);
+ return indexReader.deleteDocuments(term);
}
}
+ /**
+ * 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. Returns the number of documents deleted.
+ * @return the number of documents deleted
+ * @see IndexReader#deleteDocuments(Term)
+ * @throws IllegalStateException if the index is closed
+ * @deprecated Use {@link #deleteDocuments(Term)} instead.
+ */
+ public int delete(Term term) throws IOException {
+ return deleteDocuments(term);
+ }
+
/**
* Deletes the document numbered <code>docNum</code>.
- * @see IndexReader#delete(int)
+ * @see IndexReader#deleteDocument(int)
* @throws IllegalStateException if the index is closed
*/
- public void delete(int docNum) throws IOException {
+ public void deleteDocument(int docNum) throws IOException {
synchronized(directory) {
assureOpen();
createIndexReader();
- indexReader.delete(docNum);
+ indexReader.deleteDocument(docNum);
}
}
+
+ /**
+ * Deletes the document numbered <code>docNum</code>.
+ * @see IndexReader#deleteDocument(int)
+ * @throws IllegalStateException if the index is closed
+ * @deprecated Use {@link #deleteDocument(int)} instead.
+ */
+ public void delete(int docNum) throws IOException {
+ deleteDocument(docNum);
+ }
/**
* Returns the number of documents currently in this index.
@@ -320,7 +345,7 @@ public class IndexModifier {
this.infoStream = infoStream;
}
}
-
+
/**
* @throws IOException
* @see IndexModifier#setInfoStream(PrintStream)
@@ -361,7 +386,7 @@ public class IndexModifier {
return indexWriter.getUseCompoundFile();
}
}
-
+
/**
* The maximum number of terms that will be indexed for a single field in a
* document. This limits the amount of memory required for indexing, so that
@@ -397,7 +422,7 @@ public class IndexModifier {
return indexWriter.getMaxFieldLength();
}
}
-
+
/**
* The maximum number of terms that will be indexed for a single field in a
* document. This limits the amount of memory required for indexing, so that
@@ -443,7 +468,7 @@ public class IndexModifier {
* for batch index creation, and smaller values (&lt; 10) for indices that are
* interactively maintained.
* <p>This must never be less than 2. The default value is 10.
- *
+ *
* @see IndexWriter#setMergeFactor(int)
* @throws IllegalStateException if the index is closed
*/
@@ -471,7 +496,7 @@ public class IndexModifier {
/**
* Close this index, writing all pending changes to disk.
- *
+ *
* @throws IllegalStateException if the index has been closed before already
*/
public void close() throws IOException {
@@ -488,11 +513,11 @@ public class IndexModifier {
open = false;
}
}
-
+
public String toString() {
return "Index@" + directory;
}
-
+
/*
// used as an example in the javadoc:
public static void main(String[] args) throws IOException {