1 package org.enhydra.snapper.wrapper.lucene; 2 3 6 7 import java.io.Reader ; 8 import java.util.Date ; 9 10 11 18 19 public final class Field implements java.io.Serializable { 20 private String name = "body"; 21 private String stringValue = null; 22 private boolean storeTermVector = false; 23 private Reader readerValue = null; 24 private boolean isStored = false; 25 private boolean isIndexed = true; 26 private boolean isTokenized = true; 27 28 private float boost = 1.0f; 29 30 46 public void setBoost(float boost) { 47 this.boost = boost; 48 } 49 50 61 public float getBoost() { 62 return boost; 63 } 64 65 68 public static final Field Keyword(String name, String value) { 69 return new Field(name, value, true, true, false); 70 } 71 72 74 public static final Field UnIndexed(String name, String value) { 75 return new Field(name, value, true, false, false); 76 } 77 78 81 public static final Field Text(String name, String value) { 82 return Text(name, value, false); 83 } 84 85 87 public static final Field Keyword(String name, Date value) { 88 return new Field(name, DateField.dateToString(value), true, true, false); 89 } 90 91 94 public static final Field Text(String name, String value, boolean storeTermVector) { 95 return new Field(name, value, true, true, true, storeTermVector); 96 } 97 98 100 public static final Field UnStored(String name, String value) { 101 return UnStored(name, value, false); 102 } 103 104 106 public static final Field UnStored(String name, String value, boolean storeTermVector) { 107 return new Field(name, value, false, true, true, storeTermVector); 108 } 109 110 113 public static final Field Text(String name, Reader value) { 114 return Text(name, value, false); 115 } 116 117 120 public static final Field Text(String name, Reader value, boolean storeTermVector) { 121 Field f = new Field(name, value); 122 f.storeTermVector = storeTermVector; 123 return f; 124 } 125 126 128 public String name() { return name; } 129 130 132 public String stringValue() { return stringValue; } 133 135 public Reader readerValue() { return readerValue; } 136 137 138 141 public Field(String name, String string, 142 boolean store, boolean index, boolean token) { 143 this(name, string, store, index, token, false); 144 } 145 146 155 public Field(String name, String string, 156 boolean store, boolean index, boolean token, boolean storeTermVector) { 157 if (name == null) 158 throw new IllegalArgumentException ("name cannot be null"); 159 if (string == null) 160 throw new IllegalArgumentException ("value cannot be null"); 161 if (!index && storeTermVector) 162 throw new IllegalArgumentException ("cannot store a term vector for fields that are not indexed."); 163 164 this.name = name.intern(); this.stringValue = string; 166 this.isStored = store; 167 this.isIndexed = index; 168 this.isTokenized = token; 169 this.storeTermVector = storeTermVector; 170 } 171 172 Field(String name, Reader reader) { 173 if (name == null) 174 throw new IllegalArgumentException ("name cannot be null"); 175 if (reader == null) 176 throw new IllegalArgumentException ("value cannot be null"); 177 178 this.name = name.intern(); this.readerValue = reader; 180 } 181 182 185 public final boolean isStored() { return isStored; } 186 187 189 public final boolean isIndexed() { return isIndexed; } 190 191 194 public final boolean isTokenized() { return isTokenized; } 195 196 204 public final boolean isTermVectorStored() { return storeTermVector; } 205 206 207 public final String toString() { 208 if (isStored && isIndexed && !isTokenized) 209 return "Keyword<" + name + ":" + stringValue + ">"; 210 else if (isStored && !isIndexed && !isTokenized) 211 return "Unindexed<" + name + ":" + stringValue + ">"; 212 else if (isStored && isIndexed && isTokenized && stringValue!=null) 213 return "Text<" + name + ":" + stringValue + ">"; 214 else if (!isStored && isIndexed && isTokenized && readerValue!=null) 215 return "Text<" + name + ":" + readerValue + ">"; 216 else if (!isStored && isIndexed && isTokenized) 217 { 218 return "UnStored<" + name + ">"; 219 } 220 else 221 { 222 return super.toString(); 223 } 224 } 225 226 } 227 228 | Popular Tags |