Updated Branches: refs/heads/0.2-dev 4a8c3779f -> a0821c6ea
Cleaned up type conversions, next is in the parser. Project: http://git-wip-us.apache.org/repos/asf/incubator-blur/repo Commit: http://git-wip-us.apache.org/repos/asf/incubator-blur/commit/a0821c6e Tree: http://git-wip-us.apache.org/repos/asf/incubator-blur/tree/a0821c6e Diff: http://git-wip-us.apache.org/repos/asf/incubator-blur/diff/a0821c6e Branch: refs/heads/0.2-dev Commit: a0821c6ea418e109e96e50364fc440ca3e4919e0 Parents: b292431 Author: Aaron McCurry <[email protected]> Authored: Thu Jan 17 17:46:22 2013 -0500 Committer: Aaron McCurry <[email protected]> Committed: Thu Jan 17 17:46:22 2013 -0500 ---------------------------------------------------------------------- .../java/org/apache/blur/server/BlurServer.java | 16 +-- .../java/org/apache/blur/server/TableContext.java | 1 - .../java/org/apache/blur/server/TypeChecker.java | 25 ++++ .../apache/blur/server/ZooKeeperTypeChecker.java | 23 ++++ .../apache/blur/utils/ThriftLuceneConversion.java | 67 +++++------ .../java/org/apache/blur/thrift/BinaryField.java | 73 ++++++++++++ .../java/org/apache/blur/thrift/DoubleField.java | 91 +++++++++++++++ .../java/org/apache/blur/thrift/FloatField.java | 91 +++++++++++++++ .../main/java/org/apache/blur/thrift/IntField.java | 91 +++++++++++++++ .../java/org/apache/blur/thrift/LongField.java | 11 +- .../java/org/apache/blur/thrift/StringField.java | 6 +- .../java/org/apache/blur/thrift/TextField.java | 10 +- 12 files changed, 446 insertions(+), 59 deletions(-) ---------------------------------------------------------------------- http://git-wip-us.apache.org/repos/asf/incubator-blur/blob/a0821c6e/src/blur-core/src/main/java/org/apache/blur/server/BlurServer.java ---------------------------------------------------------------------- diff --git a/src/blur-core/src/main/java/org/apache/blur/server/BlurServer.java b/src/blur-core/src/main/java/org/apache/blur/server/BlurServer.java index 2c0fd59..ec77ebf 100644 --- a/src/blur-core/src/main/java/org/apache/blur/server/BlurServer.java +++ b/src/blur-core/src/main/java/org/apache/blur/server/BlurServer.java @@ -210,7 +210,7 @@ public class BlurServer extends TableAdmin implements Iface { Collection<SearchAction> searchersToSearch = getSearchActions(tableDescriptor, shardIndexes, searchers); List<Future<TopFieldDocs>> futures = new ArrayList<Future<TopFieldDocs>>(searchersToSearch.size()); - + TableContext context = _indexServer.getTableContext(session.getTableName()); QueryConverter queryConverter = context.getQueryConverter(); @@ -319,6 +319,7 @@ public class BlurServer extends TableAdmin implements Iface { public List<Document> doc(Session session, List<Long> docLocations, Set<String> fieldsToLoad) throws BlurException, TException { try { SessionInfo sessionInfo = getSessionInfo(session); + TableContext context = _indexServer.getTableContext(session.getTableName()); Map<Integer, IndexSearcher> searchers = sessionInfo.getSearchers(); List<Document> result = new ArrayList<Document>(); for (Long docLocation : docLocations) { @@ -332,7 +333,7 @@ public class BlurServer extends TableAdmin implements Iface { result.addAll(forwardDoc(session, shardIndex, docLocation, fieldsToLoad)); } else { org.apache.lucene.document.Document document = searcher.document(docId, fieldsToLoad); - result.add(toThrift(document)); + result.add(toThrift(document, context.getTypeChecker())); } } return result; @@ -383,7 +384,7 @@ public class BlurServer extends TableAdmin implements Iface { throw new BException(t.getMessage(), t); } } - + private int getShardIndex(MutateOptions options) { int shardIndex = options.getShardIndex(); if (shardIndex < 0) { @@ -449,7 +450,7 @@ public class BlurServer extends TableAdmin implements Iface { throw new BException(t.getMessage(), t); } } - + @Override public List<Generation> deleteDocuments(MutateOptions options, List<Term> terms) throws BlurException, TException { String table = options.getTable(); @@ -481,7 +482,7 @@ public class BlurServer extends TableAdmin implements Iface { List<Generation> generations = new ArrayList<Generation>(); try { BlurIndex index = getIndex(table, shardIndex); - List<UpdatePackage> updatePackagesWithIndexableDocs = BlurValidations.getAllIndexablePackages(updatePackages); + List<UpdatePackage> updatePackagesWithIndexableDocs = BlurValidations.getAllIndexablePackages(updatePackages); if (index == null) { generations.addAll(forwardUpdateDocuments(options, updatePackagesWithIndexableDocs)); } else { @@ -530,10 +531,7 @@ public class BlurServer extends TableAdmin implements Iface { @Override public TableSchema schema(Session session, List<Integer> shardIds) throws BlurException, TException { SessionInfo info = getSessionInfo(session); - - - - + throw new BlurException("Not implemented", null); } http://git-wip-us.apache.org/repos/asf/incubator-blur/blob/a0821c6e/src/blur-core/src/main/java/org/apache/blur/server/TableContext.java ---------------------------------------------------------------------- diff --git a/src/blur-core/src/main/java/org/apache/blur/server/TableContext.java b/src/blur-core/src/main/java/org/apache/blur/server/TableContext.java index f4a6081..a2ecd67 100644 --- a/src/blur-core/src/main/java/org/apache/blur/server/TableContext.java +++ b/src/blur-core/src/main/java/org/apache/blur/server/TableContext.java @@ -38,7 +38,6 @@ import org.apache.lucene.index.IndexDeletionPolicy; import org.apache.lucene.index.KeepOnlyLastCommitDeletionPolicy; import org.apache.lucene.search.similarities.DefaultSimilarity; import org.apache.lucene.search.similarities.Similarity; -import org.apache.zookeeper.ZooKeeper; public class TableContext { http://git-wip-us.apache.org/repos/asf/incubator-blur/blob/a0821c6e/src/blur-core/src/main/java/org/apache/blur/server/TypeChecker.java ---------------------------------------------------------------------- diff --git a/src/blur-core/src/main/java/org/apache/blur/server/TypeChecker.java b/src/blur-core/src/main/java/org/apache/blur/server/TypeChecker.java index 9a66c63..9772501 100644 --- a/src/blur-core/src/main/java/org/apache/blur/server/TypeChecker.java +++ b/src/blur-core/src/main/java/org/apache/blur/server/TypeChecker.java @@ -1,8 +1,25 @@ package org.apache.blur.server; +/** + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You under the Apache License, Version 2.0 + * (the "License"); you may not use this file except in compliance with + * the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ import java.io.IOException; import org.apache.blur.thrift.generated.Field; +import org.apache.blur.thrift.generated.TYPE; public abstract class TypeChecker { @@ -19,4 +36,12 @@ public abstract class TypeChecker { */ public abstract void validate(Field field) throws IOException; + /** + * Finds the type for the given name. + * @param name the field name. + * @return the TYPE of the field. + * @throws IOException + */ + public abstract TYPE getType(String name) throws IOException; + } http://git-wip-us.apache.org/repos/asf/incubator-blur/blob/a0821c6e/src/blur-core/src/main/java/org/apache/blur/server/ZooKeeperTypeChecker.java ---------------------------------------------------------------------- diff --git a/src/blur-core/src/main/java/org/apache/blur/server/ZooKeeperTypeChecker.java b/src/blur-core/src/main/java/org/apache/blur/server/ZooKeeperTypeChecker.java index 90002ea..87c63b3 100644 --- a/src/blur-core/src/main/java/org/apache/blur/server/ZooKeeperTypeChecker.java +++ b/src/blur-core/src/main/java/org/apache/blur/server/ZooKeeperTypeChecker.java @@ -1,10 +1,27 @@ package org.apache.blur.server; +/** + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You under the Apache License, Version 2.0 + * (the "License"); you may not use this file except in compliance with + * the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ import java.io.IOException; import org.apache.blur.log.Log; import org.apache.blur.log.LogFactory; import org.apache.blur.thrift.generated.Field; +import org.apache.blur.thrift.generated.TYPE; import org.apache.blur.zookeeper.ZkCachedMap; import org.apache.zookeeper.ZooKeeper; @@ -37,4 +54,10 @@ public class ZooKeeperTypeChecker extends TypeChecker { throw new IOException("The field type [" + fieldType + "] for field [" + fieldName + "] does not match the table type of [" + existingType + "] for table [" + _table + "]"); } } + + @Override + public TYPE getType(String name) throws IOException { + String type = cachedMap.get(name); + return TYPE.valueOf(type); + } } http://git-wip-us.apache.org/repos/asf/incubator-blur/blob/a0821c6e/src/blur-core/src/main/java/org/apache/blur/utils/ThriftLuceneConversion.java ---------------------------------------------------------------------- diff --git a/src/blur-core/src/main/java/org/apache/blur/utils/ThriftLuceneConversion.java b/src/blur-core/src/main/java/org/apache/blur/utils/ThriftLuceneConversion.java index f093ca2..8f1aaa7 100644 --- a/src/blur-core/src/main/java/org/apache/blur/utils/ThriftLuceneConversion.java +++ b/src/blur-core/src/main/java/org/apache/blur/utils/ThriftLuceneConversion.java @@ -79,53 +79,42 @@ public class ThriftLuceneConversion { return new org.apache.lucene.search.ScoreDoc(BlurUtil.getDocumentId(docLocation), (float) scoreDoc.score, BlurUtil.getShardIndex(docLocation)); } - public static org.apache.blur.thrift.generated.Document toThrift(org.apache.lucene.document.Document document) { + public static org.apache.blur.thrift.generated.Document toThrift(org.apache.lucene.document.Document document, TypeChecker typeChecker) throws IOException { org.apache.blur.thrift.generated.Document result = new org.apache.blur.thrift.generated.Document(); List<IndexableField> fields = document.getFields(); for (IndexableField field : fields) { - result.addToFields(toThrift(field)); + result.addToFields(toThrift(field, typeChecker)); } return result; } - public static Field toThrift(IndexableField field) { - Field result = new Field(); - result.setBoost(field.boost()); - result.setName(field.name()); - Number number = field.numericValue(); - if (number != null) { - if (number instanceof Byte || number instanceof Short || number instanceof Integer) { - result.setType(TYPE.INT); - result.setValue(toByteBuffer((Integer) number)); - } else if (number instanceof Long) { - result.setType(TYPE.LONG); - result.setValue(toByteBuffer((Long) number)); - } else if (number instanceof Float) { - result.setType(TYPE.FLOAT); - result.setValue(toByteBuffer((Float) number)); - } else if (number instanceof Double) { - result.setType(TYPE.DOUBLE); - result.setValue(toByteBuffer((Double) number)); - } else { - throw new IllegalArgumentException("cannot store numeric type " + number.getClass()); - } - } else { - BytesRef bytes = field.binaryValue(); - if (bytes != null) { - result.setType(TYPE.BINARY); - result.setValue(toByteBuffer(bytes)); - } else { - // @TODO this is a bit of a hack - if (field.fieldType().omitNorms()) { - result.setType(TYPE.STRING); - result.setValue(toByteBuffer(field.stringValue())); - } else { - result.setType(TYPE.TEXT); - result.setValue(toByteBuffer(field.stringValue())); - } - } + public static Field toThrift(IndexableField field, TypeChecker typeChecker) throws IOException { + TYPE type = typeChecker.getType(field.name()); + switch (type) { + case STRING: + return new org.apache.blur.thrift.StringField(field.name(), field.stringValue(), field.boost()); + case TEXT: + return new org.apache.blur.thrift.TextField(field.name(), field.stringValue(), field.boost()); + case INT: + return new org.apache.blur.thrift.IntField(field.name(), (Integer) field.numericValue(), field.boost()); + case FLOAT: + return new org.apache.blur.thrift.FloatField(field.name(), (Float) field.numericValue(), field.boost()); + case LONG: + return new org.apache.blur.thrift.LongField(field.name(), (Long) field.numericValue(), field.boost()); + case DOUBLE: + return new org.apache.blur.thrift.DoubleField(field.name(), (Double) field.numericValue(), field.boost()); + case BINARY: + byte[] value = trim(field.binaryValue()); + return new org.apache.blur.thrift.BinaryField(field.name(), value, field.boost()); + default: + throw new RuntimeException("Type [" + type + "] not supported."); } - return result; + } + + private static byte[] trim(BytesRef bytesRef) { + byte[] buf = new byte[bytesRef.length]; + System.arraycopy(buf, 0, bytesRef.bytes, bytesRef.offset, bytesRef.length); + return buf; } public static ByteBuffer toByteBuffer(String val) { http://git-wip-us.apache.org/repos/asf/incubator-blur/blob/a0821c6e/src/blur-thrift/src/main/java/org/apache/blur/thrift/BinaryField.java ---------------------------------------------------------------------- diff --git a/src/blur-thrift/src/main/java/org/apache/blur/thrift/BinaryField.java b/src/blur-thrift/src/main/java/org/apache/blur/thrift/BinaryField.java new file mode 100644 index 0000000..b71e0b4 --- /dev/null +++ b/src/blur-thrift/src/main/java/org/apache/blur/thrift/BinaryField.java @@ -0,0 +1,73 @@ +package org.apache.blur.thrift; + +import java.nio.ByteBuffer; + +import org.apache.blur.thrift.generated.Field; +import org.apache.blur.thrift.generated.TYPE; + +@SuppressWarnings("serial") +public class BinaryField extends Field { + + public BinaryField(String name, byte[] value, double boost) { + super(name, toByteBuffer(value), TYPE.BINARY, boost); + } + + public BinaryField(String name, byte[] value) { + this(name, value, 1.0); + } + + private static ByteBuffer toByteBuffer(byte[] value) { + return ByteBuffer.wrap(value); + } + + public BinaryField() { + + } + + public BinaryField(Field field) { + super(field.name, field.value, field.type, field.boost); + if (field.getType() != TYPE.BINARY) { + throw new RuntimeException("Field [" + field + "] is not of type Binary."); + } + } + + @Override + public String toString() { + StringBuilder sb = new StringBuilder("BinaryField("); + boolean first = true; + + sb.append("name:"); + if (this.name == null) { + sb.append("null"); + } else { + sb.append(this.name); + } + first = false; + if (!first) + sb.append(", "); + sb.append("value:"); + if (this.value == null) { + sb.append("null"); + } else { + org.apache.thrift.TBaseHelper.toString(this.value, sb); + } + first = false; + if (!first) + sb.append(", "); + sb.append("type:"); + if (this.type == null) { + sb.append("null"); + } else { + sb.append(this.type); + } + first = false; + if (!first) + sb.append(", "); + sb.append("boost:"); + sb.append(this.boost); + first = false; + sb.append(")"); + return sb.toString(); + } + +} http://git-wip-us.apache.org/repos/asf/incubator-blur/blob/a0821c6e/src/blur-thrift/src/main/java/org/apache/blur/thrift/DoubleField.java ---------------------------------------------------------------------- diff --git a/src/blur-thrift/src/main/java/org/apache/blur/thrift/DoubleField.java b/src/blur-thrift/src/main/java/org/apache/blur/thrift/DoubleField.java new file mode 100644 index 0000000..f2908c6 --- /dev/null +++ b/src/blur-thrift/src/main/java/org/apache/blur/thrift/DoubleField.java @@ -0,0 +1,91 @@ +package org.apache.blur.thrift; + +import java.nio.ByteBuffer; + +import org.apache.blur.thrift.generated.Field; +import org.apache.blur.thrift.generated.TYPE; + +@SuppressWarnings("serial") +public class DoubleField extends Field { + + public DoubleField(String name, Double value, double boost) { + super(name, toByteBuffer(value), TYPE.DOUBLE, boost); + } + + public DoubleField(String name, Double value) { + this(name, value, 1.0); + } + + private static ByteBuffer toByteBuffer(Double value) { + if (value == null) { + return null; + } + ByteBuffer buffer = ByteBuffer.allocate(8).putDouble(value); + buffer.flip(); + return buffer; + } + + public DoubleField() { + + } + + public DoubleField(Field field) { + super(field.name, field.value, field.type, field.boost); + if (field.getType() != TYPE.DOUBLE) { + throw new RuntimeException("Field [" + field + "] is not of type Double."); + } + } + + public Double getValueDouble() { + byte[] bs = getValue(); + if (bs == null) { + return null; + } + return ByteBuffer.wrap(bs).getDouble(); + } + + public DoubleField setValueDouble(Double value) { + setValue(toByteBuffer(value)); + return this; + } + + @Override + public String toString() { + StringBuilder sb = new StringBuilder("DoubleField("); + boolean first = true; + + sb.append("name:"); + if (this.name == null) { + sb.append("null"); + } else { + sb.append(this.name); + } + first = false; + if (!first) + sb.append(", "); + sb.append("value:"); + if (this.value == null) { + sb.append("null"); + } else { + sb.append(getValueDouble()); + } + first = false; + if (!first) + sb.append(", "); + sb.append("type:"); + if (this.type == null) { + sb.append("null"); + } else { + sb.append(this.type); + } + first = false; + if (!first) + sb.append(", "); + sb.append("boost:"); + sb.append(this.boost); + first = false; + sb.append(")"); + return sb.toString(); + } + +} http://git-wip-us.apache.org/repos/asf/incubator-blur/blob/a0821c6e/src/blur-thrift/src/main/java/org/apache/blur/thrift/FloatField.java ---------------------------------------------------------------------- diff --git a/src/blur-thrift/src/main/java/org/apache/blur/thrift/FloatField.java b/src/blur-thrift/src/main/java/org/apache/blur/thrift/FloatField.java new file mode 100644 index 0000000..f13b2dd --- /dev/null +++ b/src/blur-thrift/src/main/java/org/apache/blur/thrift/FloatField.java @@ -0,0 +1,91 @@ +package org.apache.blur.thrift; + +import java.nio.ByteBuffer; + +import org.apache.blur.thrift.generated.Field; +import org.apache.blur.thrift.generated.TYPE; + +@SuppressWarnings("serial") +public class FloatField extends Field { + + public FloatField(String name, Float value, double boost) { + super(name, toByteBuffer(value), TYPE.FLOAT, boost); + } + + public FloatField(String name, Float value) { + this(name, value, 1.0); + } + + private static ByteBuffer toByteBuffer(Float value) { + if (value == null) { + return null; + } + ByteBuffer buffer = ByteBuffer.allocate(4).putFloat(value); + buffer.flip(); + return buffer; + } + + public FloatField() { + + } + + public FloatField(Field field) { + super(field.name, field.value, field.type, field.boost); + if (field.getType() != TYPE.FLOAT) { + throw new RuntimeException("Field [" + field + "] is not of type Float."); + } + } + + public Float getValueFloat() { + byte[] bs = getValue(); + if (bs == null) { + return null; + } + return ByteBuffer.wrap(bs).getFloat(); + } + + public FloatField setValueFloat(Float value) { + setValue(toByteBuffer(value)); + return this; + } + + @Override + public String toString() { + StringBuilder sb = new StringBuilder("FloatField("); + boolean first = true; + + sb.append("name:"); + if (this.name == null) { + sb.append("null"); + } else { + sb.append(this.name); + } + first = false; + if (!first) + sb.append(", "); + sb.append("value:"); + if (this.value == null) { + sb.append("null"); + } else { + sb.append(getValueFloat()); + } + first = false; + if (!first) + sb.append(", "); + sb.append("type:"); + if (this.type == null) { + sb.append("null"); + } else { + sb.append(this.type); + } + first = false; + if (!first) + sb.append(", "); + sb.append("boost:"); + sb.append(this.boost); + first = false; + sb.append(")"); + return sb.toString(); + } + +} http://git-wip-us.apache.org/repos/asf/incubator-blur/blob/a0821c6e/src/blur-thrift/src/main/java/org/apache/blur/thrift/IntField.java ---------------------------------------------------------------------- diff --git a/src/blur-thrift/src/main/java/org/apache/blur/thrift/IntField.java b/src/blur-thrift/src/main/java/org/apache/blur/thrift/IntField.java new file mode 100644 index 0000000..21c03b4 --- /dev/null +++ b/src/blur-thrift/src/main/java/org/apache/blur/thrift/IntField.java @@ -0,0 +1,91 @@ +package org.apache.blur.thrift; + +import java.nio.ByteBuffer; + +import org.apache.blur.thrift.generated.Field; +import org.apache.blur.thrift.generated.TYPE; + +@SuppressWarnings("serial") +public class IntField extends Field { + + public IntField(String name, Integer value, double boost) { + super(name, toByteBuffer(value), TYPE.INT, boost); + } + + public IntField(String name, Integer value) { + this(name, value, 1.0); + } + + private static ByteBuffer toByteBuffer(Integer value) { + if (value == null) { + return null; + } + ByteBuffer buffer = ByteBuffer.allocate(4).putInt(value); + buffer.flip(); + return buffer; + } + + public IntField() { + + } + + public IntField(Field field) { + super(field.name, field.value, field.type, field.boost); + if (field.getType() != TYPE.INT) { + throw new RuntimeException("Field [" + field + "] is not of type Int."); + } + } + + public Integer getValueInt() { + byte[] bs = getValue(); + if (bs == null) { + return null; + } + return ByteBuffer.wrap(bs).getInt(); + } + + public IntField setValueInt(Integer value) { + setValue(toByteBuffer(value)); + return this; + } + + @Override + public String toString() { + StringBuilder sb = new StringBuilder("IntField("); + boolean first = true; + + sb.append("name:"); + if (this.name == null) { + sb.append("null"); + } else { + sb.append(this.name); + } + first = false; + if (!first) + sb.append(", "); + sb.append("value:"); + if (this.value == null) { + sb.append("null"); + } else { + sb.append(getValueInt()); + } + first = false; + if (!first) + sb.append(", "); + sb.append("type:"); + if (this.type == null) { + sb.append("null"); + } else { + sb.append(this.type); + } + first = false; + if (!first) + sb.append(", "); + sb.append("boost:"); + sb.append(this.boost); + first = false; + sb.append(")"); + return sb.toString(); + } + +} http://git-wip-us.apache.org/repos/asf/incubator-blur/blob/a0821c6e/src/blur-thrift/src/main/java/org/apache/blur/thrift/LongField.java ---------------------------------------------------------------------- diff --git a/src/blur-thrift/src/main/java/org/apache/blur/thrift/LongField.java b/src/blur-thrift/src/main/java/org/apache/blur/thrift/LongField.java index 605f128..2255b5b 100644 --- a/src/blur-thrift/src/main/java/org/apache/blur/thrift/LongField.java +++ b/src/blur-thrift/src/main/java/org/apache/blur/thrift/LongField.java @@ -8,13 +8,12 @@ import org.apache.blur.thrift.generated.TYPE; @SuppressWarnings("serial") public class LongField extends Field { - public LongField(String name, Long value) { - super(name, toByteBuffer(value), TYPE.LONG, 1.0); + public LongField(String name, Long value, double boost) { + super(name, toByteBuffer(value), TYPE.LONG, boost); } - - public static void main(String[] args) { - LongField longField = new LongField("a", 1l); - System.out.println(longField.getValueLong()); + + public LongField(String name, Long value) { + this(name, value, 1.0); } private static ByteBuffer toByteBuffer(Long value) { http://git-wip-us.apache.org/repos/asf/incubator-blur/blob/a0821c6e/src/blur-thrift/src/main/java/org/apache/blur/thrift/StringField.java ---------------------------------------------------------------------- diff --git a/src/blur-thrift/src/main/java/org/apache/blur/thrift/StringField.java b/src/blur-thrift/src/main/java/org/apache/blur/thrift/StringField.java index 656d109..28c1268 100644 --- a/src/blur-thrift/src/main/java/org/apache/blur/thrift/StringField.java +++ b/src/blur-thrift/src/main/java/org/apache/blur/thrift/StringField.java @@ -12,7 +12,11 @@ public class StringField extends Field { private static final String UTF_8 = "UTF-8"; public StringField(String name, String value) { - super(name, toByteBuffer(value), TYPE.STRING, 1.0); + this(name, value, 1.0); + } + + public StringField(String name, String value, double boost) { + super(name, toByteBuffer(value), TYPE.STRING, boost); } private static ByteBuffer toByteBuffer(String value) { http://git-wip-us.apache.org/repos/asf/incubator-blur/blob/a0821c6e/src/blur-thrift/src/main/java/org/apache/blur/thrift/TextField.java ---------------------------------------------------------------------- diff --git a/src/blur-thrift/src/main/java/org/apache/blur/thrift/TextField.java b/src/blur-thrift/src/main/java/org/apache/blur/thrift/TextField.java index 6963f99..e520a42 100644 --- a/src/blur-thrift/src/main/java/org/apache/blur/thrift/TextField.java +++ b/src/blur-thrift/src/main/java/org/apache/blur/thrift/TextField.java @@ -10,9 +10,13 @@ import org.apache.blur.thrift.generated.TYPE; public class TextField extends Field { private static final String UTF_8 = "UTF-8"; - + + public TextField(String name, String value, double boost) { + super(name, toByteBuffer(value), TYPE.TEXT, boost); + } + public TextField(String name, String value) { - super(name, toByteBuffer(value), TYPE.TEXT, 1.0); + this(name, value, 1.0); } private static ByteBuffer toByteBuffer(String value) { @@ -30,7 +34,7 @@ public class TextField extends Field { public TextField(Field field) { super(field.name, field.value, field.type, field.boost); if (field.getType() != TYPE.TEXT) { - throw new RuntimeException("Field [" + field + "] is not of type TEXT."); + throw new RuntimeException("Field [" + field + "] is not of type Text."); } }
