Skip to content

Commit

Permalink
Boolean field type does not handle number/string properly when search…
Browse files Browse the repository at this point in the history
…ing, closes #59.
  • Loading branch information
kimchy committed Mar 12, 2010
1 parent 6fe329a commit 47c11aa
Showing 1 changed file with 10 additions and 6 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -22,12 +22,13 @@
import org.apache.lucene.document.Field;
import org.apache.lucene.document.Fieldable;
import org.codehaus.jackson.JsonToken;
import org.elasticsearch.util.Booleans;
import org.elasticsearch.util.lucene.Lucene;

import java.io.IOException;

/**
* @author kimchy (Shay Banon)
* @author kimchy (shay.banon)
*/
// TODO this can be made better, maybe storing a byte for it?
public class JsonBooleanFieldMapper extends JsonFieldMapper<Boolean> {
Expand Down Expand Up @@ -93,7 +94,7 @@ protected JsonBooleanFieldMapper(Names names, Field.Index index, Field.Store sto
}

@Override public Boolean value(Fieldable field) {
return Boolean.parseBoolean(valueAsString(field));
return field.stringValue().charAt(0) == 'T' ? Boolean.TRUE : Boolean.FALSE;
}

@Override public String valueAsString(Fieldable field) {
Expand All @@ -104,7 +105,10 @@ protected JsonBooleanFieldMapper(Names names, Field.Index index, Field.Store sto
if (value == null || value.length() == 0) {
return "F";
}
return value.equals("true") ? "T" : "F";
if (Booleans.parseBoolean(value, false)) {
return "T";
}
return "F";
}

@Override public String indexedValue(Boolean value) {
Expand Down Expand Up @@ -132,10 +136,10 @@ protected JsonBooleanFieldMapper(Names names, Field.Index index, Field.Store sto
value = "T";
}
} else if (token == JsonToken.VALUE_STRING) {
if (jsonContext.jp().getText().equals("false")) {
value = "F";
} else {
if (Booleans.parseBoolean(jsonContext.jp().getText(), false)) {
value = "T";
} else {
value = "F";
}
} else {
return null;
Expand Down

0 comments on commit 47c11aa

Please sign in to comment.