incubator-blur-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From amccu...@apache.org
Subject [9/20] First commit of api changes.
Date Sun, 28 Oct 2012 00:20:59 GMT
http://git-wip-us.apache.org/repos/asf/incubator-blur/blob/1e930bbc/src/blur-new-api-prototype/src/main/java/org/apache/blur/lucene/serializer/QUERY_TYPE.java
----------------------------------------------------------------------
diff --git a/src/blur-new-api-prototype/src/main/java/org/apache/blur/lucene/serializer/QUERY_TYPE.java
b/src/blur-new-api-prototype/src/main/java/org/apache/blur/lucene/serializer/QUERY_TYPE.java
new file mode 100644
index 0000000..1b980cc
--- /dev/null
+++ b/src/blur-new-api-prototype/src/main/java/org/apache/blur/lucene/serializer/QUERY_TYPE.java
@@ -0,0 +1,113 @@
+package org.apache.blur.lucene.serializer;
+
+import org.apache.lucene.queries.BoostingQuery;
+import org.apache.lucene.queries.CustomScoreQuery;
+import org.apache.lucene.queries.mlt.MoreLikeThisQuery;
+import org.apache.lucene.sandbox.queries.FuzzyLikeThisQuery;
+import org.apache.lucene.search.AutomatonQuery;
+import org.apache.lucene.search.BooleanQuery;
+import org.apache.lucene.search.ConstantScoreQuery;
+import org.apache.lucene.search.DisjunctionMaxQuery;
+import org.apache.lucene.search.FilteredQuery;
+import org.apache.lucene.search.FuzzyQuery;
+import org.apache.lucene.search.MatchAllDocsQuery;
+import org.apache.lucene.search.MultiPhraseQuery;
+import org.apache.lucene.search.NGramPhraseQuery;
+import org.apache.lucene.search.NumericRangeQuery;
+import org.apache.lucene.search.PhraseQuery;
+import org.apache.lucene.search.PrefixQuery;
+import org.apache.lucene.search.Query;
+import org.apache.lucene.search.RegexpQuery;
+import org.apache.lucene.search.TermQuery;
+import org.apache.lucene.search.TermRangeQuery;
+import org.apache.lucene.search.WildcardQuery;
+
+public enum QUERY_TYPE {
+  BOOLEAN((byte) 0), TERM((byte) 1), FUZZY((byte) 2);
+
+  private final byte type;
+
+  private QUERY_TYPE(byte type) {
+    this.type = type;
+  }
+
+  public byte getType() {
+    return type;
+  }
+
+  public static QUERY_TYPE lookup(byte type) {
+    switch (type) {
+    case 0:
+      return BOOLEAN;
+    case 1:
+      return TERM;
+    case 2:
+      return FUZZY;
+    default:
+      throw new RuntimeException("Type [" + type + "] is not supported");
+    }
+  }
+  
+  public static QUERY_TYPE lookup(Query query) {
+    if (query instanceof BooleanQuery) {
+      return BOOLEAN;
+    } else if (query instanceof TermQuery) {
+      return TERM;
+    } else if (query instanceof FuzzyQuery) {
+      return FUZZY;
+    } else if (query instanceof BoostingQuery) {
+      throw new RuntimeException("no impl");
+    } else if (query instanceof ConstantScoreQuery) {
+      throw new RuntimeException("no impl");
+    } else if (query instanceof CustomScoreQuery) {
+      throw new RuntimeException("no impl");
+    } else if (query instanceof DisjunctionMaxQuery) {
+      throw new RuntimeException("no impl");
+    } else if (query instanceof FilteredQuery) {
+      throw new RuntimeException("no impl");
+    } else if (query instanceof FuzzyLikeThisQuery) {
+      throw new RuntimeException("no impl");
+    } else if (query instanceof MatchAllDocsQuery) {
+      throw new RuntimeException("no impl");
+    } else if (query instanceof MoreLikeThisQuery) {
+      throw new RuntimeException("no impl");
+    } else if (query instanceof MultiPhraseQuery) {
+      throw new RuntimeException("no impl");
+    } else if (query instanceof AutomatonQuery) {
+      throw new RuntimeException("no impl");
+    } else if (query instanceof RegexpQuery) {
+      throw new RuntimeException("no impl");
+    } else if (query instanceof WildcardQuery) {
+      throw new RuntimeException("no impl");
+    } else if (query instanceof FuzzyQuery) {
+      throw new RuntimeException("no impl");
+    } else if (query instanceof NumericRangeQuery) {
+      throw new RuntimeException("no impl");
+    } else if (query instanceof PrefixQuery) {
+      throw new RuntimeException("no impl");
+    } else if (query instanceof RegexpQuery) {
+      throw new RuntimeException("no impl");
+    } else if (query instanceof TermRangeQuery) {
+      throw new RuntimeException("no impl");
+    } else if (query instanceof PhraseQuery) {
+      throw new RuntimeException("no impl");
+    } else if (query instanceof NGramPhraseQuery) {
+      throw new RuntimeException("no impl");
+    } else {
+      throw new RuntimeException("Query" + query + "] is not supported");
+    }
+  }
+  
+  public static AbtractQueryWritable lookupQueryWritable(QUERY_TYPE type) {
+    switch (type) {
+    case BOOLEAN:
+      return new BooleanQueryWritable();
+    case TERM:
+      return new TermQueryWritable();
+    case FUZZY:
+      return new FuzzyQueryWritable();
+    default:
+      throw new RuntimeException("Type [" + type + "] is not supported");
+    }
+  }
+}
\ No newline at end of file

http://git-wip-us.apache.org/repos/asf/incubator-blur/blob/1e930bbc/src/blur-new-api-prototype/src/main/java/org/apache/blur/lucene/serializer/QueryWritable.java
----------------------------------------------------------------------
diff --git a/src/blur-new-api-prototype/src/main/java/org/apache/blur/lucene/serializer/QueryWritable.java
b/src/blur-new-api-prototype/src/main/java/org/apache/blur/lucene/serializer/QueryWritable.java
new file mode 100644
index 0000000..0ed4f60
--- /dev/null
+++ b/src/blur-new-api-prototype/src/main/java/org/apache/blur/lucene/serializer/QueryWritable.java
@@ -0,0 +1,51 @@
+package org.apache.blur.lucene.serializer;
+
+import java.io.DataInput;
+import java.io.DataOutput;
+import java.io.IOException;
+
+import org.apache.lucene.search.Query;
+
+public class QueryWritable extends AbtractQueryWritable {
+
+  private Query query;
+  private QUERY_TYPE lookup;
+
+  public QueryWritable() {
+
+  }
+
+  public QueryWritable(Query query) {
+    this.query = query;
+    this.lookup = QUERY_TYPE.lookup(query);
+  }
+
+  public Query getQuery() {
+    return query;
+  }
+
+  public void setQuery(Query query) {
+    this.query = query;
+    this.lookup = QUERY_TYPE.lookup(query);
+  }
+
+  public QUERY_TYPE getLookup() {
+    return lookup;
+  }
+
+  @Override
+  public void write(DataOutput out) throws IOException {
+    out.write(lookup.getType());
+    AbtractQueryWritable writable = QUERY_TYPE.lookupQueryWritable(lookup);
+    writable.write(out);
+  }
+
+  @Override
+  public void readFields(DataInput in) throws IOException {
+    byte b = in.readByte();
+    lookup = QUERY_TYPE.lookup(b);
+    AbtractQueryWritable writable = QUERY_TYPE.lookupQueryWritable(lookup);
+    writable.readFields(in);
+    query = writable.getQuery();
+  }
+}

http://git-wip-us.apache.org/repos/asf/incubator-blur/blob/1e930bbc/src/blur-new-api-prototype/src/main/java/org/apache/blur/lucene/serializer/SerializerUtil.java
----------------------------------------------------------------------
diff --git a/src/blur-new-api-prototype/src/main/java/org/apache/blur/lucene/serializer/SerializerUtil.java
b/src/blur-new-api-prototype/src/main/java/org/apache/blur/lucene/serializer/SerializerUtil.java
new file mode 100644
index 0000000..ac8e39b
--- /dev/null
+++ b/src/blur-new-api-prototype/src/main/java/org/apache/blur/lucene/serializer/SerializerUtil.java
@@ -0,0 +1,37 @@
+package org.apache.blur.lucene.serializer;
+
+import java.io.DataInput;
+import java.io.DataOutput;
+import java.io.IOException;
+
+import org.apache.lucene.util.BytesRef;
+import org.apache.lucene.util.UnicodeUtil;
+
+public class SerializerUtil {
+
+  public static void writeString(String s, DataOutput out) throws IOException {
+    BytesRef bytes = new BytesRef();
+    UnicodeUtil.UTF16toUTF8(s, 0, s.length(), bytes);
+    writeBytesRef(bytes, out);
+  }
+
+  public static void writeBytesRef(BytesRef bytes, DataOutput out) throws IOException {
+    out.writeInt(bytes.length);
+    out.write(bytes.bytes, bytes.offset, bytes.length);
+  }
+
+  public static String readString(DataInput in) throws IOException {
+    BytesRef bytes = readBytesRef(in);
+    return bytes.utf8ToString();
+  }
+
+  public static BytesRef readBytesRef(DataInput in) throws IOException {
+    int length = in.readInt();
+    BytesRef bytes = new BytesRef(length);
+    in.readFully(bytes.bytes);
+    bytes.offset = 0;
+    bytes.length = length;
+    return bytes;
+  }
+
+}

http://git-wip-us.apache.org/repos/asf/incubator-blur/blob/1e930bbc/src/blur-new-api-prototype/src/main/java/org/apache/blur/lucene/serializer/TermQueryWritable.java
----------------------------------------------------------------------
diff --git a/src/blur-new-api-prototype/src/main/java/org/apache/blur/lucene/serializer/TermQueryWritable.java
b/src/blur-new-api-prototype/src/main/java/org/apache/blur/lucene/serializer/TermQueryWritable.java
new file mode 100644
index 0000000..8a79102
--- /dev/null
+++ b/src/blur-new-api-prototype/src/main/java/org/apache/blur/lucene/serializer/TermQueryWritable.java
@@ -0,0 +1,46 @@
+package org.apache.blur.lucene.serializer;
+
+import java.io.DataInput;
+import java.io.DataOutput;
+import java.io.IOException;
+
+import org.apache.lucene.index.Term;
+import org.apache.lucene.search.TermQuery;
+
+public class TermQueryWritable extends AbtractQueryWritable {
+
+  private TermQuery query;
+
+  public TermQuery getQuery() {
+    return query;
+  }
+
+  public void setQuery(TermQuery query) {
+    this.query = query;
+  }
+
+  public TermQueryWritable() {
+
+  }
+
+  public TermQueryWritable(TermQuery termQuery) {
+    this.query = termQuery;
+  }
+
+  @Override
+  public void write(DataOutput out) throws IOException {
+    out.writeFloat(query.getBoost());
+    Term term = query.getTerm();
+    new TermWritable(term).write(out);
+  }
+
+  @Override
+  public void readFields(DataInput in) throws IOException {
+    float boost = in.readFloat();
+    TermWritable termWritable = new TermWritable();
+    termWritable.readFields(in);
+    query = new TermQuery(termWritable.getTerm());
+    query.setBoost(boost);
+  }
+
+}

http://git-wip-us.apache.org/repos/asf/incubator-blur/blob/1e930bbc/src/blur-new-api-prototype/src/main/java/org/apache/blur/lucene/serializer/TermWritable.java
----------------------------------------------------------------------
diff --git a/src/blur-new-api-prototype/src/main/java/org/apache/blur/lucene/serializer/TermWritable.java
b/src/blur-new-api-prototype/src/main/java/org/apache/blur/lucene/serializer/TermWritable.java
new file mode 100644
index 0000000..32f2790
--- /dev/null
+++ b/src/blur-new-api-prototype/src/main/java/org/apache/blur/lucene/serializer/TermWritable.java
@@ -0,0 +1,46 @@
+package org.apache.blur.lucene.serializer;
+
+import java.io.DataInput;
+import java.io.DataOutput;
+import java.io.IOException;
+
+import org.apache.hadoop.io.Writable;
+import org.apache.lucene.index.Term;
+import org.apache.lucene.util.BytesRef;
+
+public class TermWritable implements Writable {
+
+  private Term term;
+
+  public TermWritable() {
+
+  }
+
+  public TermWritable(Term term) {
+    this.term = term;
+  }
+
+  public Term getTerm() {
+    return term;
+  }
+
+  public void setTerm(Term term) {
+    this.term = term;
+  }
+
+  @Override
+  public void write(DataOutput out) throws IOException {
+    String field = term.field();
+    BytesRef bytes = term.bytes();
+    SerializerUtil.writeString(field, out);
+    SerializerUtil.writeBytesRef(bytes, out);
+  }
+
+  @Override
+  public void readFields(DataInput in) throws IOException {
+    String field = SerializerUtil.readString(in);
+    BytesRef bytes = SerializerUtil.readBytesRef(in);
+    term = new Term(field, bytes);
+  }
+
+}


Mime
View raw message