incubator-blur-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From amccu...@apache.org
Subject [1/9] git commit: Made the SuperQuery class serializable.
Date Tue, 19 Feb 2013 01:59:11 GMT
Made the SuperQuery class serializable.


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

Branch: refs/heads/0.2-dev
Commit: b75a2025c45ef4d2dc0007cf953b484670644464
Parents: 747caac
Author: Aaron McCurry <amccurry@gmail.com>
Authored: Tue Feb 12 22:06:02 2013 -0500
Committer: Aaron McCurry <amccurry@gmail.com>
Committed: Tue Feb 12 22:06:02 2013 -0500

----------------------------------------------------------------------
 .../blur/lucene/search/AbstractWrapperQuery.java   |    8 ++
 .../org/apache/blur/lucene/search/SuperQuery.java  |    9 ++
 .../org/apache/blur/lucene/serializer/IOUtil.java  |   30 +++++++
 .../blur/lucene/serializer/ProtoSerializer.java    |   13 +++-
 .../lucene/serializer/QueryWritableMapper.java     |    1 +
 .../blur/lucene/serializer/SuperQueryWritable.java |   60 +++++++++++++++
 6 files changed, 119 insertions(+), 2 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/incubator-blur/blob/b75a2025/src/blur-query/src/main/java/org/apache/blur/lucene/search/AbstractWrapperQuery.java
----------------------------------------------------------------------
diff --git a/src/blur-query/src/main/java/org/apache/blur/lucene/search/AbstractWrapperQuery.java
b/src/blur-query/src/main/java/org/apache/blur/lucene/search/AbstractWrapperQuery.java
index f9c4c6b..9f31f3d 100644
--- a/src/blur-query/src/main/java/org/apache/blur/lucene/search/AbstractWrapperQuery.java
+++ b/src/blur-query/src/main/java/org/apache/blur/lucene/search/AbstractWrapperQuery.java
@@ -39,6 +39,14 @@ public abstract class AbstractWrapperQuery extends Query {
     this._rewritten = rewritten;
   }
 
+  public Query getQuery() {
+    return _query;
+  }
+
+  public boolean isRewritten() {
+    return _rewritten;
+  }
+
   public abstract Query clone();
 
   public abstract Weight createWeight(IndexSearcher searcher) throws IOException;

http://git-wip-us.apache.org/repos/asf/incubator-blur/blob/b75a2025/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
index a503d77..46f62b1 100644
--- 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
@@ -47,6 +47,15 @@ public class SuperQuery extends AbstractWrapperQuery {
     this.scoreType = scoreType;
     this.primeDocTerm = primeDocTerm;
   }
+  
+
+  public ScoreType getScoreType() {
+    return scoreType;
+  }
+
+  public Term getPrimeDocTerm() {
+    return primeDocTerm;
+  }
 
   public Query clone() {
     return new SuperQuery((Query) _query.clone(), scoreType, primeDocTerm, _rewritten);

http://git-wip-us.apache.org/repos/asf/incubator-blur/blob/b75a2025/src/blur-query/src/main/java/org/apache/blur/lucene/serializer/IOUtil.java
----------------------------------------------------------------------
diff --git a/src/blur-query/src/main/java/org/apache/blur/lucene/serializer/IOUtil.java b/src/blur-query/src/main/java/org/apache/blur/lucene/serializer/IOUtil.java
new file mode 100644
index 0000000..64a611c
--- /dev/null
+++ b/src/blur-query/src/main/java/org/apache/blur/lucene/serializer/IOUtil.java
@@ -0,0 +1,30 @@
+package org.apache.blur.lucene.serializer;
+
+import java.io.DataInput;
+import java.io.DataOutput;
+import java.io.IOException;
+
+public class IOUtil {
+
+  private static final String UTF_8 = "UTF-8";
+
+  public static void writeString(DataOutput out, String s) throws IOException {
+    if (s == null) {
+      out.writeInt(-1);
+    }
+    byte[] bytes = s.getBytes(UTF_8);
+    out.writeInt(bytes.length);
+    out.write(bytes);
+  }
+
+  public static String readString(DataInput in) throws IOException {
+    int length = in.readInt();
+    if (length == -1) {
+      return null;
+    }
+    byte[] bs = new byte[length];
+    in.readFully(bs);
+    return new String(bs, UTF_8);
+  }
+
+}

http://git-wip-us.apache.org/repos/asf/incubator-blur/blob/b75a2025/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
index b666b54..b90d8b2 100644
--- 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
@@ -18,9 +18,12 @@ package org.apache.blur.lucene.serializer;
  */
 import java.io.IOException;
 
+import org.apache.blur.lucene.search.ScoreType;
+import org.apache.blur.lucene.search.SuperQuery;
 import org.apache.hadoop.io.DataInputBuffer;
 import org.apache.hadoop.io.DataOutputBuffer;
 import org.apache.lucene.analysis.standard.StandardAnalyzer;
+import org.apache.lucene.index.Term;
 import org.apache.lucene.queryparser.classic.ParseException;
 import org.apache.lucene.queryparser.classic.QueryParser;
 import org.apache.lucene.search.Query;
@@ -33,8 +36,10 @@ public class ProtoSerializer {
     QueryParser parser = new QueryParser(Version.LUCENE_40, "", new StandardAnalyzer(Version.LUCENE_40));
 
     Query query = parser.parse("a:v1 b:v2 c:v3~ c:asda*asda");
+    
+    SuperQuery superQuery = new SuperQuery(query,ScoreType.SUPER,new Term("_primedoc_"));
 
-    QueryWritable queryWritable = new QueryWritable(query);
+    QueryWritable queryWritable = new QueryWritable(superQuery);
     DataOutputBuffer buffer = new DataOutputBuffer();
     queryWritable.write(buffer);
     buffer.close();
@@ -47,10 +52,14 @@ public class ProtoSerializer {
     in.reset(buffer.getData(), 0, buffer.getLength());
     qw.readFields(in);
 
+    System.out.println("------------");
+    
     System.out.println(qw.getQuery());
+    
+    System.out.println("------------");
 
     while (true) {
-      run(query);
+      run(superQuery);
     }
   }
 

http://git-wip-us.apache.org/repos/asf/incubator-blur/blob/b75a2025/src/blur-query/src/main/java/org/apache/blur/lucene/serializer/QueryWritableMapper.java
----------------------------------------------------------------------
diff --git a/src/blur-query/src/main/java/org/apache/blur/lucene/serializer/QueryWritableMapper.java
b/src/blur-query/src/main/java/org/apache/blur/lucene/serializer/QueryWritableMapper.java
index 4e10a70..268b676 100644
--- a/src/blur-query/src/main/java/org/apache/blur/lucene/serializer/QueryWritableMapper.java
+++ b/src/blur-query/src/main/java/org/apache/blur/lucene/serializer/QueryWritableMapper.java
@@ -32,6 +32,7 @@ public class QueryWritableMapper {
     register(2, new FuzzyQueryWritable());
     register(3, new MatchAllDocsQueryWritable());
     register(4, new WildcardQueryWritable());
+    register(5, new SuperQueryWritable());
   }
 
   private static synchronized void register(int id, AbtractQueryWritable<? extends Query>
queryWritable) {

http://git-wip-us.apache.org/repos/asf/incubator-blur/blob/b75a2025/src/blur-query/src/main/java/org/apache/blur/lucene/serializer/SuperQueryWritable.java
----------------------------------------------------------------------
diff --git a/src/blur-query/src/main/java/org/apache/blur/lucene/serializer/SuperQueryWritable.java
b/src/blur-query/src/main/java/org/apache/blur/lucene/serializer/SuperQueryWritable.java
new file mode 100644
index 0000000..d060728
--- /dev/null
+++ b/src/blur-query/src/main/java/org/apache/blur/lucene/serializer/SuperQueryWritable.java
@@ -0,0 +1,60 @@
+package org.apache.blur.lucene.serializer;
+
+import java.io.DataInput;
+import java.io.DataOutput;
+import java.io.IOException;
+
+import org.apache.blur.lucene.search.ScoreType;
+import org.apache.blur.lucene.search.SuperQuery;
+import org.apache.lucene.index.Term;
+import org.apache.lucene.search.Query;
+
+public class SuperQueryWritable extends AbtractQueryWritable<SuperQuery> {
+
+  private SuperQuery query;
+
+  @Override
+  public void readFields(DataInput in) throws IOException {
+    QueryWritable queryWritable = new QueryWritable();
+    queryWritable.readFields(in);
+    Query subQuery = queryWritable.getQuery();
+    float boost = in.readFloat();
+    TermWritable termWritable = new TermWritable();
+    termWritable.readFields(in);
+    Term primeDocTerm = termWritable.getTerm();
+    String scoreType = IOUtil.readString(in);
+    
+    query = new SuperQuery(subQuery, ScoreType.valueOf(scoreType), primeDocTerm);
+    query.setBoost(boost);
+  }
+
+  @Override
+  public void write(DataOutput out) throws IOException {
+    Query subQuery = query.getQuery();
+    float boost = query.getBoost();
+    Term primeDocTerm = query.getPrimeDocTerm();
+    ScoreType scoreType = query.getScoreType();
+
+    // Start writing
+    new QueryWritable(subQuery).write(out);
+    out.writeFloat(boost);
+    new TermWritable(primeDocTerm).write(out);
+    IOUtil.writeString(out, scoreType.name());
+  }
+
+  @Override
+  public SuperQuery getQuery() {
+    return query;
+  }
+
+  @Override
+  public void setQuery(SuperQuery query) {
+    this.query = query;
+  }
+
+  @Override
+  public Class<SuperQuery> getType() {
+    return SuperQuery.class;
+  }
+
+}


Mime
View raw message