Mailing List Archive

proposed changes to document (doug) vs AbstractDocument (pt 2/3)
Index: IndexWriter.java
===================================================================
RCS file: /home/cvspublic/jakarta-lucene/src/java/org/apache/lucene/index/IndexWriter.java,v
retrieving revision 1.6
diff -u -r1.6 IndexWriter.java
--- IndexWriter.java 8 Feb 2002 19:39:42 -0000 1.6
+++ IndexWriter.java 9 Feb 2002 13:27:36 -0000
@@ -65,7 +65,7 @@
import org.apache.lucene.store.Lock;
import org.apache.lucene.store.InputStream;
import org.apache.lucene.store.OutputStream;
-import org.apache.lucene.document.Document;
+import org.apache.lucene.document.AbstractDocument;
import org.apache.lucene.analysis.Analyzer;

/**
@@ -175,7 +175,7 @@
public int maxFieldLength = 10000;

/** Adds a document to this index.*/
- public final void addDocument(Document doc) throws IOException {
+ public final void addDocument(AbstractDocument doc) throws IOException {
DocumentWriter dw =
new DocumentWriter(ramDirectory, analyzer, maxFieldLength);
String segmentName = newSegmentName();

Index: FieldsWriter.java
===================================================================
RCS file: /home/cvspublic/jakarta-lucene/src/java/org/apache/lucene/index/FieldsWriter.java,v
retrieving revision 1.1
diff -u -r1.1 FieldsWriter.java
--- FieldsWriter.java 18 Sep 2001 16:29:52 -0000 1.1
+++ FieldsWriter.java 9 Feb 2002 13:22:34 -0000
@@ -60,7 +60,7 @@

import org.apache.lucene.store.Directory;
import org.apache.lucene.store.OutputStream;
-import org.apache.lucene.document.Document;
+import org.apache.lucene.document.AbstractDocument;
import org.apache.lucene.document.Field;

final class FieldsWriter {
@@ -80,7 +80,7 @@
indexStream.close();
}

- final void addDocument(Document doc) throws IOException {
+ final void addDocument(AbstractDocument doc) throws IOException {
indexStream.writeLong(fieldsStream.getFilePointer());

int storedCount = 0;

Index: FieldInfos.java
===================================================================
RCS file: /home/cvspublic/jakarta-lucene/src/java/org/apache/lucene/index/FieldInfos.java,v
retrieving revision 1.2
diff -u -r1.2 FieldInfos.java
--- FieldInfos.java 1 Nov 2001 01:13:00 -0000 1.2
+++ FieldInfos.java 9 Feb 2002 13:21:43 -0000
@@ -59,7 +59,7 @@
import java.util.Enumeration;
import java.io.IOException;

-import org.apache.lucene.document.Document;
+import org.apache.lucene.document.AbstractDocument;
import org.apache.lucene.document.Field;

import org.apache.lucene.store.Directory;
@@ -84,7 +84,7 @@
}

/** Adds field info for a Document. */
- final void add(Document doc) {
+ final void add(AbstractDocument doc) {
Enumeration fields = doc.fields();
while (fields.hasMoreElements()) {
Field field = (Field)fields.nextElement();

Index: DocumentWriter.java
===================================================================
RCS file: /home/cvspublic/jakarta-lucene/src/java/org/apache/lucene/index/DocumentWriter.java,v
retrieving revision 1.1
diff -u -r1.1 DocumentWriter.java
--- DocumentWriter.java 18 Sep 2001 16:29:52 -0000 1.1
+++ DocumentWriter.java 9 Feb 2002 13:20:32 -0000
@@ -60,7 +60,7 @@
import java.util.Hashtable;
import java.util.Enumeration;

-import org.apache.lucene.document.Document;
+import org.apache.lucene.document.AbstractDocument;
import org.apache.lucene.document.Field;
import org.apache.lucene.analysis.Analyzer;
import org.apache.lucene.analysis.TokenStream;
@@ -81,7 +81,7 @@
maxFieldLength = mfl;
}

- final void addDocument(String segment, Document doc)
+ final void addDocument(String segment, AbstractDocument doc)
throws IOException {
// write field names
fieldInfos = new FieldInfos();
@@ -132,7 +132,7 @@
private int[] fieldLengths;

// Tokenizes the fields of a document into Postings.
- private final void invertDocument(Document doc)
+ private final void invertDocument(AbstractDocument doc)
throws IOException {
Enumeration fields = doc.fields();
while (fields.hasMoreElements()) {
@@ -304,7 +304,7 @@
}
}

- private final void writeNorms(Document doc, String segment)
+ private final void writeNorms(AbstractDocument doc, String segment)
throws IOException {
Enumeration fields = doc.fields();
while (fields.hasMoreElements()) {

Index: Document.java
===================================================================
RCS file: /home/cvspublic/jakarta-lucene/src/java/org/apache/lucene/document/Document.java,v
retrieving revision 1.1
diff -u -r1.1 Document.java
--- Document.java 18 Sep 2001 16:29:52 -0000 1.1
+++ Document.java 9 Feb 2002 13:16:29 -0000
@@ -56,90 +56,41 @@

import java.util.Enumeration;

-/** Documents are the unit of indexing and search.
- *
- * A Document is a set of fields. Each field has a name and a textual value.
- * A field may be stored with the document, in which case it is returned with
- * search hits on the document. Thus each document should typically contain
- * stored fields which uniquely identify it.
- * */
+/**
+ * Concrete class extending and finalizing the AbstractDocument and its methods.
+ *
+ */

-public final class Document {
+public final class Document extends AbstractDocument{
DocumentFieldList fieldList = null;

/** Constructs a new document with no fields. */
public Document() {}

- /** Adds a field to a document. Several fields may be added with
- * 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);
- }

/** Returns a field with the given name if any exist in this document, or
null. If multiple fields may exist with this name, this method returns the
last added such 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;
- return null;
+ return super.getField(name);
}

/** Returns the string value of the field with the given name if any exist in
this document, or null. If multiple fields may exist with this name, this
method returns the last added such added. */
public final String get(String name) {
- Field field = getField(name);
- if (field != null)
- return field.stringValue();
- else
- return null;
+ return super.get(name);
}

/** Returns an Enumeration of all the fields in a document. */
public final Enumeration fields() {
- return new DocumentFieldEnumeration(this);
+ return super.fields();
}

/** Prints the fields of a document for human consumption. */
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)
- buffer.append(" ");
- }
- buffer.append(">");
- return buffer.toString();
+ return super.toString();
}

}

-final class DocumentFieldList {
- 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;
- }
-}
--
www.superlinksoftware.com
www.sourceforge.net/projects/poi - port of Excel format to java
http://developer.java.sun.com/developer/bugParade/bugs/4487555.html
- fix java generics!


The avalanche has already started. It is too late for the pebbles to
vote.
-Ambassador Kosh


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