1 package org.enhydra.snapper.wrapper.lucene; 2 3 6 7 import java.util.Enumeration ; 8 import java.util.Iterator ; 9 import java.util.List ; 10 import java.util.ArrayList ; 11 import java.util.Vector ; 12 13 14 27 28 public final class Document implements java.io.Serializable { 29 List fields = new Vector (); 30 private float boost = 1.0f; 31 32 33 public Document() {} 34 35 36 45 public void setBoost(float boost) { 46 this.boost = boost; 47 } 48 49 60 public float getBoost() { 61 return boost; 62 } 63 64 74 public final void add(Field field) { 75 fields.add(field); 76 } 77 78 88 public final void removeField(String name) { 89 Iterator it = fields.iterator(); 90 while (it.hasNext()) { 91 Field field = (Field)it.next(); 92 if (field.name().equals(name)) { 93 it.remove(); 94 return; 95 } 96 } 97 } 98 99 108 public final void removeFields(String name) { 109 Iterator it = fields.iterator(); 110 while (it.hasNext()) { 111 Field field = (Field)it.next(); 112 if (field.name().equals(name)) { 113 it.remove(); 114 } 115 } 116 } 117 118 122 public final Field getField(String name) { 123 for (int i = 0; i < fields.size(); i++) { 124 Field field = (Field)fields.get(i); 125 if (field.name().equals(name)) 126 return field; 127 } 128 return null; 129 } 130 131 135 public final String get(String name) { 136 Field field = getField(name); 137 if (field != null) 138 return field.stringValue(); 139 else 140 return null; 141 } 142 143 144 public final Enumeration fields() { 145 return ((Vector )fields).elements(); 146 } 147 148 155 public final Field[] getFields(String name) { 156 List result = new ArrayList (); 157 for (int i = 0; i < fields.size(); i++) { 158 Field field = (Field)fields.get(i); 159 if (field.name().equals(name)) { 160 result.add(field); 161 } 162 } 163 164 if (result.size() == 0) 165 return null; 166 167 return (Field[])result.toArray(new Field[result.size()]); 168 } 169 170 177 public final String [] getValues(String name) { 178 Field[] namedFields = getFields(name); 179 if (namedFields == null) 180 return null; 181 String [] values = new String [namedFields.length]; 182 for (int i = 0; i < namedFields.length; i++) { 183 values[i] = namedFields[i].stringValue(); 184 } 185 return values; 186 } 187 188 189 public final String toString() { 190 StringBuffer buffer = new StringBuffer (); 191 buffer.append("Document<"); 192 for (int i = 0; i < fields.size(); i++) { 193 Field field = (Field)fields.get(i); 194 buffer.append(field.toString()); 195 if (i != fields.size()-1) 196 buffer.append(" "); 197 } 198 buffer.append(">"); 199 return buffer.toString(); 200 } 201 } 202 203 | Popular Tags |