incubator-blur-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From twilli...@apache.org
Subject [1/2] incubator-blur git commit: add simple base command for general case
Date Thu, 13 Nov 2014 01:58:38 GMT
Repository: incubator-blur
Updated Branches:
  refs/heads/master 66a199235 -> 1a59e6ace


add simple base command for general case


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

Branch: refs/heads/master
Commit: c92a22676b9fa806d542e357cee820c87caba364
Parents: 66a1992
Author: twilliams <twilliams@apache.org>
Authored: Wed Nov 12 20:57:31 2014 -0500
Committer: twilliams <twilliams@apache.org>
Committed: Wed Nov 12 20:57:31 2014 -0500

----------------------------------------------------------------------
 .../org/apache/blur/command/DocFreqCommand.java |  9 ++-
 .../command/commandtype/TableReadCommand.java   | 79 ++++++++++++++++++++
 2 files changed, 85 insertions(+), 3 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/incubator-blur/blob/c92a2267/blur-command/src/main/java/org/apache/blur/command/DocFreqCommand.java
----------------------------------------------------------------------
diff --git a/blur-command/src/main/java/org/apache/blur/command/DocFreqCommand.java b/blur-command/src/main/java/org/apache/blur/command/DocFreqCommand.java
index c436569..8881147 100644
--- a/blur-command/src/main/java/org/apache/blur/command/DocFreqCommand.java
+++ b/blur-command/src/main/java/org/apache/blur/command/DocFreqCommand.java
@@ -2,10 +2,12 @@ package org.apache.blur.command;
 
 import java.io.IOException;
 import java.util.Map;
+import java.util.Set;
 
 import org.apache.blur.command.annotation.Description;
 import org.apache.blur.command.annotation.RequiredArgument;
 import org.apache.blur.command.commandtype.ClusterServerReadCommandSingleTable;
+import org.apache.blur.command.commandtype.TableReadCommand;
 import org.apache.lucene.index.Term;
 
 /**
@@ -26,7 +28,7 @@ import org.apache.lucene.index.Term;
  */
 
 @Description("Returns the number of documents containing the term in the given field.")
-public class DocFreqCommand extends ClusterServerReadCommandSingleTable<Long> {
+public class DocFreqCommand extends TableReadCommand<Long> {
   private static final String NAME = "docFreq";
 
   @RequiredArgument
@@ -51,12 +53,12 @@ public class DocFreqCommand extends ClusterServerReadCommandSingleTable<Long>
{
   }
 
   @Override
-  public Long combine(CombiningContext context, Map<? extends Location<?>, Long>
results) throws IOException,
+  public Long combine(CombiningContext context, Iterable<Long> results) throws IOException,
       InterruptedException {
     
     Long total = 0l;
     
-    for(Long shardTotal: results.values()) {
+    for(Long shardTotal: results) {
       total += shardTotal;
     }
     
@@ -83,4 +85,5 @@ public class DocFreqCommand extends ClusterServerReadCommandSingleTable<Long>
{
   public void setValue(String term) {
     this.term = term;
   }
+
 }

http://git-wip-us.apache.org/repos/asf/incubator-blur/blob/c92a2267/blur-core/src/main/java/org/apache/blur/command/commandtype/TableReadCommand.java
----------------------------------------------------------------------
diff --git a/blur-core/src/main/java/org/apache/blur/command/commandtype/TableReadCommand.java
b/blur-core/src/main/java/org/apache/blur/command/commandtype/TableReadCommand.java
new file mode 100644
index 0000000..d015cf1
--- /dev/null
+++ b/blur-core/src/main/java/org/apache/blur/command/commandtype/TableReadCommand.java
@@ -0,0 +1,79 @@
+/**
+ * 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.
+ */
+package org.apache.blur.command.commandtype;
+
+import java.io.IOException;
+import java.util.Map;
+
+import org.apache.blur.command.CombiningContext;
+import org.apache.blur.command.IndexContext;
+import org.apache.blur.command.Location;
+import org.apache.blur.command.annotation.RequiredArgument;
+import org.apache.lucene.index.Term;
+
+/**
+ * <p>
+ * The TableReadCommand is a base command over a single table for use when 
+ * the return type from an individual shard is the same as the return type 
+ * for the combine.  
+ * </p>
+ * <p>
+ * Example usage:
+ * <pre>
+ * public class DocFreqCommand extends TableReadCommand<Long> {
+ * private static final String NAME = "docFreq";
+ *
+ * @RequiredArgument
+ * private String fieldName;
+ *
+ * @RequiredArgument
+ * private String term;
+ * ...
+ * 
+ * @Override
+ * public Long execute(IndexContext context) throws IOException {
+ *   return new Long(context.getIndexReader().docFreq(new Term(fieldName, term)));
+ * }
+ * 
+ * @Override
+ * public Long combine(CombiningContext context, Iterable<Long> results) throws IOException,
+ *     InterruptedException {
+ *   
+ *   Long total = 0l;
+ *   
+ *   for(Long shardTotal: results) {
+ *     total += shardTotal;
+ *   }
+ *   
+ *   return total;
+ * }
+ * ...
+ * }
+ * </pre>
+ * </p>
+ */
+public abstract class TableReadCommand<T> extends ClusterServerReadCommandSingleTable<T>
{
+
+  public abstract T combine(CombiningContext context, Iterable<T> results) throws IOException,
InterruptedException;
+
+  @Override
+  public T combine(CombiningContext context, Map<? extends Location<?>, T> results)
throws IOException,
+      InterruptedException {
+    return combine(context, results.values());
+  }
+
+}


Mime
View raw message