incubator-blur-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From amccu...@apache.org
Subject [2/3] Created a new project for all things lucene query related. Moved some query code from blur-core and the writable implementations from blur-store.
Date Sun, 10 Feb 2013 15:07:05 GMT
http://git-wip-us.apache.org/repos/asf/incubator-blur/blob/0f78613d/src/blur-query/src/main/java/org/apache/blur/lucene/search/SuperQuery.java
----------------------------------------------------------------------
diff --git a/src/blur-query/src/main/java/org/apache/blur/lucene/search/SuperQuery.java b/src/blur-query/src/main/java/org/apache/blur/lucene/search/SuperQuery.java
new file mode 100644
index 0000000..a503d77
--- /dev/null
+++ b/src/blur-query/src/main/java/org/apache/blur/lucene/search/SuperQuery.java
@@ -0,0 +1,279 @@
+package org.apache.blur.lucene.search;
+
+/**
+ * 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.lucene.index.AtomicReaderContext;
+import org.apache.lucene.index.IndexReader;
+import org.apache.lucene.index.Term;
+import org.apache.lucene.search.Explanation;
+import org.apache.lucene.search.IndexSearcher;
+import org.apache.lucene.search.Query;
+import org.apache.lucene.search.Scorer;
+import org.apache.lucene.search.Weight;
+import org.apache.lucene.util.Bits;
+import org.apache.lucene.util.OpenBitSet;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+public class SuperQuery extends AbstractWrapperQuery {
+
+  private final ScoreType scoreType;
+  private final Term primeDocTerm;
+
+  public SuperQuery(Query query, ScoreType scoreType, Term primeDocTerm) {
+    super(query, false);
+    this.scoreType = scoreType;
+    this.primeDocTerm = primeDocTerm;
+  }
+
+  public SuperQuery(Query query, ScoreType scoreType, Term primeDocTerm, boolean rewritten) {
+    super(query, rewritten);
+    this.scoreType = scoreType;
+    this.primeDocTerm = primeDocTerm;
+  }
+
+  public Query clone() {
+    return new SuperQuery((Query) _query.clone(), scoreType, primeDocTerm, _rewritten);
+  }
+
+  public Weight createWeight(IndexSearcher searcher) throws IOException {
+    Weight weight = _query.createWeight(searcher);
+    return new SuperWeight(weight, _query.toString(), this, scoreType, primeDocTerm);
+  }
+
+  public Query rewrite(IndexReader reader) throws IOException {
+    if (_rewritten) {
+      return this;
+    }
+    return new SuperQuery(_query.rewrite(reader), scoreType, primeDocTerm, true);
+  }
+
+  public String toString() {
+    return "super:{" + _query.toString() + "}";
+  }
+
+  public String toString(String field) {
+    return "super:{" + _query.toString(field) + "}";
+  }
+
+  public static class SuperWeight extends Weight {
+
+    private final Weight weight;
+    private final String originalQueryStr;
+    private final Query query;
+    private final ScoreType scoreType;
+    private final Term primeDocTerm;
+
+    public SuperWeight(Weight weight, String originalQueryStr, Query query, ScoreType scoreType, Term primeDocTerm) {
+      this.weight = weight;
+      this.originalQueryStr = originalQueryStr;
+      this.query = query;
+      this.scoreType = scoreType;
+      this.primeDocTerm = primeDocTerm;
+    }
+
+    @Override
+    public Query getQuery() {
+      return query;
+    }
+
+    @Override
+    public Explanation explain(AtomicReaderContext context, int doc) throws IOException {
+      throw new RuntimeException("not supported");
+    }
+
+    /*
+     * This method needs to implement in some other way Weight doesn't provide
+     * this method at all
+     * 
+     * @Override public float getValue() { return weight.getValue(); }
+     */
+
+    @Override
+    public void normalize(float norm, float topLevelBoost) {
+      weight.normalize(norm, topLevelBoost);
+    }
+
+    @Override
+    public Scorer scorer(AtomicReaderContext context, boolean scoreDocsInOrder, boolean topScorer, Bits acceptDocs) throws IOException {
+      Scorer scorer = weight.scorer(context, true, topScorer, acceptDocs);
+      if (scorer == null) {
+        return null;
+      }
+      OpenBitSet primeDocBitSet = PrimeDocCache.getPrimeDocBitSet(primeDocTerm, context.reader());
+      return new SuperScorer(scorer, primeDocBitSet, originalQueryStr, scoreType);
+    }
+
+    @Override
+    public float getValueForNormalization() throws IOException {
+      return weight.getValueForNormalization();
+    }
+
+  }
+
+  @SuppressWarnings("unused")
+  public static class SuperScorer extends Scorer {
+
+    private static final Logger LOG = LoggerFactory.getLogger(SuperScorer.class);
+
+    private static final String DOC_ID = "docId";
+    private static final String NEXT_DOC = "nextDoc";
+    private static final String ADVANCE = "advance";
+    private static final double SUPER_POWER_CONSTANT = 2;
+    private static final boolean debug = false;
+    private final Scorer scorer;
+    private final OpenBitSet bitSet;
+    private final String originalQueryStr;
+    private final ScoreType scoreType;
+    private int nextPrimeDoc;
+    private int primeDoc = -1;
+    private int numDocs;
+    private float bestScore;
+    private float aggregateScore;
+    private int hitsInEntity;
+
+    protected SuperScorer(Scorer scorer, OpenBitSet bitSet, String originalQueryStr, ScoreType scoreType) {
+      super(scorer.getWeight());
+      this.scorer = scorer;
+      this.bitSet = bitSet;
+      this.originalQueryStr = originalQueryStr;
+      this.scoreType = scoreType;
+    }
+
+    @Override
+    public float score() throws IOException {
+      switch (scoreType) {
+      case AGGREGATE:
+        return aggregateScore;
+      case BEST:
+        return bestScore;
+      case CONSTANT:
+        return 1;
+      case SUPER:
+        double log = Math.log10(aggregateScore) + 1.0;
+        double avg = aggregateScore / hitsInEntity;
+        double pow = Math.pow(avg, SUPER_POWER_CONSTANT);
+        return (float) Math.pow(log + pow, 1.0 / SUPER_POWER_CONSTANT);
+      }
+      throw new RuntimeException("Unknown Score type[" + scoreType + "]");
+    }
+
+    @Override
+    public int docID() {
+      return print(DOC_ID, primeDoc);
+    }
+
+    @Override
+    public int advance(int target) throws IOException {
+      if (target == NO_MORE_DOCS) {
+        return print(ADVANCE, primeDoc = scorer.advance(NO_MORE_DOCS));
+      }
+      int doc = scorer.docID();
+      int odoc = doc;
+      if (isScorerExhausted(doc)) {
+        return print(ADVANCE, primeDoc = doc);
+      }
+      if (target > doc || doc == -1) {
+        doc = scorer.advance(target);
+        if (isScorerExhausted(doc)) {
+          return print(ADVANCE, primeDoc = doc);
+        }
+      } else if (isScorerExhausted(doc)) {
+        return print(ADVANCE, primeDoc == -1 ? primeDoc = doc : primeDoc);
+      }
+      return print(ADVANCE, gatherAllHitsSuperDoc(doc));
+    }
+
+    private int print(String message, int i) {
+      if (debug) {
+        System.out.println(message + " [" + i + "] " + originalQueryStr);
+      }
+      return i;
+    }
+
+    @Override
+    public int nextDoc() throws IOException {
+      int doc = scorer.docID();
+      int odoc = doc;
+      if (isScorerExhausted(doc)) {
+        return primeDoc = doc;
+      }
+      if (doc == -1) {
+        doc = scorer.nextDoc();
+        if (isScorerExhausted(doc)) {
+          return print(NEXT_DOC, primeDoc = doc);
+        }
+      } else if (isScorerExhausted(doc)) {
+        return print(NEXT_DOC, primeDoc == -1 ? primeDoc = doc : primeDoc);
+      }
+
+      return print(NEXT_DOC, gatherAllHitsSuperDoc(doc));
+    }
+
+    private int gatherAllHitsSuperDoc(int doc) throws IOException {
+      reset();
+      primeDoc = getPrimeDoc(doc);
+      nextPrimeDoc = getNextPrimeDoc(doc);
+      numDocs = nextPrimeDoc - primeDoc;
+      float currentDocScore = 0;
+      while (doc < nextPrimeDoc) {
+        currentDocScore = scorer.score();
+        aggregateScore += currentDocScore;
+        if (currentDocScore > bestScore) {
+          bestScore = currentDocScore;
+        }
+        hitsInEntity++;
+        doc = scorer.nextDoc();
+      }
+      return primeDoc;
+    }
+
+    private void reset() {
+      numDocs = 0;
+      bestScore = 0;
+      aggregateScore = 0;
+      hitsInEntity = 0;
+    }
+
+    private int getNextPrimeDoc(int doc) {
+      int nextSetBit = bitSet.nextSetBit(doc + 1);
+      return nextSetBit == -1 ? NO_MORE_DOCS : nextSetBit;
+    }
+
+    private int getPrimeDoc(int doc) {
+      if (bitSet.fastGet(doc)) {
+        return doc;
+      }
+      return bitSet.prevSetBit(doc);
+    }
+
+    private boolean isScorerExhausted(int doc) {
+      return doc == NO_MORE_DOCS ? true : false;
+    }
+
+    @Override
+    public float freq() throws IOException {
+      return scorer.freq();
+    }
+  }
+
+  public Query getQuery() {
+    return _query;
+  }
+}

http://git-wip-us.apache.org/repos/asf/incubator-blur/blob/0f78613d/src/blur-query/src/main/java/org/apache/blur/lucene/serializer/AbtractQueryWritable.java
----------------------------------------------------------------------
diff --git a/src/blur-query/src/main/java/org/apache/blur/lucene/serializer/AbtractQueryWritable.java b/src/blur-query/src/main/java/org/apache/blur/lucene/serializer/AbtractQueryWritable.java
new file mode 100644
index 0000000..1e59fba
--- /dev/null
+++ b/src/blur-query/src/main/java/org/apache/blur/lucene/serializer/AbtractQueryWritable.java
@@ -0,0 +1,28 @@
+package org.apache.blur.lucene.serializer;
+
+/**
+ * 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 org.apache.hadoop.io.Writable;
+import org.apache.lucene.search.Query;
+
+public abstract class AbtractQueryWritable<T extends Query> implements Writable {
+
+  public abstract Query getQuery();
+
+  public abstract void setQuery(T query);
+
+}

http://git-wip-us.apache.org/repos/asf/incubator-blur/blob/0f78613d/src/blur-query/src/main/java/org/apache/blur/lucene/serializer/BooleanClauseWritable.java
----------------------------------------------------------------------
diff --git a/src/blur-query/src/main/java/org/apache/blur/lucene/serializer/BooleanClauseWritable.java b/src/blur-query/src/main/java/org/apache/blur/lucene/serializer/BooleanClauseWritable.java
new file mode 100644
index 0000000..e96a19b
--- /dev/null
+++ b/src/blur-query/src/main/java/org/apache/blur/lucene/serializer/BooleanClauseWritable.java
@@ -0,0 +1,87 @@
+package org.apache.blur.lucene.serializer;
+
+/**
+ * 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.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/0f78613d/src/blur-query/src/main/java/org/apache/blur/lucene/serializer/BooleanQueryWritable.java
----------------------------------------------------------------------
diff --git a/src/blur-query/src/main/java/org/apache/blur/lucene/serializer/BooleanQueryWritable.java b/src/blur-query/src/main/java/org/apache/blur/lucene/serializer/BooleanQueryWritable.java
new file mode 100644
index 0000000..a7da00b
--- /dev/null
+++ b/src/blur-query/src/main/java/org/apache/blur/lucene/serializer/BooleanQueryWritable.java
@@ -0,0 +1,73 @@
+package org.apache.blur.lucene.serializer;
+
+/**
+ * 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.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<BooleanQuery> {
+
+  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/0f78613d/src/blur-query/src/main/java/org/apache/blur/lucene/serializer/FuzzyQueryWritable.java
----------------------------------------------------------------------
diff --git a/src/blur-query/src/main/java/org/apache/blur/lucene/serializer/FuzzyQueryWritable.java b/src/blur-query/src/main/java/org/apache/blur/lucene/serializer/FuzzyQueryWritable.java
new file mode 100644
index 0000000..d285f5b
--- /dev/null
+++ b/src/blur-query/src/main/java/org/apache/blur/lucene/serializer/FuzzyQueryWritable.java
@@ -0,0 +1,105 @@
+package org.apache.blur.lucene.serializer;
+
+/**
+ * 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.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<FuzzyQuery> {
+
+  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/0f78613d/src/blur-query/src/main/java/org/apache/blur/lucene/serializer/MatchAllDocsQueryWritable.java
----------------------------------------------------------------------
diff --git a/src/blur-query/src/main/java/org/apache/blur/lucene/serializer/MatchAllDocsQueryWritable.java b/src/blur-query/src/main/java/org/apache/blur/lucene/serializer/MatchAllDocsQueryWritable.java
new file mode 100644
index 0000000..88e988b
--- /dev/null
+++ b/src/blur-query/src/main/java/org/apache/blur/lucene/serializer/MatchAllDocsQueryWritable.java
@@ -0,0 +1,36 @@
+package org.apache.blur.lucene.serializer;
+
+import java.io.DataInput;
+import java.io.DataOutput;
+import java.io.IOException;
+
+import org.apache.lucene.search.MatchAllDocsQuery;
+import org.apache.lucene.search.Query;
+
+public class MatchAllDocsQueryWritable extends AbtractQueryWritable<MatchAllDocsQuery> {
+
+  private MatchAllDocsQuery query;
+
+  @Override
+  public void write(DataOutput out) throws IOException {
+    out.writeFloat(query.getBoost());
+  }
+
+  @Override
+  public void readFields(DataInput in) throws IOException {
+    float boost = in.readFloat();
+    query = new MatchAllDocsQuery();
+    query.setBoost(boost);
+  }
+
+  @Override
+  public Query getQuery() {
+    return query;
+  }
+
+  @Override
+  public void setQuery(MatchAllDocsQuery query) {
+    this.query = query;
+  }
+
+}

http://git-wip-us.apache.org/repos/asf/incubator-blur/blob/0f78613d/src/blur-query/src/main/java/org/apache/blur/lucene/serializer/ProtoSerializer.java
----------------------------------------------------------------------
diff --git a/src/blur-query/src/main/java/org/apache/blur/lucene/serializer/ProtoSerializer.java b/src/blur-query/src/main/java/org/apache/blur/lucene/serializer/ProtoSerializer.java
new file mode 100644
index 0000000..0aada55
--- /dev/null
+++ b/src/blur-query/src/main/java/org/apache/blur/lucene/serializer/ProtoSerializer.java
@@ -0,0 +1,79 @@
+package org.apache.blur.lucene.serializer;
+
+/**
+ * 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.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/0f78613d/src/blur-query/src/main/java/org/apache/blur/lucene/serializer/QUERY_TYPE.java
----------------------------------------------------------------------
diff --git a/src/blur-query/src/main/java/org/apache/blur/lucene/serializer/QUERY_TYPE.java b/src/blur-query/src/main/java/org/apache/blur/lucene/serializer/QUERY_TYPE.java
new file mode 100644
index 0000000..495261a
--- /dev/null
+++ b/src/blur-query/src/main/java/org/apache/blur/lucene/serializer/QUERY_TYPE.java
@@ -0,0 +1,133 @@
+package org.apache.blur.lucene.serializer;
+
+/**
+ * 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 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), MATCH_ALL_DOCS((byte) 3);
+
+  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;
+    case 3:
+      return MATCH_ALL_DOCS;
+    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) {
+      return MATCH_ALL_DOCS;
+    } 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();
+    case MATCH_ALL_DOCS:
+      return new MatchAllDocsQueryWritable();
+    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/0f78613d/src/blur-query/src/main/java/org/apache/blur/lucene/serializer/QueryWritable.java
----------------------------------------------------------------------
diff --git a/src/blur-query/src/main/java/org/apache/blur/lucene/serializer/QueryWritable.java b/src/blur-query/src/main/java/org/apache/blur/lucene/serializer/QueryWritable.java
new file mode 100644
index 0000000..2a1fa93
--- /dev/null
+++ b/src/blur-query/src/main/java/org/apache/blur/lucene/serializer/QueryWritable.java
@@ -0,0 +1,70 @@
+package org.apache.blur.lucene.serializer;
+
+/**
+ * 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.DataInput;
+import java.io.DataOutput;
+import java.io.IOException;
+
+import org.apache.lucene.search.Query;
+
+public class QueryWritable extends AbtractQueryWritable<Query> {
+
+  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;
+  }
+
+  @SuppressWarnings("unchecked")
+  @Override
+  public void write(DataOutput out) throws IOException {
+    out.write(lookup.getType());
+    AbtractQueryWritable<Query> writable = (AbtractQueryWritable<Query>) QUERY_TYPE.lookupQueryWritable(lookup);
+    writable.setQuery(query);
+    writable.write(out);
+  }
+
+  @SuppressWarnings("unchecked")
+  @Override
+  public void readFields(DataInput in) throws IOException {
+    byte b = in.readByte();
+    lookup = QUERY_TYPE.lookup(b);
+    AbtractQueryWritable<Query> writable = (AbtractQueryWritable<Query>) QUERY_TYPE.lookupQueryWritable(lookup);
+    writable.readFields(in);
+    query = writable.getQuery();
+  }
+}

http://git-wip-us.apache.org/repos/asf/incubator-blur/blob/0f78613d/src/blur-query/src/main/java/org/apache/blur/lucene/serializer/SerializerUtil.java
----------------------------------------------------------------------
diff --git a/src/blur-query/src/main/java/org/apache/blur/lucene/serializer/SerializerUtil.java b/src/blur-query/src/main/java/org/apache/blur/lucene/serializer/SerializerUtil.java
new file mode 100644
index 0000000..a43ac0e
--- /dev/null
+++ b/src/blur-query/src/main/java/org/apache/blur/lucene/serializer/SerializerUtil.java
@@ -0,0 +1,53 @@
+package org.apache.blur.lucene.serializer;
+
+/**
+ * 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.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/0f78613d/src/blur-query/src/main/java/org/apache/blur/lucene/serializer/TermQueryWritable.java
----------------------------------------------------------------------
diff --git a/src/blur-query/src/main/java/org/apache/blur/lucene/serializer/TermQueryWritable.java b/src/blur-query/src/main/java/org/apache/blur/lucene/serializer/TermQueryWritable.java
new file mode 100644
index 0000000..4173ac2
--- /dev/null
+++ b/src/blur-query/src/main/java/org/apache/blur/lucene/serializer/TermQueryWritable.java
@@ -0,0 +1,62 @@
+package org.apache.blur.lucene.serializer;
+
+/**
+ * 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.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<TermQuery> {
+
+  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/0f78613d/src/blur-query/src/main/java/org/apache/blur/lucene/serializer/TermWritable.java
----------------------------------------------------------------------
diff --git a/src/blur-query/src/main/java/org/apache/blur/lucene/serializer/TermWritable.java b/src/blur-query/src/main/java/org/apache/blur/lucene/serializer/TermWritable.java
new file mode 100644
index 0000000..9c008b5
--- /dev/null
+++ b/src/blur-query/src/main/java/org/apache/blur/lucene/serializer/TermWritable.java
@@ -0,0 +1,62 @@
+package org.apache.blur.lucene.serializer;
+
+/**
+ * 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.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);
+  }
+
+}

http://git-wip-us.apache.org/repos/asf/incubator-blur/blob/0f78613d/src/blur-query/src/test/java/org/apache/blur/lucene/search/FacetQueryTest.java
----------------------------------------------------------------------
diff --git a/src/blur-query/src/test/java/org/apache/blur/lucene/search/FacetQueryTest.java b/src/blur-query/src/test/java/org/apache/blur/lucene/search/FacetQueryTest.java
new file mode 100644
index 0000000..fadd0d5
--- /dev/null
+++ b/src/blur-query/src/test/java/org/apache/blur/lucene/search/FacetQueryTest.java
@@ -0,0 +1,105 @@
+package org.apache.blur.lucene.search;
+
+/**
+ * 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 java.util.concurrent.atomic.AtomicLongArray;
+
+import org.apache.lucene.analysis.core.KeywordAnalyzer;
+import org.apache.lucene.document.Document;
+import org.apache.lucene.document.Field;
+import org.apache.lucene.document.FieldType;
+import org.apache.lucene.index.CorruptIndexException;
+import org.apache.lucene.index.DirectoryReader;
+import org.apache.lucene.index.IndexReader;
+import org.apache.lucene.index.IndexWriter;
+import org.apache.lucene.index.IndexWriterConfig;
+import org.apache.lucene.index.Term;
+import org.apache.lucene.search.BooleanClause.Occur;
+import org.apache.lucene.search.BooleanQuery;
+import org.apache.lucene.search.IndexSearcher;
+import org.apache.lucene.search.Query;
+import org.apache.lucene.search.TermQuery;
+import org.apache.lucene.store.LockObtainFailedException;
+import org.apache.lucene.store.RAMDirectory;
+import static org.apache.blur.lucene.LuceneVersionConstant.LUCENE_VERSION;
+import org.junit.After;
+import org.junit.Before;
+import org.junit.Test;
+
+
+public class FacetQueryTest {
+
+  private IndexReader reader;
+
+  @Before
+  public void setup() throws CorruptIndexException, LockObtainFailedException, IOException {
+    reader = createIndex();
+  }
+
+  @After
+  public void tearDown() {
+
+  }
+
+  @Test
+  public void testFacetQueryNoSuper() throws IOException {
+    BooleanQuery bq = new BooleanQuery();
+    bq.add(new TermQuery(new Term("f1", "value")), Occur.SHOULD);
+    bq.add(new TermQuery(new Term("f2", "v3")), Occur.SHOULD);
+
+    Query f1 = new TermQuery(new Term("f2", "v4"));
+
+    BooleanQuery f2 = new BooleanQuery();
+    f2.add(new TermQuery(new Term("f1", "value")), Occur.MUST);
+    f2.add(new TermQuery(new Term("f2", "v3")), Occur.MUST);
+
+    Query[] facets = new Query[] { f1, f2 };
+
+    AtomicLongArray counts = new AtomicLongArray(facets.length);
+    FacetQuery facetQuery = new FacetQuery(bq, facets, counts);
+
+    IndexSearcher indexSearcher = new IndexSearcher(reader);
+    indexSearcher.search(facetQuery, 10);
+
+    //@TODO add actual assertion
+    for (int i = 0; i < counts.length(); i++) {
+      System.out.println(counts.get(i));
+    }
+  }
+
+  private IndexReader createIndex() throws CorruptIndexException, LockObtainFailedException, IOException {
+    RAMDirectory directory = new RAMDirectory();
+    IndexWriterConfig conf = new IndexWriterConfig(LUCENE_VERSION, new KeywordAnalyzer());
+    IndexWriter writer = new IndexWriter(directory, conf);
+    FieldType fieldType = new FieldType();
+    fieldType.setStored(true);
+    fieldType.setIndexed(true);
+    fieldType.setOmitNorms(true);
+    for (int i = 0; i < 10; i++) {
+      Document document = new Document();
+      
+      document.add(new Field("f1", "value", fieldType));
+      document.add(new Field("f2", "v" + i, fieldType));
+      writer.addDocument(document);
+    }
+    writer.close();
+    return DirectoryReader.open(directory);
+  }
+
+}

http://git-wip-us.apache.org/repos/asf/incubator-blur/blob/0f78613d/src/blur-query/src/test/java/org/apache/blur/lucene/serializer/QueryWritableTest.java
----------------------------------------------------------------------
diff --git a/src/blur-query/src/test/java/org/apache/blur/lucene/serializer/QueryWritableTest.java b/src/blur-query/src/test/java/org/apache/blur/lucene/serializer/QueryWritableTest.java
new file mode 100644
index 0000000..2b1e87c
--- /dev/null
+++ b/src/blur-query/src/test/java/org/apache/blur/lucene/serializer/QueryWritableTest.java
@@ -0,0 +1,38 @@
+package org.apache.blur.lucene.serializer;
+
+import static org.junit.Assert.assertEquals;
+
+import java.io.IOException;
+
+import org.apache.hadoop.io.DataInputBuffer;
+import org.apache.hadoop.io.DataOutputBuffer;
+import org.apache.lucene.index.Term;
+import org.apache.lucene.search.Query;
+import org.apache.lucene.search.TermQuery;
+import org.junit.Test;
+
+public class QueryWritableTest {
+  
+  @Test
+  public void testTermQuery() throws IOException {
+    TermQuery query = new TermQuery(new Term("field","value"));
+    QueryWritable queryWritable = new QueryWritable();
+    queryWritable.setQuery(query);
+    DataOutputBuffer out = new DataOutputBuffer();
+    queryWritable.write(out);
+    byte[] data = out.getData();
+    int length = out.getLength();
+    
+    DataInputBuffer in = new DataInputBuffer();
+    in.reset(data, length);
+    
+    QueryWritable newQueryWritable = new QueryWritable();
+    newQueryWritable.readFields(in);
+    
+    Query termQuery = newQueryWritable.getQuery();
+    
+    assertEquals(query,termQuery);
+    
+  }
+
+}

http://git-wip-us.apache.org/repos/asf/incubator-blur/blob/0f78613d/src/blur-query/src/test/java/org/apache/blur/search/RandomSuperQueryTest.java
----------------------------------------------------------------------
diff --git a/src/blur-query/src/test/java/org/apache/blur/search/RandomSuperQueryTest.java b/src/blur-query/src/test/java/org/apache/blur/search/RandomSuperQueryTest.java
new file mode 100644
index 0000000..bfb5952
--- /dev/null
+++ b/src/blur-query/src/test/java/org/apache/blur/search/RandomSuperQueryTest.java
@@ -0,0 +1,152 @@
+package org.apache.blur.search;
+
+/**
+ * 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 static junit.framework.Assert.assertTrue;
+import static org.apache.blur.lucene.LuceneVersionConstant.LUCENE_VERSION;
+
+import java.io.IOException;
+import java.util.ArrayList;
+import java.util.Collection;
+import java.util.HashMap;
+import java.util.HashSet;
+import java.util.List;
+import java.util.Map;
+import java.util.Random;
+
+import org.apache.blur.lucene.search.ScoreType;
+import org.apache.blur.lucene.search.SuperQuery;
+import org.apache.lucene.analysis.standard.StandardAnalyzer;
+import org.apache.lucene.document.Document;
+import org.apache.lucene.document.Field.Store;
+import org.apache.lucene.document.StringField;
+import org.apache.lucene.index.CorruptIndexException;
+import org.apache.lucene.index.DirectoryReader;
+import org.apache.lucene.index.IndexReader;
+import org.apache.lucene.index.IndexWriter;
+import org.apache.lucene.index.IndexWriterConfig;
+import org.apache.lucene.index.Term;
+import org.apache.lucene.queryparser.classic.ParseException;
+import org.apache.lucene.search.BooleanClause.Occur;
+import org.apache.lucene.search.BooleanQuery;
+import org.apache.lucene.search.IndexSearcher;
+import org.apache.lucene.search.Query;
+import org.apache.lucene.search.TermQuery;
+import org.apache.lucene.search.TopDocs;
+import org.apache.lucene.store.Directory;
+import org.apache.lucene.store.LockObtainFailedException;
+import org.apache.lucene.store.RAMDirectory;
+import org.junit.Test;
+
+public class RandomSuperQueryTest {
+
+  private static final int MOD_COLS_USED_FOR_SKIPPING = 3;
+  private static final int MAX_NUM_OF_DOCS = 10000;// 10000
+  private static final int MIN_NUM_COL_FAM = 3;// 3
+  private static final int MAX_NUM_COL_FAM = 20;// 20
+  private static final int MAX_NUM_DOCS_PER_COL_FAM = 25;// 25
+  private static final int MAX_NUM_COLS = 21;// 21
+  private static final int MIN_NUM_COLS = 3;// 3
+  private static final int MAX_NUM_OF_WORDS = 1000;
+  private static final int MOD_USED_FOR_SAMPLING = 7;//
+  private static final String PRIME_DOC = "_p_";
+  private static final String PRIME_DOC_VALUE = "_true_";
+
+  private Random seedGen = new Random(1);
+
+  @Test
+  public void testRandomSuperQuery() throws CorruptIndexException, IOException, InterruptedException, ParseException {
+    long seed = seedGen.nextLong();
+
+    Random random = new Random(seed);
+    Collection<Query> sampler = new HashSet<Query>();
+    System.out.print("Creating index... ");
+    System.out.flush();
+    Directory directory = createIndex(random, sampler);
+    IndexReader reader = DirectoryReader.open(directory);
+    System.out.print("Running searches [" + sampler.size() + "]... ");
+    System.out.flush();
+    assertTrue(!sampler.isEmpty());
+    IndexSearcher searcher = new IndexSearcher(reader);
+    long s = System.currentTimeMillis();
+    for (Query query : sampler) {
+      TopDocs topDocs = searcher.search(query, 10);
+      assertTrue("seed [" + seed + "] {" + query + "} {" + s + "}", topDocs.totalHits > 0);
+    }
+    long e = System.currentTimeMillis();
+    System.out.println("Finished in [" + (e - s) + "] ms");
+  }
+
+  private Directory createIndex(Random random, Collection<Query> sampler) throws CorruptIndexException, LockObtainFailedException, IOException {
+    Directory directory = new RAMDirectory();
+    String[] columnFamilies = genWords(random, MIN_NUM_COL_FAM, MAX_NUM_COL_FAM, "colfam");
+    Map<String, String[]> columns = new HashMap<String, String[]>();
+    for (int i = 0; i < columnFamilies.length; i++) {
+      columns.put(columnFamilies[i], genWords(random, MIN_NUM_COLS, MAX_NUM_COLS, "col"));
+    }
+    IndexWriter writer = new IndexWriter(directory, new IndexWriterConfig(LUCENE_VERSION, new StandardAnalyzer(LUCENE_VERSION)));
+    int numberOfDocs = random.nextInt(MAX_NUM_OF_DOCS) + 1;
+    for (int i = 0; i < numberOfDocs; i++) {
+      writer.addDocuments(generatSuperDoc(random, columns, sampler));
+    }
+    writer.close();
+    return directory;
+  }
+
+  private String[] genWords(Random random, int min, int max, String prefix) {
+    int numberOfColFam = random.nextInt(max - min) + min;
+    String[] str = new String[numberOfColFam];
+    for (int i = 0; i < numberOfColFam; i++) {
+      str[i] = genWord(random, prefix);
+    }
+    return str;
+  }
+
+  private List<Document> generatSuperDoc(Random random, Map<String, String[]> columns, Collection<Query> sampler) {
+    List<Document> docs = new ArrayList<Document>();
+    BooleanQuery booleanQuery = new BooleanQuery();
+    for (String colFam : columns.keySet()) {
+      String[] cols = columns.get(colFam);
+      for (int i = 0; i < random.nextInt(MAX_NUM_DOCS_PER_COL_FAM); i++) {
+        Document doc = new Document();
+        for (String column : cols) {
+          if (random.nextInt() % MOD_COLS_USED_FOR_SKIPPING == 0) {
+            String word = genWord(random, "word");
+            doc.add(new StringField(colFam + "." + column, word, Store.YES));
+            if (random.nextInt() % MOD_USED_FOR_SAMPLING == 0) {
+              TermQuery termQuery = new TermQuery(new Term(colFam + "." + column, word));
+              SuperQuery query = new SuperQuery(termQuery, ScoreType.SUPER, new Term(PRIME_DOC, PRIME_DOC_VALUE));
+              booleanQuery.add(query, Occur.MUST);
+            }
+          }
+        }
+        docs.add(doc);
+      }
+    }
+    if (!booleanQuery.clauses().isEmpty()) {
+      sampler.add(booleanQuery);
+    }
+    Document document = docs.get(0);
+    document.add(new StringField(PRIME_DOC, PRIME_DOC_VALUE, Store.NO));
+    return docs;
+  }
+
+  private String genWord(Random random, String prefix) {
+    return prefix + random.nextInt(MAX_NUM_OF_WORDS);
+  }
+}

http://git-wip-us.apache.org/repos/asf/incubator-blur/blob/0f78613d/src/blur-query/src/test/java/org/apache/blur/search/SuperQueryTest.java
----------------------------------------------------------------------
diff --git a/src/blur-query/src/test/java/org/apache/blur/search/SuperQueryTest.java b/src/blur-query/src/test/java/org/apache/blur/search/SuperQueryTest.java
new file mode 100644
index 0000000..5eaf8b2
--- /dev/null
+++ b/src/blur-query/src/test/java/org/apache/blur/search/SuperQueryTest.java
@@ -0,0 +1,199 @@
+package org.apache.blur.search;
+
+/**
+ * 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 static junit.framework.Assert.assertEquals;
+import static org.apache.blur.lucene.LuceneVersionConstant.LUCENE_VERSION;
+
+import java.io.IOException;
+import java.util.Arrays;
+import java.util.List;
+import java.util.concurrent.atomic.AtomicLongArray;
+
+import org.apache.blur.lucene.search.FacetQuery;
+import org.apache.blur.lucene.search.ScoreType;
+import org.apache.blur.lucene.search.SuperQuery;
+import org.apache.lucene.analysis.standard.StandardAnalyzer;
+import org.apache.lucene.document.Document;
+import org.apache.lucene.document.Field.Store;
+import org.apache.lucene.document.StringField;
+import org.apache.lucene.index.CorruptIndexException;
+import org.apache.lucene.index.DirectoryReader;
+import org.apache.lucene.index.IndexReader;
+import org.apache.lucene.index.IndexWriter;
+import org.apache.lucene.index.IndexWriterConfig;
+import org.apache.lucene.index.IndexableField;
+import org.apache.lucene.index.Term;
+import org.apache.lucene.search.BooleanClause.Occur;
+import org.apache.lucene.search.BooleanQuery;
+import org.apache.lucene.search.IndexSearcher;
+import org.apache.lucene.search.Query;
+import org.apache.lucene.search.TermQuery;
+import org.apache.lucene.search.TopDocs;
+import org.apache.lucene.store.Directory;
+import org.apache.lucene.store.LockObtainFailedException;
+import org.apache.lucene.store.RAMDirectory;
+import org.junit.Test;
+
+public class SuperQueryTest {
+
+  private static final String PERSON_NAME = "person.name";
+  private static final String ADDRESS_STREET = "address.street";
+
+  private static final String PRIME_DOC = "_p_";
+  private static final String PRIME_DOC_VALUE = "_true_";
+
+  private static final String NAME1 = "jon";
+  private static final String NAME2 = "jane";
+  private static final String STREET2 = "main st";
+  private static final String STREET1 = "main";
+  private static final String ROW_ID = "rowid";
+
+  @Test
+  public void testSimpleSuperQuery() throws CorruptIndexException, IOException, InterruptedException {
+    BooleanQuery booleanQuery = new BooleanQuery();
+    booleanQuery.add(wrapSuper(new TermQuery(new Term(PERSON_NAME, NAME1))), Occur.MUST);
+    booleanQuery.add(wrapSuper(new TermQuery(new Term(ADDRESS_STREET, STREET1))), Occur.MUST);
+
+    Directory directory = createIndex();
+    IndexReader reader = DirectoryReader.open(directory);
+
+    IndexSearcher searcher = new IndexSearcher(reader);
+    TopDocs topDocs = searcher.search(booleanQuery, 10);
+    assertEquals(2, topDocs.totalHits);
+    assertEquals("1", searcher.doc(topDocs.scoreDocs[0].doc).get(ROW_ID));
+    assertEquals("3", searcher.doc(topDocs.scoreDocs[1].doc).get(ROW_ID));
+  }
+
+  @Test
+  public void testAggregateScoreTypes() throws Exception {
+    IndexSearcher searcher = createSearcher();
+    BooleanQuery booleanQuery = new BooleanQuery();
+    booleanQuery.add(wrapSuper(PERSON_NAME, NAME1, ScoreType.AGGREGATE), Occur.SHOULD);
+    booleanQuery.add(wrapSuper(ADDRESS_STREET, STREET1, ScoreType.AGGREGATE), Occur.MUST);
+    TopDocs topDocs = searcher.search(booleanQuery, 10);
+    printTopDocs(topDocs);
+    assertEquals(3, topDocs.totalHits);
+  }
+
+  @Test
+  public void testBestScoreTypes() throws Exception {
+    IndexSearcher searcher = createSearcher();
+    BooleanQuery booleanQuery = new BooleanQuery();
+    booleanQuery.add(wrapSuper(PERSON_NAME, NAME1, ScoreType.BEST), Occur.SHOULD);
+    booleanQuery.add(wrapSuper(ADDRESS_STREET, STREET1, ScoreType.BEST), Occur.MUST);
+    TopDocs topDocs = searcher.search(booleanQuery, 10);
+    assertEquals(3, topDocs.totalHits);
+    printTopDocs(topDocs);
+  }
+
+  private void printTopDocs(TopDocs topDocs) {
+    for (int i = 0; i < topDocs.totalHits; i++) {
+      System.out.println("doc " + i + " score " + topDocs.scoreDocs[i].score);
+    }
+
+  }
+
+  @Test
+  public void testConstantScoreTypes() throws Exception {
+    IndexSearcher searcher = createSearcher();
+    BooleanQuery booleanQuery = new BooleanQuery();
+    booleanQuery.add(wrapSuper(PERSON_NAME, NAME1, ScoreType.CONSTANT), Occur.SHOULD);
+    booleanQuery.add(wrapSuper(ADDRESS_STREET, STREET1, ScoreType.CONSTANT), Occur.MUST);
+    TopDocs topDocs = searcher.search(booleanQuery, 10);
+    assertEquals(3, topDocs.totalHits);
+    printTopDocs(topDocs);
+  }
+
+  @Test
+  public void testSuperScoreTypes() throws Exception {
+    IndexSearcher searcher = createSearcher();
+    BooleanQuery booleanQuery = new BooleanQuery();
+    booleanQuery.add(wrapSuper(PERSON_NAME, NAME1, ScoreType.SUPER), Occur.SHOULD);
+    booleanQuery.add(wrapSuper(ADDRESS_STREET, STREET1, ScoreType.SUPER), Occur.MUST);
+    TopDocs topDocs = searcher.search(booleanQuery, 10);
+    assertEquals(3, topDocs.totalHits);
+    printTopDocs(topDocs);
+  }
+
+  @Test
+  public void testSuperScoreTypesWithFacet() throws Exception {
+    IndexSearcher searcher = createSearcher();
+    BooleanQuery booleanQuery = new BooleanQuery();
+    booleanQuery.add(wrapSuper(PERSON_NAME, NAME1, ScoreType.SUPER), Occur.SHOULD);
+    booleanQuery.add(wrapSuper(ADDRESS_STREET, STREET1, ScoreType.SUPER), Occur.MUST);
+
+    BooleanQuery f1 = new BooleanQuery();
+    f1.add(new TermQuery(new Term(PERSON_NAME, NAME1)), Occur.MUST);
+    f1.add(new TermQuery(new Term(PERSON_NAME, NAME2)), Occur.MUST);
+
+    Query[] facets = new Query[] { new SuperQuery(f1, ScoreType.CONSTANT, new Term(PRIME_DOC, PRIME_DOC_VALUE)) };
+    AtomicLongArray counts = new AtomicLongArray(facets.length);
+    FacetQuery query = new FacetQuery(booleanQuery, facets, counts);
+
+    TopDocs topDocs = searcher.search(query, 10);
+    assertEquals(3, topDocs.totalHits);
+    printTopDocs(topDocs);
+  }
+
+  private static IndexSearcher createSearcher() throws Exception {
+    Directory directory = createIndex();
+    IndexReader reader = DirectoryReader.open(directory);
+    return new IndexSearcher(reader);
+  }
+
+  public static Directory createIndex() throws CorruptIndexException, LockObtainFailedException, IOException {
+    Directory directory = new RAMDirectory();
+    IndexWriter writer = new IndexWriter(directory, new IndexWriterConfig(LUCENE_VERSION, new StandardAnalyzer(LUCENE_VERSION)));
+    writer.addDocuments(addPrime(Arrays.asList(newDocument(newStringField(ROW_ID, "1"), newStringField(PERSON_NAME, NAME1)),
+        newDocument(newStringField(ROW_ID, "1"), newStringField(PERSON_NAME, NAME1)), newDocument(newStringField(ROW_ID, "1"), newStringField(ADDRESS_STREET, STREET1)))));
+    writer.addDocuments(addPrime(Arrays.asList(newDocument(newStringField(ROW_ID, "2"), newStringField(PERSON_NAME, NAME2)),
+        newDocument(newStringField(ROW_ID, "2"), newStringField(ADDRESS_STREET, STREET1)))));
+    writer.addDocuments(addPrime(Arrays.asList(newDocument(newStringField(ROW_ID, "3"), newStringField(PERSON_NAME, NAME1)),
+        newDocument(newStringField(ROW_ID, "3"), newStringField(ADDRESS_STREET, STREET1)), newDocument(newStringField(ROW_ID, "3"), newStringField(ADDRESS_STREET, STREET2)))));
+    writer.close();
+    return directory;
+  }
+
+  private static List<Document> addPrime(List<Document> docs) {
+    Document document = docs.get(0);
+    document.add(new StringField(PRIME_DOC, PRIME_DOC_VALUE, Store.NO));
+    return docs;
+  }
+
+  private static Document newDocument(IndexableField... fields) {
+    Document document = new Document();
+    for (IndexableField field : fields) {
+      document.add(field);
+    }
+    return document;
+  }
+
+  private static IndexableField newStringField(String name, String value) {
+    return new StringField(name, value, Store.YES);
+  }
+
+  private Query wrapSuper(Query query) {
+    return new SuperQuery(query, ScoreType.AGGREGATE, new Term(PRIME_DOC, PRIME_DOC_VALUE));
+  }
+
+  private Query wrapSuper(String field, String value, ScoreType scoreType) {
+    return new SuperQuery(new TermQuery(new Term(field, value)), scoreType, new Term(PRIME_DOC, PRIME_DOC_VALUE));
+  }
+
+}

http://git-wip-us.apache.org/repos/asf/incubator-blur/blob/0f78613d/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
deleted file mode 100644
index 1e59fba..0000000
--- a/src/blur-store/src/main/java/org/apache/blur/lucene/serializer/AbtractQueryWritable.java
+++ /dev/null
@@ -1,28 +0,0 @@
-package org.apache.blur.lucene.serializer;
-
-/**
- * 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 org.apache.hadoop.io.Writable;
-import org.apache.lucene.search.Query;
-
-public abstract class AbtractQueryWritable<T extends Query> implements Writable {
-
-  public abstract Query getQuery();
-
-  public abstract void setQuery(T query);
-
-}

http://git-wip-us.apache.org/repos/asf/incubator-blur/blob/0f78613d/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
deleted file mode 100644
index e96a19b..0000000
--- a/src/blur-store/src/main/java/org/apache/blur/lucene/serializer/BooleanClauseWritable.java
+++ /dev/null
@@ -1,87 +0,0 @@
-package org.apache.blur.lucene.serializer;
-
-/**
- * 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.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/0f78613d/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
deleted file mode 100644
index a7da00b..0000000
--- a/src/blur-store/src/main/java/org/apache/blur/lucene/serializer/BooleanQueryWritable.java
+++ /dev/null
@@ -1,73 +0,0 @@
-package org.apache.blur.lucene.serializer;
-
-/**
- * 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.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<BooleanQuery> {
-
-  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/0f78613d/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
deleted file mode 100644
index d285f5b..0000000
--- a/src/blur-store/src/main/java/org/apache/blur/lucene/serializer/FuzzyQueryWritable.java
+++ /dev/null
@@ -1,105 +0,0 @@
-package org.apache.blur.lucene.serializer;
-
-/**
- * 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.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<FuzzyQuery> {
-
-  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/0f78613d/src/blur-store/src/main/java/org/apache/blur/lucene/serializer/MatchAllDocsQueryWritable.java
----------------------------------------------------------------------
diff --git a/src/blur-store/src/main/java/org/apache/blur/lucene/serializer/MatchAllDocsQueryWritable.java b/src/blur-store/src/main/java/org/apache/blur/lucene/serializer/MatchAllDocsQueryWritable.java
deleted file mode 100644
index 88e988b..0000000
--- a/src/blur-store/src/main/java/org/apache/blur/lucene/serializer/MatchAllDocsQueryWritable.java
+++ /dev/null
@@ -1,36 +0,0 @@
-package org.apache.blur.lucene.serializer;
-
-import java.io.DataInput;
-import java.io.DataOutput;
-import java.io.IOException;
-
-import org.apache.lucene.search.MatchAllDocsQuery;
-import org.apache.lucene.search.Query;
-
-public class MatchAllDocsQueryWritable extends AbtractQueryWritable<MatchAllDocsQuery> {
-
-  private MatchAllDocsQuery query;
-
-  @Override
-  public void write(DataOutput out) throws IOException {
-    out.writeFloat(query.getBoost());
-  }
-
-  @Override
-  public void readFields(DataInput in) throws IOException {
-    float boost = in.readFloat();
-    query = new MatchAllDocsQuery();
-    query.setBoost(boost);
-  }
-
-  @Override
-  public Query getQuery() {
-    return query;
-  }
-
-  @Override
-  public void setQuery(MatchAllDocsQuery query) {
-    this.query = query;
-  }
-
-}

http://git-wip-us.apache.org/repos/asf/incubator-blur/blob/0f78613d/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
deleted file mode 100644
index 0aada55..0000000
--- a/src/blur-store/src/main/java/org/apache/blur/lucene/serializer/ProtoSerializer.java
+++ /dev/null
@@ -1,79 +0,0 @@
-package org.apache.blur.lucene.serializer;
-
-/**
- * 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.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/0f78613d/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
deleted file mode 100644
index 495261a..0000000
--- a/src/blur-store/src/main/java/org/apache/blur/lucene/serializer/QUERY_TYPE.java
+++ /dev/null
@@ -1,133 +0,0 @@
-package org.apache.blur.lucene.serializer;
-
-/**
- * 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 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), MATCH_ALL_DOCS((byte) 3);
-
-  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;
-    case 3:
-      return MATCH_ALL_DOCS;
-    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) {
-      return MATCH_ALL_DOCS;
-    } 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();
-    case MATCH_ALL_DOCS:
-      return new MatchAllDocsQueryWritable();
-    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/0f78613d/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
deleted file mode 100644
index 2a1fa93..0000000
--- a/src/blur-store/src/main/java/org/apache/blur/lucene/serializer/QueryWritable.java
+++ /dev/null
@@ -1,70 +0,0 @@
-package org.apache.blur.lucene.serializer;
-
-/**
- * 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.DataInput;
-import java.io.DataOutput;
-import java.io.IOException;
-
-import org.apache.lucene.search.Query;
-
-public class QueryWritable extends AbtractQueryWritable<Query> {
-
-  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;
-  }
-
-  @SuppressWarnings("unchecked")
-  @Override
-  public void write(DataOutput out) throws IOException {
-    out.write(lookup.getType());
-    AbtractQueryWritable<Query> writable = (AbtractQueryWritable<Query>) QUERY_TYPE.lookupQueryWritable(lookup);
-    writable.setQuery(query);
-    writable.write(out);
-  }
-
-  @SuppressWarnings("unchecked")
-  @Override
-  public void readFields(DataInput in) throws IOException {
-    byte b = in.readByte();
-    lookup = QUERY_TYPE.lookup(b);
-    AbtractQueryWritable<Query> writable = (AbtractQueryWritable<Query>) QUERY_TYPE.lookupQueryWritable(lookup);
-    writable.readFields(in);
-    query = writable.getQuery();
-  }
-}


Mime
View raw message