incubator-blur-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From amccu...@apache.org
Subject git commit: Initial commit for BLUR-30
Date Tue, 23 Oct 2012 01:13:04 GMT
Updated Branches:
  refs/heads/lucene-4.0.0-compress-codec [created] c767e2a77


Initial commit for BLUR-30


Project: http://git-wip-us.apache.org/repos/asf/incubator-blur/repo
Commit: http://git-wip-us.apache.org/repos/asf/incubator-blur/commit/c767e2a7
Tree: http://git-wip-us.apache.org/repos/asf/incubator-blur/tree/c767e2a7
Diff: http://git-wip-us.apache.org/repos/asf/incubator-blur/diff/c767e2a7

Branch: refs/heads/lucene-4.0.0-compress-codec
Commit: c767e2a77787e3ac60ceb1d52f14ae501e5eb156
Parents: bc7b6df
Author: Aaron McCurry <amccurry@gmail.com>
Authored: Mon Oct 22 21:11:43 2012 -0400
Committer: Aaron McCurry <amccurry@gmail.com>
Committed: Mon Oct 22 21:11:43 2012 -0400

----------------------------------------------------------------------
 .../blur/lucene/codecs/DocumentWritable.java       |   37 +++++
 .../apache/blur/lucene/codecs/FieldWritable.java   |  125 +++++++++++++++
 2 files changed, 162 insertions(+), 0 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/incubator-blur/blob/c767e2a7/src/blur-store/src/main/java/org/apache/blur/lucene/codecs/DocumentWritable.java
----------------------------------------------------------------------
diff --git a/src/blur-store/src/main/java/org/apache/blur/lucene/codecs/DocumentWritable.java
b/src/blur-store/src/main/java/org/apache/blur/lucene/codecs/DocumentWritable.java
new file mode 100644
index 0000000..1afb422
--- /dev/null
+++ b/src/blur-store/src/main/java/org/apache/blur/lucene/codecs/DocumentWritable.java
@@ -0,0 +1,37 @@
+package org.apache.blur.lucene.codecs;
+
+import java.io.DataInput;
+import java.io.DataOutput;
+import java.io.IOException;
+import java.util.ArrayList;
+import java.util.List;
+
+import org.apache.hadoop.io.Writable;
+
+public class DocumentWritable implements Writable {
+
+  private List<FieldWritable> fields = new ArrayList<FieldWritable>();
+
+  public void addFields(FieldWritable field) {
+    fields.add(field);
+  }
+
+  @Override
+  public void readFields(DataInput in) throws IOException {
+    fields.clear();
+    int size = in.readInt();
+    for (int i = 0; i < size; i++) {
+      FieldWritable blurField = new FieldWritable();
+      blurField.readFields(in);
+      fields.add(blurField);
+    }
+  }
+
+  @Override
+  public void write(DataOutput out) throws IOException {
+    out.writeInt(fields.size());
+    for (FieldWritable blurField : fields) {
+      blurField.write(out);
+    }
+  }
+}
\ No newline at end of file

http://git-wip-us.apache.org/repos/asf/incubator-blur/blob/c767e2a7/src/blur-store/src/main/java/org/apache/blur/lucene/codecs/FieldWritable.java
----------------------------------------------------------------------
diff --git a/src/blur-store/src/main/java/org/apache/blur/lucene/codecs/FieldWritable.java
b/src/blur-store/src/main/java/org/apache/blur/lucene/codecs/FieldWritable.java
new file mode 100644
index 0000000..78fc1c8
--- /dev/null
+++ b/src/blur-store/src/main/java/org/apache/blur/lucene/codecs/FieldWritable.java
@@ -0,0 +1,125 @@
+package org.apache.blur.lucene.codecs;
+
+import java.io.DataInput;
+import java.io.DataOutput;
+import java.io.IOException;
+
+import org.apache.hadoop.io.Writable;
+import org.apache.lucene.index.IndexableField;
+
+public class FieldWritable implements Writable {
+
+  private static final int FIELD_TYPE_INT = 1;
+  private static final int FIELD_TYPE_LONG = 2;
+  private static final int FIELD_TYPE_FLOAT = 3;
+  private static final int FIELD_TYPE_DOUBLE = 4;
+  private static final int FIELD_TYPE_BINARY = 5;
+  private int fieldNum;
+  private String fieldName;
+  private Object fieldValue;
+  private int fieldType;
+
+  public FieldWritable() {
+  }
+
+  public FieldWritable(IndexableField field, int fieldNum) {
+    this.fieldNum = fieldNum;
+    populateBlurField(field);
+  }
+
+  private void populateBlurField(IndexableField field) {
+    fieldName = field.name();
+    Number number = field.numericValue();
+    if (number != null) {
+      if (field.numericValue() instanceof Byte || field.numericValue() instanceof Short ||
field.numericValue() instanceof Integer) {
+        fieldType = FIELD_TYPE_INT;
+      } else if (number instanceof Long) {
+        fieldType = FIELD_TYPE_LONG;
+      } else if (number instanceof Float) {
+        fieldType = FIELD_TYPE_FLOAT;
+      } else if (number instanceof Double) {
+        fieldType = FIELD_TYPE_DOUBLE;
+      } else {
+        throw new IllegalArgumentException("Numeric Type not supported" + number.getClass());
+      }
+      fieldValue = field.numericValue();
+    } else if (field.binaryValue() != null) {
+      fieldType = FIELD_TYPE_BINARY;
+      fieldValue = field.binaryValue();
+    } else {
+      fieldValue = field.stringValue();
+      if (fieldValue == null) {
+        throw new IllegalArgumentException("field " + field.name() + " not a valid field
type (Number, Binary, String)");
+      }
+    }
+
+  }
+
+  @Override
+  public void readFields(DataInput in) throws IOException {
+    fieldNum = in.readInt();
+    fieldType = in.readInt();
+    fieldName = in.readLine();
+    switch (fieldType) {
+    case 1: {
+      fieldValue = in.readInt();
+      break;
+    }
+    case 2: {
+      fieldValue = in.readLong();
+      break;
+    }
+    case 3: {
+      fieldValue = in.readFloat();
+      break;
+    }
+    case 4: {
+      fieldValue = in.readDouble();
+      break;
+    }
+    case 5: {
+      byte[] buf = new byte[in.readInt()];
+      fieldValue = buf;
+      in.readFully(buf);
+      break;
+    }
+    default: {
+      throw new IllegalArgumentException("Invalid field Type");
+    }
+    }
+  }
+
+  @Override
+  public void write(DataOutput out) throws IOException {
+    out.writeInt(fieldNum);
+    out.writeInt(fieldType);
+    out.writeBytes(fieldName);
+    switch (fieldType) {
+    case 1: {
+      out.writeInt((Integer) fieldValue);
+      break;
+    }
+    case 2: {
+      out.writeLong((Long) fieldValue);
+      break;
+    }
+    case 3: {
+      out.writeFloat((Float) fieldValue);
+      break;
+    }
+    case 4: {
+      out.writeDouble((Double) fieldValue);
+      break;
+    }
+    case 5: {
+      byte[] bs = (byte[]) fieldValue;
+      out.writeInt(bs.length);
+      out.write(bs);
+      break;
+    }
+    default: {
+      throw new IllegalArgumentException("Invalid field Type");
+    }
+    }
+  }
+}
\ No newline at end of file


Mime
View raw message