Apache Lucene open-source search software
new method: public abstract Collection getFieldNames(FieldOption fldOption) added to IndexReader. This is a replacement for all existing IndexReader.getFieldName methods. All the other methods are marked deprecated and should be removed with 2.0
Bernhard Messer8f5e0f64068f
diff --git a/src/java/org/apache/lucene/index/FilterIndexReader.java b/src/java/org/apache/lucene/index/FilterIndexReader.javaindex a6f50a3ac70..5b968430aa9 100644--- a/src/java/org/apache/lucene/index/FilterIndexReader.java+++ b/src/java/org/apache/lucene/index/FilterIndexReader.java@@ -141,4 +141,8 @@ public class FilterIndexReader extends IndexReader {public Collection getIndexedFieldNames (Field.TermVector tvSpec){return in.getIndexedFieldNames(tvSpec);}++ public Collection getFieldNames(IndexReader.FieldOption fieldNames) {+ return in.getFieldNames(fieldNames);+ }}diff --git a/src/java/org/apache/lucene/index/IndexReader.java b/src/java/org/apache/lucene/index/IndexReader.javaindex 3aca75afd7e..eece42f0a90 100644--- a/src/java/org/apache/lucene/index/IndexReader.java+++ b/src/java/org/apache/lucene/index/IndexReader.java@@ -47,6 +47,35 @@ import java.util.Set;*/public abstract class IndexReader {+ public static final class FieldOption {+ private String option;+ private FieldOption() { }+ private FieldOption(String option) {+ this.option = option;+ }+ public String toString() {+ return this.option;+ }+ // all fields+ public static final FieldOption ALL = new FieldOption ("ALL");+ // all indexed fields+ public static final FieldOption INDEXED = new FieldOption ("INDEXED");+ // all fields which are not indexed+ public static final FieldOption UNINDEXED = new FieldOption ("UNINDEXED");+ // all fields which are indexed with termvectors enables+ public static final FieldOption INDEXED_WITH_TERMVECTOR = new FieldOption ("INDEXED_WITH_TERMVECTOR");+ // all fields which are indexed but don't have termvectors enabled+ public static final FieldOption INDEXED_NO_TERMVECTOR = new FieldOption ("INDEXED_NO_TERMVECTOR");+ // all fields where termvectors are enabled. Please note that only standard termvector fields are returned+ public static final FieldOption TERMVECTOR = new FieldOption ("TERMVECTOR");+ // all field with termvectors wiht positions enabled+ public static final FieldOption TERMVECTOR_WITH_POSITION = new FieldOption ("TERMVECTOR_WITH_POSITION");+ // all fields where termvectors with offset position are set+ public static final FieldOption TERMVECTOR_WITH_OFFSET = new FieldOption ("TERMVECTOR_WITH_OFFSET");+ // all fields where termvectors with offset and position values set+ public static final FieldOption TERMVECTOR_WITH_POSITION_OFFSET = new FieldOption ("TERMVECTOR_WITH_POSITION_OFFSET");+ }+/*** Constructor used if IndexReader is not owner of its directory.* This is used for IndexReaders that are used within other IndexReaders that take care or locking directories.@@ -113,12 +142,12 @@ public abstract class IndexReader {infos.read(directory);if (infos.size() == 1) { // index is optimizedreturn SegmentReader.get(infos, infos.info(0), closeDirectory);- } else {- IndexReader[] readers = new IndexReader[infos.size()];- for (int i = 0; i < infos.size(); i++)- readers[i] = SegmentReader.get(infos.info(i));- return new MultiReader(directory, infos, closeDirectory, readers);}+ IndexReader[] readers = new IndexReader[infos.size()];+ for (int i = 0; i < infos.size(); i++)+ readers[i] = SegmentReader.get(infos.info(i));+ return new MultiReader(directory, infos, closeDirectory, readers);+}}.run();}@@ -544,6 +573,8 @@ public abstract class IndexReader {* to by this IndexReader.* @return Collection of Strings indicating the names of the fields* @throws IOException if there is a problem with accessing the index+ *+ * @deprecated Replaced by {@link #getFieldNames (IndexReader.FieldOption fldOption)}*/public abstract Collection getFieldNames() throws IOException;@@ -555,6 +586,8 @@ public abstract class IndexReader {* <code>false</code> if only unindexed fields should be returned.* @return Collection of Strings indicating the names of the fields* @throws IOException if there is a problem with accessing the index+ *+ * @deprecated Replaced by {@link #getFieldNames (IndexReader.FieldOption fldOption)}*/public abstract Collection getFieldNames(boolean indexed) throws IOException;@@ -564,7 +597,7 @@ public abstract class IndexReader {* else only indexed fields without term vector info* @return Collection of Strings indicating the names of the fields*- * @deprecated Replaced by {@link #getIndexedFieldNames (Field.TermVector tvSpec)}+ * @deprecated Replaced by {@link #getFieldNames (IndexReader.FieldOption fldOption)}*/public Collection getIndexedFieldNames(boolean storedTermVector){if(storedTermVector){@@ -585,8 +618,19 @@ public abstract class IndexReader {** @param tvSpec specifies which term vector information should be available for the fields* @return Collection of Strings indicating the names of the fields+ *+ * @deprecated Replaced by {@link #getFieldNames (IndexReader.FieldOption fldOption)}*/public abstract Collection getIndexedFieldNames(Field.TermVector tvSpec);++ /**+ * Get a list of unique field names that exist in this index and have the specified+ * field option information.+ * @param fldOption specifies which field option should be available for the returned fields+ * @return Collection of Strings indicating the names of the fields.+ * @see IndexReader.FieldOption+ */+ public abstract Collection getFieldNames(FieldOption fldOption);/*** Returns <code>true</code> iff the index in the named directory isdiff --git a/src/java/org/apache/lucene/index/MultiReader.java b/src/java/org/apache/lucene/index/MultiReader.javaindex 56a35ae87f4..1fd3abfdbec 100644--- a/src/java/org/apache/lucene/index/MultiReader.java+++ b/src/java/org/apache/lucene/index/MultiReader.java@@ -246,6 +246,19 @@ public class MultiReader extends IndexReader {return fieldSet;}+ /**+ * @see IndexReader#getFieldNames(IndexReader.FieldNames fldOption)+ */+ public Collection getFieldNames (IndexReader.FieldOption fieldNames) {+ // maintain a unique set of field names+ Set fieldSet = new HashSet();+ for (int i = 0; i < subReaders.length; i++) {+ IndexReader reader = subReaders[i];+ Collection names = reader.getFieldNames(fieldNames);+ fieldSet.addAll(names);+ }+ return fieldSet;+ }}class MultiTermEnum extends TermEnum {diff --git a/src/java/org/apache/lucene/index/SegmentReader.java b/src/java/org/apache/lucene/index/SegmentReader.javaindex 73373f02194..e6e9ef55d8b 100644--- a/src/java/org/apache/lucene/index/SegmentReader.java+++ b/src/java/org/apache/lucene/index/SegmentReader.java@@ -320,6 +320,7 @@ class SegmentReader extends IndexReader {/*** @see IndexReader#getFieldNames()+ * @deprecated Replaced by {@link #getFieldNames (IndexReader.FieldOption fldOption)}*/public Collection getFieldNames() {// maintain a unique set of field names@@ -333,6 +334,7 @@ class SegmentReader extends IndexReader {/*** @see IndexReader#getFieldNames(boolean)+ * @deprecated Replaced by {@link #getFieldNames (IndexReader.FieldOption fldOption)}*/public Collection getFieldNames(boolean indexed) {// maintain a unique set of field names@@ -345,6 +347,10 @@ class SegmentReader extends IndexReader {return fieldSet;}+ /**+ * @see IndexReader#getIndexedFieldNames(Field.TermVector tvSpec)+ * @deprecated Replaced by {@link #getFieldNames (IndexReader.FieldOption fldOption)}+ */public Collection getIndexedFieldNames (Field.TermVector tvSpec){boolean storedTermVector;boolean storePositionWithTermVector;@@ -392,6 +398,49 @@ class SegmentReader extends IndexReader {return fieldSet;}+ /**+ * @see IndexReader#getFieldNames(IndexReader.FieldOption fldOption)+ */+ public Collection getFieldNames(IndexReader.FieldOption fieldOption) {++ Set fieldSet = new HashSet();+ for (int i = 0; i < fieldInfos.size(); i++) {+ FieldInfo fi = fieldInfos.fieldInfo(i);+ if (fieldOption == IndexReader.FieldOption.ALL) {+ fieldSet.add(fi.name);+ }+ else if (!fi.isIndexed && fieldOption == IndexReader.FieldOption.UNINDEXED) {+ fieldSet.add(fi.name);+ }+ else if (fi.isIndexed && fieldOption == IndexReader.FieldOption.INDEXED) {+ fieldSet.add(fi.name);+ }+ else if (fi.isIndexed && fi.storeTermVector == false && fieldOption == IndexReader.FieldOption.INDEXED_NO_TERMVECTOR) {+ fieldSet.add(fi.name);+ }+ else if (fi.storeTermVector == true &&+ fi.storePositionWithTermVector == false &&+ fi.storeOffsetWithTermVector == false &&+ fieldOption == IndexReader.FieldOption.TERMVECTOR) {+ fieldSet.add(fi.name);+ }+ else if (fi.isIndexed && fi.storeTermVector && fieldOption == IndexReader.FieldOption.INDEXED_WITH_TERMVECTOR) {+ fieldSet.add(fi.name);+ }+ else if (fi.storePositionWithTermVector && fi.storeOffsetWithTermVector == false && fieldOption == IndexReader.FieldOption.TERMVECTOR_WITH_POSITION) {+ fieldSet.add(fi.name);+ }+ else if (fi.storeOffsetWithTermVector && fi.storePositionWithTermVector == false && fieldOption == IndexReader.FieldOption.TERMVECTOR_WITH_OFFSET) {+ fieldSet.add(fi.name);+ }+ else if ((fi.storeOffsetWithTermVector && fi.storePositionWithTermVector) &&+ fieldOption == IndexReader.FieldOption.TERMVECTOR_WITH_POSITION_OFFSET) {+ fieldSet.add(fi.name);+ }+ }+ return fieldSet;+ }+public synchronized byte[] norms(String field) throws IOException {Norm norm = (Norm) norms.get(field);if (norm == null) // not an indexed field