goller 2004/10/06 02:19:04 Modified: src/java/org/apache/lucene/search BooleanClause.java src/java/org/apache/lucene/document Field.java Added: src/java/org/apache/lucene/util Parameter.java Log: Introduce a serializable Parameter Class. Revision Changes Path 1.11 +8 -45 jakarta-lucene/src/java/org/apache/lucene/search/BooleanClause.java Index: BooleanClause.java =================================================================== RCS file: /home/cvs/jakarta-lucene/src/java/org/apache/lucene/search/BooleanClause.java,v retrieving revision 1.10 retrieving revision 1.11 diff -u -r1.10 -r1.11 --- BooleanClause.java 12 Sep 2004 13:16:02 -0000 1.10 +++ BooleanClause.java 6 Oct 2004 09:19:04 -0000 1.11 @@ -1,7 +1,6 @@ package org.apache.lucene.search; -import java.io.ObjectStreamException; -import java.io.StreamCorruptedException; +import org.apache.lucene.util.Parameter; /** * Copyright 2004 The Apache Software Foundation @@ -22,59 +21,23 @@ /** A clause in a BooleanQuery. */ public class BooleanClause implements java.io.Serializable { - public static final class Occur implements java.io.Serializable { + public static final class Occur extends Parameter implements java.io.Serializable { - private int id; - private String name; - private static final int MUST_ID = 0; - private static final int MUST_NOT_ID = 1; - private static final int SHOULD_ID = 2; - - private Occur() { + private Occur(String name) { // typesafe enum pattern, no public constructor + super(name); } - - private Occur(int id, String name) { - // typesafe enum pattern, no public constructor - this.id = id; - this.name = name; - } - - public String toString() { - return name; - } - + /** Use this operator for terms that <i>must</i> appear in the matching documents. */ - public static final Occur MUST = new Occur(MUST_ID, "MUST"); + public static final Occur MUST = new Occur("MUST"); /** Use this operator for terms of which <i>should</i> appear in the * matching documents. For a BooleanQuery with two <code>SHOULD</code> * subqueries, at least one of the queries must appear in the matching documents. */ - public static final Occur SHOULD = new Occur(SHOULD_ID, "SHOULD"); + public static final Occur SHOULD = new Occur("SHOULD"); /** Use this operator for terms that <i>must not</i> appear in the matching documents. * Note that it is not possible to search for queries that only consist * of a <code>MUST_NOT</code> query. */ - public static final Occur MUST_NOT = new Occur(MUST_NOT_ID, "MUST_NOT"); - - /** - * Resolves the deserialized instance to the local reference for accurate - * equals() and == comparisons. - * - * @return a reference to Occur as resolved in the local VM - * @throws ObjectStreamException - */ - private Object readResolve() throws ObjectStreamException { - int id = ((Occur) this).id; - switch (id) { - case MUST_ID : - return Occur.MUST; - case MUST_NOT_ID : - return Occur.MUST_NOT; - case SHOULD_ID: - return Occur.SHOULD; - default : - throw new StreamCorruptedException("Unknown id " + id); - } - } + public static final Occur MUST_NOT = new Occur("MUST_NOT"); } 1.26 +15 -23 jakarta-lucene/src/java/org/apache/lucene/document/Field.java Index: Field.java =================================================================== RCS file: /home/cvs/jakarta-lucene/src/java/org/apache/lucene/document/Field.java,v retrieving revision 1.25 retrieving revision 1.26 diff -u -r1.25 -r1.26 --- Field.java 5 Oct 2004 17:30:48 -0000 1.25 +++ Field.java 6 Oct 2004 09:19:04 -0000 1.26 @@ -17,11 +17,13 @@ */ import java.io.Reader; +import java.io.Serializable; import java.util.Date; import org.apache.lucene.index.IndexReader; import org.apache.lucene.search.Hits; import org.apache.lucene.search.Similarity; +import org.apache.lucene.util.Parameter; /** A field is a section of a Document. Each field has two parts, a name and a @@ -31,7 +33,7 @@ index, so that they may be returned with hits on the document. */ -public final class Field implements java.io.Serializable { +public final class Field implements Serializable { private String name = "body"; // the one and only data object for all different kind of field values @@ -48,14 +50,10 @@ private float boost = 1.0f; - public static final class Store { - private String name; - private Store() {} + public static final class Store extends Parameter implements Serializable { + private Store(String name) { - this.name = name; - } - public String toString() { - return name; + super(name); } /** Store the original field value in the index in a compressed form. This is @@ -74,24 +72,23 @@ public static final Store NO = new Store("NO"); } - public static final class Index { - private String name; - private Index() {} + public static final class Index extends Parameter implements Serializable { + private Index(String name) { - this.name = name; - } - public String toString() { - return name; + super(name); } + /** Do not index the field value. This field can thus not be searched, * but one can still access its contents provided it is * [EMAIL PROTECTED] Field.Store stored}. */ public static final Index NO = new Index("NO"); + /** Index the field's value so it can be searched. An Analyzer will be used * to tokenize and possibly further normalize the text before its * terms will be stored in the index. This is useful for common text. */ public static final Index TOKENIZED = new Index("TOKENIZED"); + /** Index the field's value without using an Analyzer, so it can be searched. * As no analyzer is used the value will be stored as a single term. This is * useful for unique Ids like product numbers. @@ -99,15 +96,10 @@ public static final Index UN_TOKENIZED = new Index("UN_TOKENIZED"); } - public static final class TermVector { - private String name; - private TermVector() {} + public static final class TermVector extends Parameter implements Serializable { + private TermVector(String name) { - this.name = name; - } - - public String toString() { - return name; + super(name); } /** Do not store term vectors. 1.1 jakarta-lucene/src/java/org/apache/lucene/util/Parameter.java Index: Parameter.java =================================================================== package org.apache.lucene.util; /** * Copyright 2004 The Apache Software Foundation * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */ import java.io.ObjectStreamException; import java.io.Serializable; import java.io.StreamCorruptedException; import java.util.HashMap; import java.util.Map; /** * A serializable Enum class. */ public abstract class Parameter implements Serializable { static Map allParameters = new HashMap(); private String name; private Parameter() { // typesafe enum pattern, no public constructor } protected Parameter(String name) { // typesafe enum pattern, no public constructor this.name = name; String key = makeKey(name); if(allParameters.containsKey(key)) throw new IllegalArgumentException("Parameter name " + key + " already used!"); allParameters.put(key, this); } private String makeKey(String name){ return getClass() + " " + name; } public String toString() { return name; } /** * Resolves the deserialized instance to the local reference for accurate * equals() and == comparisons. * * @return a reference to Parameter as resolved in the local VM * @throws ObjectStreamException */ private Object readResolve() throws ObjectStreamException { Object par = allParameters.get(makeKey(name)); if(par == null) throw new StreamCorruptedException("Unknown parameter value: " + name); return par; } }
--------------------------------------------------------------------- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]