Skip to content
This repository has been archived by the owner on May 4, 2023. It is now read-only.

Commit

Permalink
add termvector to the possible options for Field.
Browse files Browse the repository at this point in the history
  • Loading branch information
smola authored and Robert Newson committed May 5, 2010
1 parent 8fb2c1c commit b00fb7f
Show file tree
Hide file tree
Showing 3 changed files with 19 additions and 5 deletions.
6 changes: 6 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -142,6 +142,12 @@ The following indexing options can be defaulted;
<td>analyzed, analyzed_no_norms, no, not_analyzed, not_analyzed_no_norms</td>
<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>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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() {
Expand All @@ -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;
}
Expand Down

0 comments on commit b00fb7f

Please sign in to comment.