incubator-blur-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From amccu...@apache.org
Subject [2/46] git commit: Adding a proto lucene query writable object.
Date Tue, 30 Oct 2012 02:53:18 GMT
Adding a proto lucene query writable object.


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

Branch: refs/heads/0.2-dev
Commit: 97b00963cf4eae869bd4c0e5c3b15d46c8a79de9
Parents: f219d52
Author: Aaron McCurry <amccurry@gmail.com>
Authored: Mon Oct 29 22:16:42 2012 -0400
Committer: Aaron McCurry <amccurry@gmail.com>
Committed: Mon Oct 29 22:16:42 2012 -0400

----------------------------------------------------------------------
 .../org/apache/blur/thrift/BlurShardServer.java    |   55 ++++++--
 .../main/java/org/apache/blur/utils/BlurUtil.java  |   23 +++-
 .../lucene/serializer/AbtractQueryWritable.java    |   11 ++
 .../lucene/serializer/BooleanClauseWritable.java   |   71 +++++++++
 .../lucene/serializer/BooleanQueryWritable.java    |   57 ++++++++
 .../blur/lucene/serializer/FuzzyQueryWritable.java |   89 ++++++++++++
 .../blur/lucene/serializer/ProtoSerializer.java    |   63 ++++++++
 .../apache/blur/lucene/serializer/QUERY_TYPE.java  |  113 +++++++++++++++
 .../blur/lucene/serializer/QueryWritable.java      |   51 +++++++
 .../blur/lucene/serializer/SerializerUtil.java     |   37 +++++
 .../blur/lucene/serializer/TermQueryWritable.java  |   46 ++++++
 .../blur/lucene/serializer/TermWritable.java       |   46 ++++++
 12 files changed, 646 insertions(+), 16 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/incubator-blur/blob/97b00963/src/blur-core/src/main/java/org/apache/blur/thrift/BlurShardServer.java
----------------------------------------------------------------------
diff --git a/src/blur-core/src/main/java/org/apache/blur/thrift/BlurShardServer.java b/src/blur-core/src/main/java/org/apache/blur/thrift/BlurShardServer.java
index b808651..727e434 100644
--- a/src/blur-core/src/main/java/org/apache/blur/thrift/BlurShardServer.java
+++ b/src/blur-core/src/main/java/org/apache/blur/thrift/BlurShardServer.java
@@ -62,10 +62,7 @@ import org.apache.blur.thrift.generated.TableStats;
 import org.apache.blur.thrift.generated.Term;
 import org.apache.blur.thrift.generated.TopFieldDocs;
 import org.apache.blur.utils.BlurConstants;
-import org.apache.blur.utils.BlurExecutorCompletionService.Cancel;
 import org.apache.blur.utils.BlurUtil;
-import org.apache.blur.utils.ForkJoin;
-import org.apache.blur.utils.ForkJoin.ParallelReturn;
 import org.apache.blur.utils.QueryCache;
 import org.apache.blur.utils.QueryCacheEntry;
 import org.apache.blur.utils.QueryCacheKey;
@@ -73,6 +70,7 @@ import org.apache.lucene.index.IndexReader;
 import org.apache.lucene.search.Filter;
 import org.apache.lucene.search.IndexSearcher;
 import org.apache.lucene.search.Query;
+import org.apache.lucene.search.ScoreDoc;
 import org.apache.lucene.search.Sort;
 import org.apache.thrift.TException;
 
@@ -411,27 +409,62 @@ public class BlurShardServer extends TableAdmin implements Iface {
       Query query = BlurUtil.getQuery(queryArgs);
       Filter filter = BlurUtil.getFilter(queryArgs);
       Sort sort = BlurUtil.getSort(queryArgs);
+      ScoreDoc after = BlurUtil.convert(queryArgs.getAfter());
+      boolean doDocScores = queryArgs.isDoDocScores();
+      boolean doMaxScore = queryArgs.isDoMaxScore();
+      int numberToFetch = queryArgs.getNumberToFetch();
       for (IndexSearcher searcher : searchersToSearch) {
-        Future<TopFieldDocs> future = _searchExecutor.submit(new SearchCallable(searcher,query));
+        Future<TopFieldDocs> future = _searchExecutor.submit(new SearchCallable(searcher,
after, query, filter, sort, numberToFetch, doDocScores, doMaxScore));
         futures.add(future);
       }
-
-      return null;
+      
+      List<TopFieldDocs> result = new ArrayList<TopFieldDocs>(futures.size());
+      for (Future<TopFieldDocs> future : futures) {
+        result.add(future.get());
+      }
+      return result;
     } catch (Throwable t) {
       LOG.error("Unknown error", t);
       throw new BException(t.getMessage(), t);
     }
   }
 
-  private static class SearchCallable implements Callable<TopFieldDocs> {
-    public SearchCallable(IndexSearcher searcher, Query query) {
-      // TODO Auto-generated constructor stub
+  static class SearchCallable implements Callable<TopFieldDocs> {
+    private final ScoreDoc after;
+    private final Sort sort;
+    private final Filter filter;
+    private final Query query;
+    private final IndexSearcher searcher;
+    private final int count;
+    private final boolean doDocScores;
+    private final boolean doMaxScore;
+
+    SearchCallable(IndexSearcher searcher, ScoreDoc after, Query query, Filter filter, Sort
sort, int count, boolean doDocScores, boolean doMaxScore) {
+      this.after = after;
+      this.searcher = searcher;
+      this.query = query;
+      this.filter = filter;
+      this.sort = sort;
+      this.count = count;
+      this.doDocScores = doDocScores;
+      this.doMaxScore = doMaxScore;
     }
 
     @Override
     public TopFieldDocs call() throws Exception {
-
-      return null;
+      if (after == null) {
+        if (sort == null) {
+          return BlurUtil.convert(searcher.search(query, filter, count));
+        } else {
+          return BlurUtil.convert(searcher.search(query, filter, count, sort, doDocScores,
doMaxScore));
+        }
+      } else {
+        if (sort == null) {
+          return BlurUtil.convert(searcher.searchAfter(after, query, filter, count));
+        } else {
+          return BlurUtil.convert((org.apache.lucene.search.TopFieldDocs) searcher.searchAfter(after,
query, filter, count, sort, doDocScores, doMaxScore));
+        }
+      }
     }
   }
 

http://git-wip-us.apache.org/repos/asf/incubator-blur/blob/97b00963/src/blur-core/src/main/java/org/apache/blur/utils/BlurUtil.java
----------------------------------------------------------------------
diff --git a/src/blur-core/src/main/java/org/apache/blur/utils/BlurUtil.java b/src/blur-core/src/main/java/org/apache/blur/utils/BlurUtil.java
index 616c898..05db8bd 100644
--- a/src/blur-core/src/main/java/org/apache/blur/utils/BlurUtil.java
+++ b/src/blur-core/src/main/java/org/apache/blur/utils/BlurUtil.java
@@ -45,6 +45,7 @@ import java.util.concurrent.atomic.AtomicLongArray;
 
 import org.apache.blur.log.Log;
 import org.apache.blur.log.LogFactory;
+import org.apache.blur.lucene.serializer.QueryWritable;
 import org.apache.blur.manager.clusterstatus.ZookeeperPathConstants;
 import org.apache.blur.manager.results.BlurResultIterable;
 import org.apache.blur.metrics.BlurMetrics;
@@ -74,6 +75,7 @@ import org.apache.hadoop.conf.Configuration;
 import org.apache.hadoop.fs.FileStatus;
 import org.apache.hadoop.fs.FileSystem;
 import org.apache.hadoop.fs.Path;
+import org.apache.hadoop.io.DataInputBuffer;
 import org.apache.lucene.document.Document;
 import org.apache.lucene.index.AtomicReader;
 import org.apache.lucene.index.IndexReader;
@@ -774,18 +776,29 @@ public class BlurUtil {
     throw new RuntimeException("Not supported YET!");
   }
 
-  public static Query getQuery(QueryArgs queryArgs) {
-    // TODO Auto-generated method stub
-    return null;
+  public static Query getQuery(QueryArgs queryArgs) throws IOException {
+    byte[] query = queryArgs.getQuery();
+    DataInputBuffer in = new DataInputBuffer();
+    in.reset(query, 0, query.length);
+    QueryWritable qw = new QueryWritable();
+    qw.readFields(in);
+    return qw.getQuery();
   }
 
   public static Filter getFilter(QueryArgs queryArgs) {
-    // TODO Auto-generated method stub
+    byte[] filter = queryArgs.getFilter();
     return null;
   }
 
   public static Sort getSort(QueryArgs queryArgs) {
-    // TODO Auto-generated method stub
     return null;
   }
+
+  public static TopFieldDocs convert(TopDocs topDocs) {
+    return convert(new org.apache.lucene.search.TopFieldDocs(topDocs.totalHits, topDocs.scoreDocs,
null, Float.NaN));
+  }
+
+  public static org.apache.lucene.search.ScoreDoc convert(org.apache.blur.thrift.generated.ScoreDoc
scoreDoc) {
+    return new org.apache.lucene.search.ScoreDoc(scoreDoc.docLocation.doc, (float) scoreDoc.score,
scoreDoc.docLocation.shardIndex);
+  }
 }

http://git-wip-us.apache.org/repos/asf/incubator-blur/blob/97b00963/src/blur-store/src/main/java/org/apache/blur/lucene/serializer/AbtractQueryWritable.java
----------------------------------------------------------------------
diff --git a/src/blur-store/src/main/java/org/apache/blur/lucene/serializer/AbtractQueryWritable.java
b/src/blur-store/src/main/java/org/apache/blur/lucene/serializer/AbtractQueryWritable.java
new file mode 100644
index 0000000..afd78c8
--- /dev/null
+++ b/src/blur-store/src/main/java/org/apache/blur/lucene/serializer/AbtractQueryWritable.java
@@ -0,0 +1,11 @@
+package org.apache.blur.lucene.serializer;
+
+
+import org.apache.hadoop.io.Writable;
+import org.apache.lucene.search.Query;
+
+public abstract class AbtractQueryWritable implements Writable {
+  
+  public abstract Query getQuery();
+
+}

http://git-wip-us.apache.org/repos/asf/incubator-blur/blob/97b00963/src/blur-store/src/main/java/org/apache/blur/lucene/serializer/BooleanClauseWritable.java
----------------------------------------------------------------------
diff --git a/src/blur-store/src/main/java/org/apache/blur/lucene/serializer/BooleanClauseWritable.java
b/src/blur-store/src/main/java/org/apache/blur/lucene/serializer/BooleanClauseWritable.java
new file mode 100644
index 0000000..54cb9fc
--- /dev/null
+++ b/src/blur-store/src/main/java/org/apache/blur/lucene/serializer/BooleanClauseWritable.java
@@ -0,0 +1,71 @@
+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.search.BooleanClause;
+import org.apache.lucene.search.BooleanClause.Occur;
+
+public class BooleanClauseWritable implements Writable {
+
+  private BooleanClause booleanClause;
+
+  public BooleanClauseWritable() {
+
+  }
+
+  public BooleanClauseWritable(BooleanClause booleanClause) {
+    this.booleanClause = booleanClause;
+  }
+
+  @Override
+  public void write(DataOutput out) throws IOException {
+    Occur occur = booleanClause.getOccur();
+    switch (occur) {
+    case MUST:
+      out.write(0);
+      break;
+    case MUST_NOT:
+      out.write(1);
+      break;
+    case SHOULD:
+      out.write(2);
+      break;
+    default:
+      throw new RuntimeException("Occur [" + occur + "] not supported");
+    }
+    new QueryWritable(booleanClause.getQuery()).write(out);
+  }
+
+  @Override
+  public void readFields(DataInput in) throws IOException {
+    Occur occur = null;
+    byte o = in.readByte();
+    switch (o) {
+    case 0:
+      occur = Occur.MUST;
+      break;
+    case 1:
+      occur = Occur.MUST_NOT;
+      break;
+    case 2:
+      occur = Occur.SHOULD;
+      break;
+    default:
+      throw new RuntimeException("Occur [" + o + "] not supported");
+    }
+    QueryWritable queryWritable = new QueryWritable();
+    queryWritable.readFields(in);
+    booleanClause = new BooleanClause(queryWritable.getQuery(), occur);
+  }
+
+  public BooleanClause getBooleanClause() {
+    return booleanClause;
+  }
+
+  public void setBooleanClause(BooleanClause booleanClause) {
+    this.booleanClause = booleanClause;
+  }
+}

http://git-wip-us.apache.org/repos/asf/incubator-blur/blob/97b00963/src/blur-store/src/main/java/org/apache/blur/lucene/serializer/BooleanQueryWritable.java
----------------------------------------------------------------------
diff --git a/src/blur-store/src/main/java/org/apache/blur/lucene/serializer/BooleanQueryWritable.java
b/src/blur-store/src/main/java/org/apache/blur/lucene/serializer/BooleanQueryWritable.java
new file mode 100644
index 0000000..9cedb91
--- /dev/null
+++ b/src/blur-store/src/main/java/org/apache/blur/lucene/serializer/BooleanQueryWritable.java
@@ -0,0 +1,57 @@
+package org.apache.blur.lucene.serializer;
+
+import java.io.DataInput;
+import java.io.DataOutput;
+import java.io.IOException;
+
+import org.apache.lucene.search.BooleanClause;
+import org.apache.lucene.search.BooleanQuery;
+
+public class BooleanQueryWritable extends AbtractQueryWritable {
+
+  private BooleanQuery query;
+
+  public BooleanQuery getQuery() {
+    return query;
+  }
+
+  public void setQuery(BooleanQuery query) {
+    this.query = query;
+  }
+
+  public BooleanQueryWritable() {
+
+  }
+
+  public BooleanQueryWritable(BooleanQuery booleanQuery) {
+    this.query = booleanQuery;
+  }
+
+  @Override
+  public void write(DataOutput out) throws IOException {
+    out.writeBoolean(query.isCoordDisabled());
+    out.writeFloat(query.getBoost());
+    out.writeInt(query.getMinimumNumberShouldMatch());
+    BooleanClause[] clauses = query.getClauses();
+    out.writeInt(clauses.length);
+    for (int i = 0; i < clauses.length; i++) {
+      BooleanClauseWritable booleanClauseWritable = new BooleanClauseWritable(clauses[i]);
+      booleanClauseWritable.write(out);
+    }
+  }
+
+  @Override
+  public void readFields(DataInput in) throws IOException {
+    query = new BooleanQuery(in.readBoolean());
+    query.setBoost(in.readFloat());
+    query.setMinimumNumberShouldMatch(in.readInt());
+    int length = in.readInt();
+    for (int i = 0; i < length; i++) {
+      BooleanClauseWritable booleanClauseWritable = new BooleanClauseWritable();
+      booleanClauseWritable.readFields(in);
+      query.add(booleanClauseWritable.getBooleanClause());
+    }
+
+  }
+
+}

http://git-wip-us.apache.org/repos/asf/incubator-blur/blob/97b00963/src/blur-store/src/main/java/org/apache/blur/lucene/serializer/FuzzyQueryWritable.java
----------------------------------------------------------------------
diff --git a/src/blur-store/src/main/java/org/apache/blur/lucene/serializer/FuzzyQueryWritable.java
b/src/blur-store/src/main/java/org/apache/blur/lucene/serializer/FuzzyQueryWritable.java
new file mode 100644
index 0000000..174746e
--- /dev/null
+++ b/src/blur-store/src/main/java/org/apache/blur/lucene/serializer/FuzzyQueryWritable.java
@@ -0,0 +1,89 @@
+package org.apache.blur.lucene.serializer;
+
+import java.io.DataInput;
+import java.io.DataOutput;
+import java.io.IOException;
+import java.lang.reflect.Field;
+
+import org.apache.lucene.index.Term;
+import org.apache.lucene.search.FuzzyQuery;
+
+public class FuzzyQueryWritable extends AbtractQueryWritable {
+
+  private FuzzyQuery query;
+  private static Field maxExpansionsField;
+  private static Field transpositionsField;
+
+  static {
+    try {
+      maxExpansionsField = FuzzyQuery.class.getDeclaredField("maxExpansions");
+      transpositionsField = FuzzyQuery.class.getDeclaredField("transpositions");
+      maxExpansionsField.setAccessible(true);
+      transpositionsField.setAccessible(true);
+    } catch (SecurityException e) {
+      throw new RuntimeException(e);
+    } catch (NoSuchFieldException e) {
+      throw new RuntimeException(e);
+    }
+  }
+
+  public FuzzyQueryWritable() {
+
+  }
+
+  public FuzzyQueryWritable(FuzzyQuery query) {
+    this.query = query;
+  }
+
+  public FuzzyQuery getQuery() {
+    return query;
+  }
+
+  public void setQuery(FuzzyQuery query) {
+    this.query = query;
+  }
+
+  @Override
+  public void write(DataOutput out) throws IOException {
+    out.writeFloat(query.getBoost());
+    new TermWritable(query.getTerm()).write(out);
+    out.writeInt(query.getMaxEdits());
+    out.writeInt(query.getPrefixLength());
+    out.writeInt(getMaxExpansions(query));
+    out.writeBoolean(getTranspositions(query));
+  }
+
+  @Override
+  public void readFields(DataInput in) throws IOException {
+    float boost = in.readFloat();
+    TermWritable termWritable = new TermWritable();
+    termWritable.readFields(in);
+    Term term = termWritable.getTerm();
+    int maxEdits = in.readInt();
+    int prefixLength = in.readInt();
+    int maxExpansions = in.readInt();
+    boolean transpositions = in.readBoolean();
+    query = new FuzzyQuery(term, maxEdits, prefixLength, maxExpansions, transpositions);
+    query.setBoost(boost);
+  }
+
+  private static boolean getTranspositions(FuzzyQuery query) {
+    try {
+      return transpositionsField.getBoolean(query);
+    } catch (IllegalArgumentException e) {
+      throw new RuntimeException(e);
+    } catch (IllegalAccessException e) {
+      throw new RuntimeException(e);
+    }
+  }
+
+  private static int getMaxExpansions(FuzzyQuery query) {
+    try {
+      return maxExpansionsField.getInt(query);
+    } catch (IllegalArgumentException e) {
+      throw new RuntimeException(e);
+    } catch (IllegalAccessException e) {
+      throw new RuntimeException(e);
+    }
+  }
+}

http://git-wip-us.apache.org/repos/asf/incubator-blur/blob/97b00963/src/blur-store/src/main/java/org/apache/blur/lucene/serializer/ProtoSerializer.java
----------------------------------------------------------------------
diff --git a/src/blur-store/src/main/java/org/apache/blur/lucene/serializer/ProtoSerializer.java
b/src/blur-store/src/main/java/org/apache/blur/lucene/serializer/ProtoSerializer.java
new file mode 100644
index 0000000..76b0aec
--- /dev/null
+++ b/src/blur-store/src/main/java/org/apache/blur/lucene/serializer/ProtoSerializer.java
@@ -0,0 +1,63 @@
+package org.apache.blur.lucene.serializer;
+
+import java.io.IOException;
+
+import org.apache.hadoop.io.DataInputBuffer;
+import org.apache.hadoop.io.DataOutputBuffer;
+import org.apache.lucene.analysis.standard.StandardAnalyzer;
+import org.apache.lucene.queryparser.classic.ParseException;
+import org.apache.lucene.queryparser.classic.QueryParser;
+import org.apache.lucene.search.Query;
+import org.apache.lucene.util.Version;
+
+public class ProtoSerializer {
+
+  public static void main(String[] args) throws ParseException, IOException {
+
+    QueryParser parser = new QueryParser(Version.LUCENE_40, "", new StandardAnalyzer(Version.LUCENE_40));
+
+    Query query = parser.parse("a:v1 b:v2 c:v3~");
+
+    QueryWritable queryWritable = new QueryWritable(query);
+    DataOutputBuffer buffer = new DataOutputBuffer();
+    queryWritable.write(buffer);
+    buffer.close();
+
+    System.out.println(new String(buffer.getData(), 0, buffer.getLength()));
+
+    QueryWritable qw = new QueryWritable();
+
+    DataInputBuffer in = new DataInputBuffer();
+    in.reset(buffer.getData(), 0, buffer.getLength());
+    qw.readFields(in);
+
+    System.out.println(qw.getQuery());
+
+    while (true) {
+      run(query);
+    }
+  }
+
+  private static void run(Query query) throws IOException {
+
+    DataOutputBuffer buffer = new DataOutputBuffer();
+    DataInputBuffer in = new DataInputBuffer();
+    QueryWritable outQw = new QueryWritable();
+    QueryWritable inQw = new QueryWritable();
+
+    long s = System.nanoTime();
+    int count = 1000000;
+    for (int i = 0; i < count; i++) {
+      outQw.setQuery(query);
+      outQw.write(buffer);
+
+      in.reset(buffer.getData(), 0, buffer.getLength());
+      inQw.readFields(in);
+
+      buffer.reset();
+    }
+    long e = System.nanoTime();
+    System.out.println((e - s) / 1000000.0 / (double) count);
+    // System.out.println((e - s) / (double) count);
+  }
+}

http://git-wip-us.apache.org/repos/asf/incubator-blur/blob/97b00963/src/blur-store/src/main/java/org/apache/blur/lucene/serializer/QUERY_TYPE.java
----------------------------------------------------------------------
diff --git a/src/blur-store/src/main/java/org/apache/blur/lucene/serializer/QUERY_TYPE.java
b/src/blur-store/src/main/java/org/apache/blur/lucene/serializer/QUERY_TYPE.java
new file mode 100644
index 0000000..1b980cc
--- /dev/null
+++ b/src/blur-store/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/97b00963/src/blur-store/src/main/java/org/apache/blur/lucene/serializer/QueryWritable.java
----------------------------------------------------------------------
diff --git a/src/blur-store/src/main/java/org/apache/blur/lucene/serializer/QueryWritable.java
b/src/blur-store/src/main/java/org/apache/blur/lucene/serializer/QueryWritable.java
new file mode 100644
index 0000000..0ed4f60
--- /dev/null
+++ b/src/blur-store/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/97b00963/src/blur-store/src/main/java/org/apache/blur/lucene/serializer/SerializerUtil.java
----------------------------------------------------------------------
diff --git a/src/blur-store/src/main/java/org/apache/blur/lucene/serializer/SerializerUtil.java
b/src/blur-store/src/main/java/org/apache/blur/lucene/serializer/SerializerUtil.java
new file mode 100644
index 0000000..ac8e39b
--- /dev/null
+++ b/src/blur-store/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/97b00963/src/blur-store/src/main/java/org/apache/blur/lucene/serializer/TermQueryWritable.java
----------------------------------------------------------------------
diff --git a/src/blur-store/src/main/java/org/apache/blur/lucene/serializer/TermQueryWritable.java
b/src/blur-store/src/main/java/org/apache/blur/lucene/serializer/TermQueryWritable.java
new file mode 100644
index 0000000..8a79102
--- /dev/null
+++ b/src/blur-store/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/97b00963/src/blur-store/src/main/java/org/apache/blur/lucene/serializer/TermWritable.java
----------------------------------------------------------------------
diff --git a/src/blur-store/src/main/java/org/apache/blur/lucene/serializer/TermWritable.java
b/src/blur-store/src/main/java/org/apache/blur/lucene/serializer/TermWritable.java
new file mode 100644
index 0000000..32f2790
--- /dev/null
+++ b/src/blur-store/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