incubator-blur-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From twilli...@apache.org
Subject git commit: let terms respect size request
Date Wed, 24 Sep 2014 23:25:41 GMT
Repository: incubator-blur
Updated Branches:
  refs/heads/master 9fcba9c0e -> fdead86bf


let terms respect size request


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

Branch: refs/heads/master
Commit: fdead86bf6945e7edca9166596e711fa957915a0
Parents: 9fcba9c
Author: twilliams <twilliams@apache.org>
Authored: Wed Sep 24 19:25:35 2014 -0400
Committer: twilliams <twilliams@apache.org>
Committed: Wed Sep 24 19:25:35 2014 -0400

----------------------------------------------------------------------
 .../org/apache/blur/command/TermsCommand.java   | 23 +++++++++++-----
 .../apache/blur/command/TermsCommandTest.java   | 28 +++++++++++++++++---
 .../main/java/org/apache/blur/command/Args.java |  4 +++
 3 files changed, 46 insertions(+), 9 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/incubator-blur/blob/fdead86b/blur-command/src/main/java/org/apache/blur/command/TermsCommand.java
----------------------------------------------------------------------
diff --git a/blur-command/src/main/java/org/apache/blur/command/TermsCommand.java b/blur-command/src/main/java/org/apache/blur/command/TermsCommand.java
index 446e7ae..b9b62b9 100644
--- a/blur-command/src/main/java/org/apache/blur/command/TermsCommand.java
+++ b/blur-command/src/main/java/org/apache/blur/command/TermsCommand.java
@@ -56,16 +56,27 @@ public class TermsCommand extends Command implements ClusterReadCombiningCommand
   }
 
   @Override
-  public BlurArray combine(CombiningContext context, Map<? extends Location<?>,
BlurArray> results)
-      throws IOException, InterruptedException {
+  public BlurArray combine(CombiningContext context, Map<? extends Location<?>,
BlurArray> results) throws IOException,
+      InterruptedException {
     TreeSet<String> terms = Sets.newTreeSet();
+    
 
     for (BlurArray t : results.values()) {
-      terms.addAll((List<String>)t.asList());
+      terms.addAll((List<String>) t.asList());
     }
-    // TODO: Use default until we figure out the requested size from the
-    // context.
-    return new BlurArray(Lists.newArrayList(terms).subList(0, Math.min(DEFAULT_SIZE, terms.size())));
+
+    short size = getSize(context);
+
+    return new BlurArray(Lists.newArrayList(terms).subList(0, Math.min((int) size, terms.size())));
+  }
+
+  private short getSize(CombiningContext context) {
+    short size = DEFAULT_SIZE;
+    if ((context.getArgs() != null) && (context.getArgs().containsArg(PARAMS))) {
+      BlurObject params = context.getArgs().get(PARAMS);
+      size = params.getShort(P_SIZE, DEFAULT_SIZE);
+    }
+    return size;
   }
 
   @Override

http://git-wip-us.apache.org/repos/asf/incubator-blur/blob/fdead86b/blur-command/src/test/java/org/apache/blur/command/TermsCommandTest.java
----------------------------------------------------------------------
diff --git a/blur-command/src/test/java/org/apache/blur/command/TermsCommandTest.java b/blur-command/src/test/java/org/apache/blur/command/TermsCommandTest.java
index c480f29..512cff9 100644
--- a/blur-command/src/test/java/org/apache/blur/command/TermsCommandTest.java
+++ b/blur-command/src/test/java/org/apache/blur/command/TermsCommandTest.java
@@ -59,17 +59,39 @@ public class TermsCommandTest {
 
     assertEquals(expected, returned);
   }
+  
+  @Test
+  public void combineSizeShouldDefaultToTen() throws IOException, InterruptedException {
+    Map<Shard, BlurArray> execResults = Maps.newHashMap();
+    execResults.put(new Shard("t1", "s1"), new BlurArray(Lists.newArrayList("aa", "cc", "ee",
"gg", "ii")));
+    execResults.put(new Shard("t1", "s2"), new BlurArray(Lists.newArrayList("bb", "dd", "ff",
"hh", "jj")));
+    
+    BlurArray expected = new BlurArray(Lists.newArrayList("aa", "bb", "cc", "dd", "ee", "ff",
"gg", "hh", "ii", "jj"));
+    
+    TermsCommand cmd = new TermsCommand();
+    Args args = new Args();
+    BlurObject params = new BlurObject();
+    args.set("params", params);
+    BlurArray returned = cmd.combine(new TestCombiningContext(args), execResults);
+    
+    assertEquals(expected, returned);
+  }
 
   @Test
-  public void combineShouldBeCorrect() throws IOException, InterruptedException {
+  public void combineShouldRespectSize() throws IOException, InterruptedException {
     Map<Shard, BlurArray> execResults = Maps.newHashMap();
     execResults.put(new Shard("t1", "s1"), new BlurArray(Lists.newArrayList("aa", "cc")));
     execResults.put(new Shard("t1", "s2"), new BlurArray(Lists.newArrayList("bb", "dd")));
     
-    BlurArray expected = new BlurArray(Lists.newArrayList("aa", "bb", "cc", "dd"));
+    BlurArray expected = new BlurArray(Lists.newArrayList("aa", "bb"));
     
     TermsCommand cmd = new TermsCommand();
-    BlurArray returned = cmd.combine(new TestCombiningContext(), execResults);
+    Args args = new Args();
+    BlurObject params = new BlurObject();
+    params.put("size", (short)2);
+    args.set("params", params);
+    
+    BlurArray returned = cmd.combine(new TestCombiningContext(args), execResults);
     
     assertEquals(expected, returned);
   }

http://git-wip-us.apache.org/repos/asf/incubator-blur/blob/fdead86b/blur-core/src/main/java/org/apache/blur/command/Args.java
----------------------------------------------------------------------
diff --git a/blur-core/src/main/java/org/apache/blur/command/Args.java b/blur-core/src/main/java/org/apache/blur/command/Args.java
index ec14700..e3e98de 100644
--- a/blur-core/src/main/java/org/apache/blur/command/Args.java
+++ b/blur-core/src/main/java/org/apache/blur/command/Args.java
@@ -43,5 +43,9 @@ public class Args {
   public Map<String, Object> getValues() {
     return _values;
   }
+  
+  public boolean containsArg(String name) {
+    return _values.containsKey(name);
+  }
 
 }


Mime
View raw message