Permalink
Browse files

add termvector to the possible options for Field.

  • Loading branch information...
1 parent 8fb2c1c commit b00fb7f70ec3b6799f4d904e28d9449f9936ea0b Santiago M. Mola committed with Robert Newson May 5, 2010
View
@@ -143,6 +143,12 @@ The following indexing options can be defaulted;
<td>analyzed</td>
</tr>
<tr>
+ <th>termvector</th>
+ <td>whether and how a field should have term vectors</td>
+ <td>no, with_offsets, with_positions, with_positions_offsets, yes</td>
+ <td>no</td>
+ </tr>
+ <tr>
<th>boost</th>
<td>Sets the boost factor hits on this field. This value will be multiplied into the score of all hits on this this field of this document.</td>
<td>floating-point value</td>
@@ -139,7 +139,7 @@ private static NumericField field(final String name, final int precisionStep, fi
}
private static Field field(final String name, final Object value, final ViewSettings settings) {
- return boost(new Field(name, value.toString(), settings.getStore(), settings.getIndex()), settings);
+ return boost(new Field(name, value.toString(), settings.getStore(), settings.getIndex(), settings.getTermVector()), settings);
}
private static <T extends AbstractField> T boost(final T field, final ViewSettings settings) {
@@ -4,6 +4,7 @@
import org.apache.lucene.document.Field.Index;
import org.apache.lucene.document.Field.Store;
+import org.apache.lucene.document.Field.TermVector;
import org.mozilla.javascript.NativeObject;
import com.github.rnewson.couchdb.lucene.util.Constants;
@@ -27,37 +28,39 @@
public final class ViewSettings {
public static ViewSettings getDefaultSettings() {
- return new ViewSettings(Constants.DEFAULT_FIELD, "analyzed", "no", "string", "1.0", null);
+ return new ViewSettings(Constants.DEFAULT_FIELD, "analyzed", "no", "string", "1.0", "no", null);
}
private final Index index;
private final Store store;
private final String field;
private final FieldType type;
private final float boost;
+ private final TermVector termvector;
public ViewSettings(final JSONObject json) {
this(json, getDefaultSettings());
}
public ViewSettings(final JSONObject json, final ViewSettings defaults) {
- this(json.optString("field", null), json.optString("index", null), json.optString("store", null), json.optString("type", null), json.optString("boost", null), defaults);
+ this(json.optString("field", null), json.optString("index", null), json.optString("store", null), json.optString("type", null), json.optString("boost", null), json.optString("termvector", null), defaults);
}
public ViewSettings(final NativeObject obj) {
this(obj, getDefaultSettings());
}
public ViewSettings(final NativeObject obj, final ViewSettings defaults) {
- this(get(obj, "field"), get(obj, "index"), get(obj, "store"), get(obj, "type"), get(obj, "boost"), defaults);
+ this(get(obj, "field"), get(obj, "index"), get(obj, "store"), get(obj, "type"), get(obj, "boost"), get(obj, "termvector"), defaults);
}
- private ViewSettings(final String field, final String index, final String store, final String type, final String boost, final ViewSettings defaults) {
+ private ViewSettings(final String field, final String index, final String store, final String type, final String boost, final String termvector, final ViewSettings defaults) {
this.field = field != null ? field : defaults.getField();
this.index = index != null ? Index.valueOf(index.toUpperCase()) : defaults.getIndex();
this.store = store != null ? Store.valueOf(store.toUpperCase()) : defaults.getStore();
this.type = type != null ? FieldType.valueOf(type.toUpperCase()) : defaults.getFieldType();
this.boost = boost != null ? Float.valueOf(boost) : defaults.getBoost();
+ this.termvector = termvector != null? TermVector.valueOf(termvector.toUpperCase()) : defaults.getTermVector();
}
public float getBoost() {
@@ -80,6 +83,11 @@ public FieldType getFieldType() {
return type;
}
+ public TermVector getTermVector()
+ {
+ return termvector;
+ }
+
private static String get(final NativeObject obj, final String key) {
return obj == null ? null : obj.has(key, null) ? obj.get(key, null).toString() : null;
}

0 comments on commit b00fb7f

Please sign in to comment.