adding a constructor that takes a Reader; some small doc improvements, some whitespace fixes. I will soon deprecate the static methods.

git-svn-id: https://svn.apache.org/repos/asf/lucene/java/trunk@150472 13f79535-47bb-0310-9956-ffa450edef68
This commit is contained in:
Daniel Naber 2004-09-01 20:31:48 +00:00
parent 794ba80e15
commit ac4238947f
1 changed files with 96 additions and 56 deletions

View File

@ -213,12 +213,20 @@ public final class Field implements java.io.Serializable {
is used. Exactly one of stringValue() and readerValue() must be set. */
public Reader readerValue() { return readerValue; }
/** Create a field by specifying all parameters except for <code>termVector</code>,
* which is set to <code>TermVector.NO</code>.
/**
* Create a field by specifying its name, value and how it will
* be saved in the index. Term vectors will not be stored in the index.
*
* @param name The name of the field
* @param value The string to process
* @param store Whether <code>value</code> should be stored in the index
* @param index Whether the field should be indexed, and if so, if it should
* be tokenized before indexing
* @throws NullPointerException if name or value is <code>null</code>
* @throws IllegalArgumentException if the field is neither stored nor indexed
*/
public Field(String name, String string, Store store, Index index) {
this(name, string, store, index, TermVector.NO);
public Field(String name, String value, Store store, Index index) {
this(name, value, store, index, TermVector.NO);
}
/**
@ -227,10 +235,11 @@ public final class Field implements java.io.Serializable {
*
* @param name The name of the field
* @param value The string to process
* @param store whether <code>value</code> should be stored in the index
* @param index whether the field should be indexed, and if so, if it should
* @param store Whether <code>value</code> should be stored in the index
* @param index Whether the field should be indexed, and if so, if it should
* be tokenized before indexing
* @param termVector whether Term Vector info should be stored
* @param termVector Whether term vector should be stored
* @throws NullPointerException if name or value is <code>null</code>
* @throws IllegalArgumentException in any of the following situations:
* <ul>
* <li>the field is neither stored nor indexed</li>
@ -251,6 +260,7 @@ public final class Field implements java.io.Serializable {
this.name = name.intern(); // field names are interned
this.stringValue = value;
if (store == Store.YES)
this.isStored = true;
else if (store == Store.NO)
@ -271,17 +281,46 @@ public final class Field implements java.io.Serializable {
throw new IllegalArgumentException("unknown index parameter " + index);
}
if (termVector == TermVector.NO) {
this.storeTermVector = false;
} else if (termVector == TermVector.YES) {
this.storeTermVector = true;
} else {
throw new IllegalArgumentException("unknown termVector parameter " + termVector);
setStoreTermVector(termVector);
}
/**
* Create a tokenized and indexed field that is not stored. Term vectors will
* not be stored.
*
* @param name The name of the field
* @param reader The reader with the content
* @throws NullPointerException if name or reader is <code>null</code>
*/
public Field(String name, Reader reader) {
this(name, reader, TermVector.NO);
}
/**
* Create a tokenized and indexed field that is not stored, optionally with
* storing term vectors.
*
* @param name The name of the field
* @param reader The reader with the content
* @param termVector Whether term vector should be stored
* @throws NullPointerException if name or reader is <code>null</code>
*/
public Field(String name, Reader reader, TermVector termVector) {
if (name == null)
throw new NullPointerException("name cannot be null");
if (reader == null)
throw new NullPointerException("reader cannot be null");
this.name = name.intern(); // field names are interned
this.readerValue = reader;
this.isStored = false;
this.isIndexed = true;
this.isTokenized = true;
setStoreTermVector(termVector);
}
/** Create a field by specifying all parameters except for <code>storeTermVector</code>,
* which is set to <code>false</code>.
*
* @deprecated use {@link #Field(String, String, Field.Store, Field.Index)} instead
*/
public Field(String name, String string,
@ -297,6 +336,7 @@ public final class Field implements java.io.Serializable {
* @param index true if the field should be indexed
* @param token true if the field should be tokenized
* @param storeTermVector true if we should store the Term Vector info
*
* @deprecated use {@link #Field(String, String, Field.Store, Field.Index, Field.TermVector)} instead
*/
public Field(String name, String string,
@ -316,14 +356,14 @@ public final class Field implements java.io.Serializable {
this.storeTermVector = storeTermVector;
}
Field(String name, Reader reader) {
if (name == null)
throw new NullPointerException("name cannot be null");
if (reader == null)
throw new NullPointerException("value cannot be null");
this.name = name.intern(); // field names are interned
this.readerValue = reader;
private void setStoreTermVector(TermVector termVector) {
if (termVector == TermVector.NO) {
this.storeTermVector = false;
} else if (termVector == TermVector.YES) {
this.storeTermVector = true;
} else {
throw new IllegalArgumentException("unknown termVector parameter " + termVector);
}
}
/** True iff the value of the field is to be stored in the index for return