lucene-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From cutt...@apache.org
Subject cvs commit: jakarta-lucene/src/test/org/apache/lucene/document TestDocument.java
Date Mon, 01 Mar 2004 17:32:50 GMT
cutting     2004/03/01 09:32:50

  Modified:    src/java/org/apache/lucene/document Document.java
               src/test/org/apache/lucene/document TestDocument.java
  Log:
  Changed Document so that field order is observed when indexing.
  
  Revision  Changes    Path
  1.14      +22 -45    jakarta-lucene/src/java/org/apache/lucene/document/Document.java
  
  Index: Document.java
  ===================================================================
  RCS file: /home/cvs/jakarta-lucene/src/java/org/apache/lucene/document/Document.java,v
  retrieving revision 1.13
  retrieving revision 1.14
  diff -u -r1.13 -r1.14
  --- Document.java	12 Feb 2004 18:37:41 -0000	1.13
  +++ Document.java	1 Mar 2004 17:32:50 -0000	1.14
  @@ -57,6 +57,7 @@
   import java.util.Enumeration;
   import java.util.List;
   import java.util.ArrayList;
  +import java.util.Vector;
   import org.apache.lucene.index.IndexReader;       // for javadoc
   import org.apache.lucene.search.Hits;             // for javadoc
   
  @@ -69,7 +70,7 @@
    * */
   
   public final class Document implements java.io.Serializable {
  -  DocumentFieldList fieldList = null;
  +  List fields = new Vector();
     private float boost = 1.0f;
   
     /** Constructs a new document with no fields. */
  @@ -108,16 +109,18 @@
      * the same name.  In this case, if the fields are indexed, their text is
      * treated as though appended for the purposes of search. */
     public final void add(Field field) {
  -    fieldList = new DocumentFieldList(field, fieldList);
  +    fields.add(field);
     }
   
     /** Returns a field with the given name if any exist in this document, or
       null.  If multiple fields exists with this name, this method returns the
       last field value added. */
     public final Field getField(String name) {
  -    for (DocumentFieldList list = fieldList; list != null; list = list.next)
  -      if (list.field.name().equals(name))
  -	return list.field;
  +    for (int i = 0; i < fields.size(); i++) {
  +      Field field = (Field)fields.get(i);
  +      if (field.name().equals(name))
  +	return field;
  +    }
       return null;
     }
   
  @@ -134,7 +137,7 @@
   
     /** Returns an Enumeration of all the fields in a document. */
     public final Enumeration fields() {
  -    return new DocumentFieldEnumeration(this);
  +    return ((Vector)fields).elements();
     }
   
     /**
  @@ -145,19 +148,18 @@
      * @return a <code>Field[]</code> array
      */
      public final Field[] getFields(String name) {
  -     List tempFieldList = new ArrayList();
  -     for (DocumentFieldList list = fieldList; list != null; list = list.next) {
  -       if (list.field.name().equals(name)) {
  -         tempFieldList.add(list.field);
  +     List result = new ArrayList();
  +     for (int i = 0; i < fields.size(); i++) {
  +       Field field = (Field)fields.get(i);
  +       if (field.name().equals(name)) {
  +         result.add(field);
          }
        }
  -     int fieldCount = tempFieldList.size();
  -     if (fieldCount == 0) {
  +
  +     if (result.size() == 0)
          return null;
  -     }
  -     else {
  -       return (Field[])tempFieldList.toArray(new Field[] {});
  -     }
  +
  +     return (Field[])result.toArray(new Field[result.size()]);
      }
   
     /**
  @@ -183,38 +185,13 @@
     public final String toString() {
       StringBuffer buffer = new StringBuffer();
       buffer.append("Document<");
  -    for (DocumentFieldList list = fieldList; list != null; list = list.next) {
  -      buffer.append(list.field.toString());
  -      if (list.next != null)
  +    for (int i = 0; i < fields.size(); i++) {
  +      Field field = (Field)fields.get(i);
  +      buffer.append(field.toString());
  +      if (i != fields.size()-1)
           buffer.append(" ");
       }
       buffer.append(">");
       return buffer.toString();
  -  }
  -}
  -
  -final class DocumentFieldList implements java.io.Serializable {
  -  DocumentFieldList(Field f, DocumentFieldList n) {
  -    field = f;
  -    next = n;
  -  }
  -  Field field;
  -  DocumentFieldList next;
  -}
  -
  -final class DocumentFieldEnumeration implements Enumeration {
  -  DocumentFieldList fields;
  -  DocumentFieldEnumeration(Document d) {
  -    fields = d.fieldList;
  -  }
  -
  -  public final boolean hasMoreElements() {
  -    return fields == null ? false : true;
  -  }
  -
  -  public final Object nextElement() {
  -    Field result = fields.field;
  -    fields = fields.next;
  -    return result;
     }
   }
  
  
  
  1.2       +9 -9      jakarta-lucene/src/test/org/apache/lucene/document/TestDocument.java
  
  Index: TestDocument.java
  ===================================================================
  RCS file: /home/cvs/jakarta-lucene/src/test/org/apache/lucene/document/TestDocument.java,v
  retrieving revision 1.1
  retrieving revision 1.2
  diff -u -r1.1 -r1.2
  --- TestDocument.java	7 Jan 2003 02:30:52 -0000	1.1
  +++ TestDocument.java	1 Mar 2004 17:32:50 -0000	1.2
  @@ -157,18 +157,18 @@
               assertTrue(unstoredFieldValues.length  == 2);
           }
   
  -        assertTrue(keywordFieldValues[0].equals("test2"));
  -        assertTrue(keywordFieldValues[1].equals("test1"));
  -        assertTrue(textFieldValues[0].equals("test2"));
  -        assertTrue(textFieldValues[1].equals("test1"));
  -        assertTrue(unindexedFieldValues[0].equals("test2"));
  -        assertTrue(unindexedFieldValues[1].equals("test1"));
  +        assertTrue(keywordFieldValues[0].equals("test1"));
  +        assertTrue(keywordFieldValues[1].equals("test2"));
  +        assertTrue(textFieldValues[0].equals("test1"));
  +        assertTrue(textFieldValues[1].equals("test2"));
  +        assertTrue(unindexedFieldValues[0].equals("test1"));
  +        assertTrue(unindexedFieldValues[1].equals("test2"));
           // this test cannot work for documents retrieved from the index
           // since unstored fields will obviously not be returned
           if (! fromIndex)
           {
  -            assertTrue(unstoredFieldValues[0].equals("test2"));
  -            assertTrue(unstoredFieldValues[1].equals("test1"));
  +            assertTrue(unstoredFieldValues[0].equals("test1"));
  +            assertTrue(unstoredFieldValues[1].equals("test2"));
           }
       }
   }
  
  
  

---------------------------------------------------------------------
To unsubscribe, e-mail: lucene-dev-unsubscribe@jakarta.apache.org
For additional commands, e-mail: lucene-dev-help@jakarta.apache.org


Mime
View raw message