.getIndexReader().document(docID) */
public Document doc(int docID) throws CorruptIndexException, IOException {
- return reader.document(docID);
+ return reader.document(docID, null, null);
}
+ /** see {@link IndexReader#document(int, Set, Set)} for detail*/
+ public Document doc(int docID, Set.getIndexReader().document(docID, fieldVisitor) */
public void doc(int docID, StoredFieldVisitor fieldVisitor) throws CorruptIndexException, IOException {
reader.document(docID, fieldVisitor);
Index: src/java/org/apache/lucene/index/IndexReader.java
===================================================================
--- src/java/org/apache/lucene/index/IndexReader.java (版本 1211892)
+++ src/java/org/apache/lucene/index/IndexReader.java (工作副本)
@@ -24,6 +24,7 @@
import java.util.Collection;
import java.util.List;
import java.util.Map;
+import java.util.Set;
import java.util.concurrent.atomic.AtomicInteger;
import org.apache.lucene.document.Document;
@@ -882,11 +883,22 @@
// Document returned here contains that class not
// IndexableField
public Document document(int docID) throws CorruptIndexException, IOException {
+ return document(docID, null, null);
+ }
+
+ /**
+ * Manipulate the specific fields to be loaded with two sets.
+ * The fieldsToFilter is provided because there is usually less fields carry huge data. + * And in this scenario it needs not to check other fields
+ * @param fieldsToAdd fields to be loaded + * @param fieldsToFilter fields to be filtered + */ + public Document document(int docID, final SetSet<String>. */
- public DocumentStoredFieldVisitor(SetSet<String>.
+ * And do not load fields in provided List<String> */
+ public DocumentStoredFieldVisitor(SetSet<String>. */
@@ -48,11 +52,13 @@
for(String field : fields) {
fieldsToAdd.add(field);
}
+ this.fieldsToFilter = null;
}
/** Load all stored fields. */
public DocumentStoredFieldVisitor() {
this.fieldsToAdd = null;
+ this.fieldsToFilter = null;
}
@Override
@@ -103,7 +109,9 @@
@Override
public Status needsField(FieldInfo fieldInfo) throws IOException {
- return fieldsToAdd == null || fieldsToAdd.contains(fieldInfo.name) ? Status.YES : Status.NO;
+ return (fieldsToFilter == null || !fieldsToFilter.contains(fieldInfo.name)) &&
+ (fieldsToAdd == null || fieldsToAdd.contains(fieldInfo.name)) ?
+ Status.YES : Status.NO;
}
public Document getDocument() {