bmesser     2004/12/29 13:35:45

  Modified:    src/java/org/apache/lucene/index MultiReader.java
                        FilterIndexReader.java IndexReader.java
                        SegmentReader.java
  Log:
  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
  
  Revision  Changes    Path
  1.11      +14 -1     
jakarta-lucene/src/java/org/apache/lucene/index/MultiReader.java
  
  Index: MultiReader.java
  ===================================================================
  RCS file: 
/home/cvs/jakarta-lucene/src/java/org/apache/lucene/index/MultiReader.java,v
  retrieving revision 1.10
  retrieving revision 1.11
  diff -u -r1.10 -r1.11
  --- MultiReader.java  6 Oct 2004 09:05:56 -0000       1.10
  +++ MultiReader.java  29 Dec 2004 21:35:45 -0000      1.11
  @@ -246,6 +246,19 @@
       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 {
  
  
  
  1.15      +4 -0      
jakarta-lucene/src/java/org/apache/lucene/index/FilterIndexReader.java
  
  Index: FilterIndexReader.java
  ===================================================================
  RCS file: 
/home/cvs/jakarta-lucene/src/java/org/apache/lucene/index/FilterIndexReader.java,v
  retrieving revision 1.14
  retrieving revision 1.15
  diff -u -r1.14 -r1.15
  --- FilterIndexReader.java    6 Oct 2004 09:05:56 -0000       1.14
  +++ FilterIndexReader.java    29 Dec 2004 21:35:45 -0000      1.15
  @@ -141,4 +141,8 @@
     public Collection getIndexedFieldNames (Field.TermVector tvSpec){
       return in.getIndexedFieldNames(tvSpec);
     }
  +  
  +  public Collection getFieldNames(IndexReader.FieldOption fieldNames) {
  +    return in.getFieldNames(fieldNames);
  +  }
   }
  
  
  
  1.42      +51 -7     
jakarta-lucene/src/java/org/apache/lucene/index/IndexReader.java
  
  Index: IndexReader.java
  ===================================================================
  RCS file: 
/home/cvs/jakarta-lucene/src/java/org/apache/lucene/index/IndexReader.java,v
  retrieving revision 1.41
  retrieving revision 1.42
  diff -u -r1.41 -r1.42
  --- IndexReader.java  10 Oct 2004 18:37:47 -0000      1.41
  +++ IndexReader.java  29 Dec 2004 21:35:45 -0000      1.42
  @@ -47,6 +47,35 @@
   */
   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 @@
               infos.read(directory);
               if (infos.size() == 1) {           // index is optimized
                 return 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 @@
      * 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 [EMAIL PROTECTED] #getFieldNames 
(IndexReader.FieldOption fldOption)}
      */
     public abstract Collection getFieldNames() throws IOException;
   
  @@ -555,6 +586,8 @@
      *                <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 [EMAIL PROTECTED] #getFieldNames 
(IndexReader.FieldOption fldOption)}
      */
     public abstract Collection getFieldNames(boolean indexed) throws 
IOException;
   
  @@ -564,7 +597,7 @@
      *                        else only indexed fields without term vector 
info 
      * @return Collection of Strings indicating the names of the fields
      * 
  -   * @deprecated  Replaced by [EMAIL PROTECTED] #getIndexedFieldNames 
(Field.TermVector tvSpec)}
  +   * @deprecated  Replaced by [EMAIL PROTECTED] #getFieldNames 
(IndexReader.FieldOption fldOption)}
      */ 
     public Collection getIndexedFieldNames(boolean storedTermVector){
       if(storedTermVector){
  @@ -585,8 +618,19 @@
      * 
      * @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 [EMAIL PROTECTED] #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 is
  
  
  
  1.36      +50 -1     
jakarta-lucene/src/java/org/apache/lucene/index/SegmentReader.java
  
  Index: SegmentReader.java
  ===================================================================
  RCS file: 
/home/cvs/jakarta-lucene/src/java/org/apache/lucene/index/SegmentReader.java,v
  retrieving revision 1.35
  retrieving revision 1.36
  diff -u -r1.35 -r1.36
  --- SegmentReader.java        21 Nov 2004 22:32:49 -0000      1.35
  +++ SegmentReader.java        29 Dec 2004 21:35:45 -0000      1.36
  @@ -320,6 +320,7 @@
   
     /**
      * @see IndexReader#getFieldNames()
  +   * @deprecated  Replaced by [EMAIL PROTECTED] #getFieldNames 
(IndexReader.FieldOption fldOption)}
      */
     public Collection getFieldNames() {
       // maintain a unique set of field names
  @@ -333,6 +334,7 @@
   
     /**
      * @see IndexReader#getFieldNames(boolean)
  +   * @deprecated  Replaced by [EMAIL PROTECTED] #getFieldNames 
(IndexReader.FieldOption fldOption)}
      */
     public Collection getFieldNames(boolean indexed) {
       // maintain a unique set of field names
  @@ -345,6 +347,10 @@
       return fieldSet;
     }
     
  +  /**
  +   * @see IndexReader#getIndexedFieldNames(Field.TermVector tvSpec)
  +   * @deprecated  Replaced by [EMAIL PROTECTED] #getFieldNames 
(IndexReader.FieldOption fldOption)}
  +   */
     public Collection getIndexedFieldNames (Field.TermVector tvSpec){
       boolean storedTermVector;
       boolean storePositionWithTermVector;
  @@ -392,6 +398,49 @@
       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
  
  
  

---------------------------------------------------------------------
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]

Reply via email to