Skip to content
This repository has been archived by the owner on Nov 22, 2017. It is now read-only.

Commit

Permalink
add double, float and int numeric types
Browse files Browse the repository at this point in the history
  • Loading branch information
tjake committed Jul 29, 2011
1 parent 35b972e commit b8d8b81
Show file tree
Hide file tree
Showing 5 changed files with 370 additions and 89 deletions.
14 changes: 13 additions & 1 deletion src/lucandra/IndexReader.java
Expand Up @@ -328,7 +328,19 @@ public Document document(int docNum, FieldSelector selector) throws CorruptIndex
if( term.isSetLongVal() )
{
f = new NumericField(term.getField()).setLongValue(term.getLongVal());
}
}
else if(term.isSetDoubleVal())
{
f = new NumericField(term.getField()).setDoubleValue(term.getDoubleVal());
}
else if(term.isSetIntVal())
{
f = new NumericField(term.getField()).setIntValue(term.getIntVal());
}
else if(term.isSetFloatVal())
{
f = new NumericField(term.getField()).setFloatValue((float)term.getFloatVal());
}
else if(term.isSetIs_binary())
{
if(term.is_binary)
Expand Down
10 changes: 9 additions & 1 deletion src/lucandra/IndexWriter.java
Expand Up @@ -45,6 +45,7 @@
import org.apache.lucene.document.Document;
import org.apache.lucene.document.Fieldable;
import org.apache.lucene.document.NumericField;
import org.apache.lucene.document.NumericField.DataType;
import org.apache.lucene.index.CorruptIndexException;
import org.apache.lucene.index.FieldInvertState;
import org.apache.lucene.index.Term;
Expand Down Expand Up @@ -289,7 +290,14 @@ public void addDocument(String indexName, Document doc, Analyzer analyzer, int d
if (field instanceof NumericField)
{
Number n = ((NumericField) field).getNumericValue();
tt.setLongVal(n.longValue());
switch(((NumericField) field).getDataType())
{
case LONG: tt.setLongVal(n.longValue()); break;
case INT: tt.setIntVal(n.intValue()); break;
case FLOAT: tt.setFloatVal(n.floatValue()); break;
case DOUBLE: tt.setDoubleVal(n.doubleValue()); break;
default: throw new IllegalStateException("Unknown numeric type in field: "+field);
};
}

byte[] value = field.isBinary() ? field.getBinaryValue() : field.stringValue().getBytes("UTF-8");
Expand Down
54 changes: 24 additions & 30 deletions thrift/gen-java/lucandra/serializers/thrift/DocumentMetadata.java
Expand Up @@ -21,21 +21,15 @@
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

import org.apache.thrift.*;
import org.apache.thrift.async.*;
import org.apache.thrift.meta_data.*;
import org.apache.thrift.transport.*;
import org.apache.thrift.protocol.*;
public class DocumentMetadata implements org.apache.thrift.TBase<DocumentMetadata, DocumentMetadata._Fields>, java.io.Serializable, Cloneable {
private static final org.apache.thrift.protocol.TStruct STRUCT_DESC = new org.apache.thrift.protocol.TStruct("DocumentMetadata");

public class DocumentMetadata implements TBase<DocumentMetadata, DocumentMetadata._Fields>, java.io.Serializable, Cloneable {
private static final TStruct STRUCT_DESC = new TStruct("DocumentMetadata");

private static final TField TERMS_FIELD_DESC = new TField("terms", TType.LIST, (short)1);
private static final org.apache.thrift.protocol.TField TERMS_FIELD_DESC = new org.apache.thrift.protocol.TField("terms", org.apache.thrift.protocol.TType.LIST, (short)1);

public List<ThriftTerm> terms;

/** The set of fields this struct contains, along with convenience methods for finding and manipulating them. */
public enum _Fields implements TFieldIdEnum {
public enum _Fields implements org.apache.thrift.TFieldIdEnum {
TERMS((short)1, "terms");

private static final Map<String, _Fields> byName = new HashMap<String, _Fields>();
Expand Down Expand Up @@ -94,14 +88,14 @@ public String getFieldName() {

// isset id assignments

public static final Map<_Fields, FieldMetaData> metaDataMap;
public static final Map<_Fields, org.apache.thrift.meta_data.FieldMetaData> metaDataMap;
static {
Map<_Fields, FieldMetaData> tmpMap = new EnumMap<_Fields, FieldMetaData>(_Fields.class);
tmpMap.put(_Fields.TERMS, new FieldMetaData("terms", TFieldRequirementType.REQUIRED,
new ListMetaData(TType.LIST,
new StructMetaData(TType.STRUCT, ThriftTerm.class))));
Map<_Fields, org.apache.thrift.meta_data.FieldMetaData> tmpMap = new EnumMap<_Fields, org.apache.thrift.meta_data.FieldMetaData>(_Fields.class);
tmpMap.put(_Fields.TERMS, new org.apache.thrift.meta_data.FieldMetaData("terms", org.apache.thrift.TFieldRequirementType.REQUIRED,
new org.apache.thrift.meta_data.ListMetaData(org.apache.thrift.protocol.TType.LIST,
new org.apache.thrift.meta_data.StructMetaData(org.apache.thrift.protocol.TType.STRUCT, ThriftTerm.class))));
metaDataMap = Collections.unmodifiableMap(tmpMap);
FieldMetaData.addStructMetaDataMap(DocumentMetadata.class, metaDataMap);
org.apache.thrift.meta_data.FieldMetaData.addStructMetaDataMap(DocumentMetadata.class, metaDataMap);
}

public DocumentMetadata() {
Expand Down Expand Up @@ -164,7 +158,7 @@ public void unsetTerms() {
this.terms = null;
}

/** Returns true if field terms is set (has been asigned a value) and false otherwise */
/** Returns true if field terms is set (has been assigned a value) and false otherwise */
public boolean isSetTerms() {
return this.terms != null;
}
Expand Down Expand Up @@ -197,7 +191,7 @@ public Object getFieldValue(_Fields field) {
throw new IllegalStateException();
}

/** Returns true if field corresponding to fieldID is set (has been asigned a value) and false otherwise */
/** Returns true if field corresponding to fieldID is set (has been assigned a value) and false otherwise */
public boolean isSet(_Fields field) {
if (field == null) {
throw new IllegalArgumentException();
Expand Down Expand Up @@ -260,7 +254,7 @@ public int compareTo(DocumentMetadata other) {
return lastComparison;
}
if (isSetTerms()) {
lastComparison = TBaseHelper.compareTo(this.terms, typedOther.terms);
lastComparison = org.apache.thrift.TBaseHelper.compareTo(this.terms, typedOther.terms);
if (lastComparison != 0) {
return lastComparison;
}
Expand All @@ -272,20 +266,20 @@ public _Fields fieldForId(int fieldId) {
return _Fields.findByThriftId(fieldId);
}

public void read(TProtocol iprot) throws TException {
TField field;
public void read(org.apache.thrift.protocol.TProtocol iprot) throws org.apache.thrift.TException {
org.apache.thrift.protocol.TField field;
iprot.readStructBegin();
while (true)
{
field = iprot.readFieldBegin();
if (field.type == TType.STOP) {
if (field.type == org.apache.thrift.protocol.TType.STOP) {
break;
}
switch (field.id) {
case 1: // TERMS
if (field.type == TType.LIST) {
if (field.type == org.apache.thrift.protocol.TType.LIST) {
{
TList _list0 = iprot.readListBegin();
org.apache.thrift.protocol.TList _list0 = iprot.readListBegin();
this.terms = new ArrayList<ThriftTerm>(_list0.size);
for (int _i1 = 0; _i1 < _list0.size; ++_i1)
{
Expand All @@ -297,11 +291,11 @@ public void read(TProtocol iprot) throws TException {
iprot.readListEnd();
}
} else {
TProtocolUtil.skip(iprot, field.type);
org.apache.thrift.protocol.TProtocolUtil.skip(iprot, field.type);
}
break;
default:
TProtocolUtil.skip(iprot, field.type);
org.apache.thrift.protocol.TProtocolUtil.skip(iprot, field.type);
}
iprot.readFieldEnd();
}
Expand All @@ -311,14 +305,14 @@ public void read(TProtocol iprot) throws TException {
validate();
}

public void write(TProtocol oprot) throws TException {
public void write(org.apache.thrift.protocol.TProtocol oprot) throws org.apache.thrift.TException {
validate();

oprot.writeStructBegin(STRUCT_DESC);
if (this.terms != null) {
oprot.writeFieldBegin(TERMS_FIELD_DESC);
{
oprot.writeListBegin(new TList(TType.STRUCT, this.terms.size()));
oprot.writeListBegin(new org.apache.thrift.protocol.TList(org.apache.thrift.protocol.TType.STRUCT, this.terms.size()));
for (ThriftTerm _iter3 : this.terms)
{
_iter3.write(oprot);
Expand Down Expand Up @@ -347,10 +341,10 @@ public String toString() {
return sb.toString();
}

public void validate() throws TException {
public void validate() throws org.apache.thrift.TException {
// check for required fields
if (terms == null) {
throw new TProtocolException("Required field 'terms' was not present! Struct: " + toString());
throw new org.apache.thrift.protocol.TProtocolException("Required field 'terms' was not present! Struct: " + toString());
}
}

Expand Down

0 comments on commit b8d8b81

Please sign in to comment.