You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@lucene.apache.org by Julien Nioche <Ju...@lingway.com> on 2003/04/23 21:04:28 UTC
[PATCH] getFieldNames(boolean indexed)
Hello,
[Seems like my first message on sunday did not arrive on the list - I send
it again >> sorry if you receive it twice]
The current getFieldNames() in IndexReader returns indexed and non-indexed
field names.
The patch I'm proposing enables to specify whether we want to get indexed or
non-indexed field names, depending on the value of the boolean parameter.
For example, IndexReaderInstance.getFieldNames(true) will return a list of
all the indexed fields.
A diff file is attached. The classes modified are :
java/org/apache/lucene/index/IndexReader -
java/org/apache/lucene/index/SegmentReader -
java/org/apache/lucene/index/SegmentsReader
Any suggestions or comments are welcome.
----------------
Index: IndexReader.java
===================================================================
RCS file:
/home/cvspublic/jakarta-lucene/src/java/org/apache/lucene/index/IndexReader.
java,v
retrieving revision 1.14
diff -u -r1.14 IndexReader.java
--- IndexReader.java 20 Mar 2003 18:28:13 -0000 1.14
+++ IndexReader.java 19 Apr 2003 15:33:18 -0000
@@ -312,6 +312,16 @@
*/
public abstract Collection getFieldNames() throws IOException;
+ /**
+ * Return a list of all unique field names which exist in the index
pointed to by
+ * this IndexReader. The boolean argument specifies whether the fields
returned are indexed or not.
+ * @return Collection of Strings indicating the names of the fields
+ * @throws IOException if there is a problem with accessing the index
+ */
+ public abstract Collection getFieldNames(boolean indexed) throws
IOException;
+
+
+
/**
* Returns <code>true</code> iff the index in the named directory is
* currently locked.
Index: SegmentReader.java
===================================================================
RCS file:
/home/cvspublic/jakarta-lucene/src/java/org/apache/lucene/index/SegmentReade
r.java,v
retrieving revision 1.7
diff -u -r1.7 SegmentReader.java
--- SegmentReader.java 4 Jan 2003 17:13:39 -0000 1.7
+++ SegmentReader.java 19 Apr 2003 15:34:05 -0000
@@ -284,4 +284,17 @@
}
return fieldSet;
}
+
+ // javadoc inherited
+ public Collection getFieldNames(boolean indexed) throws IOException {
+ // maintain a unique set of field names
+ Set fieldSet = new HashSet();
+ for (int i = 0; i < fieldInfos.size(); i++) {
+ FieldInfo fi = fieldInfos.fieldInfo(i);
+ if (fi.isIndexed==indexed)
+ fieldSet.add(fi.name);
+ }
+ return fieldSet;
+ }
+
}
Index: SegmentsReader.java
===================================================================
RCS file:
/home/cvspublic/jakarta-lucene/src/java/org/apache/lucene/index/SegmentsRead
er.java,v
retrieving revision 1.10
diff -u -r1.10 SegmentsReader.java
--- SegmentsReader.java 4 Jan 2003 17:13:39 -0000 1.10
+++ SegmentsReader.java 19 Apr 2003 15:34:33 -0000
@@ -194,6 +194,19 @@
}
return fieldSet;
}
+
+ // javadoc inherited
+ public Collection getFieldNames(boolean indexed) throws IOException {
+ // maintain a unique set of field names
+ Set fieldSet = new HashSet();
+ for (int i = 0; i < readers.length; i++) {
+ SegmentReader reader = readers[i];
+ Collection names = reader.getFieldNames(indexed);
+ fieldSet.addAll(names);
+ }
+ return fieldSet;
+ }
+
}
class SegmentsTermEnum extends TermEnum {
Re: [PATCH] getFieldNames(boolean indexed)
Posted by Otis Gospodnetic <ot...@yahoo.com>.
Julien, I finally had the chance to look at this while riding the
subway today.
Looks good and simple.
I will apply your patches as soon as I have a moment to write a unit
test for this (if you already have this, please email).
If anyone thinks this patch should not be applied, speak up.
Thanks Julien.
Otis
--- Julien Nioche <Ju...@lingway.com> wrote:
> Hello,
>
> [Seems like my first message on sunday did not arrive on the list - I
> send
> it again >> sorry if you receive it twice]
>
> The current getFieldNames() in IndexReader returns indexed and
> non-indexed
> field names.
> The patch I'm proposing enables to specify whether we want to get
> indexed or
> non-indexed field names, depending on the value of the boolean
> parameter.
> For example, IndexReaderInstance.getFieldNames(true) will return a
> list of
> all the indexed fields.
>
> A diff file is attached. The classes modified are :
> java/org/apache/lucene/index/IndexReader -
> java/org/apache/lucene/index/SegmentReader -
> java/org/apache/lucene/index/SegmentsReader
>
> Any suggestions or comments are welcome.
>
> ----------------
>
> Index: IndexReader.java
> ===================================================================
> RCS file:
>
/home/cvspublic/jakarta-lucene/src/java/org/apache/lucene/index/IndexReader.
> java,v
> retrieving revision 1.14
> diff -u -r1.14 IndexReader.java
> --- IndexReader.java 20 Mar 2003 18:28:13 -0000 1.14
> +++ IndexReader.java 19 Apr 2003 15:33:18 -0000
> @@ -312,6 +312,16 @@
> */
> public abstract Collection getFieldNames() throws IOException;
>
> + /**
> + * Return a list of all unique field names which exist in the
> index
> pointed to by
> + * this IndexReader. The boolean argument specifies whether the
> fields
> returned are indexed or not.
> + * @return Collection of Strings indicating the names of the
> fields
> + * @throws IOException if there is a problem with accessing the
> index
> + */
> + public abstract Collection getFieldNames(boolean indexed)
> throws
> IOException;
> +
> +
> +
> /**
> * Returns <code>true</code> iff the index in the named directory
> is
> * currently locked.
>
>
>
>
>
>
> Index: SegmentReader.java
> ===================================================================
> RCS file:
>
/home/cvspublic/jakarta-lucene/src/java/org/apache/lucene/index/SegmentReade
> r.java,v
> retrieving revision 1.7
> diff -u -r1.7 SegmentReader.java
> --- SegmentReader.java 4 Jan 2003 17:13:39 -0000 1.7
> +++ SegmentReader.java 19 Apr 2003 15:34:05 -0000
> @@ -284,4 +284,17 @@
> }
> return fieldSet;
> }
> +
> + // javadoc inherited
> + public Collection getFieldNames(boolean indexed) throws
> IOException {
> + // maintain a unique set of field names
> + Set fieldSet = new HashSet();
> + for (int i = 0; i < fieldInfos.size(); i++) {
> + FieldInfo fi = fieldInfos.fieldInfo(i);
> + if (fi.isIndexed==indexed)
> + fieldSet.add(fi.name);
> + }
> + return fieldSet;
> + }
> +
> }
>
>
>
>
>
>
>
> Index: SegmentsReader.java
> ===================================================================
> RCS file:
>
/home/cvspublic/jakarta-lucene/src/java/org/apache/lucene/index/SegmentsRead
> er.java,v
> retrieving revision 1.10
> diff -u -r1.10 SegmentsReader.java
> --- SegmentsReader.java 4 Jan 2003 17:13:39 -0000 1.10
> +++ SegmentsReader.java 19 Apr 2003 15:34:33 -0000
> @@ -194,6 +194,19 @@
> }
> return fieldSet;
> }
> +
> + // javadoc inherited
> + public Collection getFieldNames(boolean indexed) throws
> IOException {
> + // maintain a unique set of field names
> + Set fieldSet = new HashSet();
> + for (int i = 0; i < readers.length; i++) {
> + SegmentReader reader = readers[i];
> + Collection names = reader.getFieldNames(indexed);
> + fieldSet.addAll(names);
> + }
> + return fieldSet;
> + }
> +
> }
>
> class SegmentsTermEnum extends TermEnum {
>
>
> > Index: IndexReader.java
> ===================================================================
> RCS file:
>
/home/cvspublic/jakarta-lucene/src/java/org/apache/lucene/index/IndexReader.java,v
> retrieving revision 1.14
> diff -u -r1.14 IndexReader.java
> --- IndexReader.java 20 Mar 2003 18:28:13 -0000 1.14
> +++ IndexReader.java 19 Apr 2003 15:33:18 -0000
> @@ -312,6 +312,16 @@
> */
> public abstract Collection getFieldNames() throws IOException;
>
> + /**
> + * Return a list of all unique field names which exist in the
> index pointed to by
> + * this IndexReader. The boolean argument specifies whether the
> fields returned are indexed or not.
> + * @return Collection of Strings indicating the names of the
> fields
> + * @throws IOException if there is a problem with accessing the
> index
> + */
> + public abstract Collection getFieldNames(boolean indexed)
> throws IOException;
> +
> +
> +
> /**
> * Returns <code>true</code> iff the index in the named directory
> is
> * currently locked.
>
>
>
>
>
>
> Index: SegmentReader.java
> ===================================================================
> RCS file:
>
/home/cvspublic/jakarta-lucene/src/java/org/apache/lucene/index/SegmentReader.java,v
> retrieving revision 1.7
> diff -u -r1.7 SegmentReader.java
> --- SegmentReader.java 4 Jan 2003 17:13:39 -0000 1.7
> +++ SegmentReader.java 19 Apr 2003 15:34:05 -0000
> @@ -284,4 +284,17 @@
> }
> return fieldSet;
> }
> +
> + // javadoc inherited
> + public Collection getFieldNames(boolean indexed) throws
> IOException {
> + // maintain a unique set of field names
> + Set fieldSet = new HashSet();
> + for (int i = 0; i < fieldInfos.size(); i++) {
> + FieldInfo fi = fieldInfos.fieldInfo(i);
> + if (fi.isIndexed==indexed)
> + fieldSet.add(fi.name);
> + }
> + return fieldSet;
> + }
> +
> }
>
>
>
>
>
>
>
> Index: SegmentsReader.java
> ===================================================================
> RCS file:
>
/home/cvspublic/jakarta-lucene/src/java/org/apache/lucene/index/SegmentsReader.java,v
> retrieving revision 1.10
> diff -u -r1.10 SegmentsReader.java
> --- SegmentsReader.java 4 Jan 2003 17:13:39 -0000 1.10
> +++ SegmentsReader.java 19 Apr 2003 15:34:33 -0000
> @@ -194,6 +194,19 @@
> }
> return fieldSet;
> }
> +
> + // javadoc inherited
> + public Collection getFieldNames(boolean indexed) throws
> IOException {
> + // maintain a unique set of field names
> + Set fieldSet = new HashSet();
> + for (int i = 0; i < readers.length; i++) {
> + SegmentReader reader = readers[i];
> + Collection names = reader.getFieldNames(indexed);
> + fieldSet.addAll(names);
> + }
> + return fieldSet;
> + }
> +
> }
>
> class SegmentsTermEnum extends TermEnum {
>
>
> >
---------------------------------------------------------------------
> To unsubscribe, e-mail: lucene-dev-unsubscribe@jakarta.apache.org
> For additional commands, e-mail: lucene-dev-help@jakarta.apache.org
__________________________________
Do you Yahoo!?
The New Yahoo! Search - Faster. Easier. Bingo.
http://search.yahoo.com
---------------------------------------------------------------------
To unsubscribe, e-mail: lucene-dev-unsubscribe@jakarta.apache.org
For additional commands, e-mail: lucene-dev-help@jakarta.apache.org