incubator-blur-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From twilli...@apache.org
Subject git commit: add docfreq command
Date Thu, 02 Oct 2014 02:28:55 GMT
Repository: incubator-blur
Updated Branches:
  refs/heads/master c90ddc57e -> 36e3c85d7


add docfreq command


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

Branch: refs/heads/master
Commit: 36e3c85d77dc2c733edf6c20036e6d0fa35166d8
Parents: c90ddc5
Author: twilliams <twilliams@apache.org>
Authored: Wed Oct 1 22:09:19 2014 -0400
Committer: twilliams <twilliams@apache.org>
Committed: Wed Oct 1 22:09:19 2014 -0400

----------------------------------------------------------------------
 .../org/apache/blur/command/DocFreqCommand.java | 86 ++++++++++++++++++++
 .../apache/blur/command/DocFreqCommandTest.java | 56 +++++++++++++
 2 files changed, 142 insertions(+)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/incubator-blur/blob/36e3c85d/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
new file mode 100644
index 0000000..c436569
--- /dev/null
+++ b/blur-command/src/main/java/org/apache/blur/command/DocFreqCommand.java
@@ -0,0 +1,86 @@
+package org.apache.blur.command;
+
+import java.io.IOException;
+import java.util.Map;
+
+import org.apache.blur.command.annotation.Description;
+import org.apache.blur.command.annotation.RequiredArgument;
+import org.apache.blur.command.commandtype.ClusterServerReadCommandSingleTable;
+import org.apache.lucene.index.Term;
+
+/**
+ * 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.
+ */
+
+@Description("Returns the number of documents containing the term in the given field.")
+public class DocFreqCommand extends ClusterServerReadCommandSingleTable<Long> {
+  private static final String NAME = "docFreq";
+
+  @RequiredArgument
+  private String fieldName;
+
+  @RequiredArgument
+  private String term;
+
+  public DocFreqCommand() {
+    super();
+  }
+
+  public DocFreqCommand(String fieldName, String term) {
+    super();
+    this.fieldName = fieldName;
+    this.term = 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, Map<? extends Location<?>, Long>
results) throws IOException,
+      InterruptedException {
+    
+    Long total = 0l;
+    
+    for(Long shardTotal: results.values()) {
+      total += shardTotal;
+    }
+    
+    return total;
+  }
+
+  @Override
+  public String getName() {
+    return NAME;
+  }
+
+  public String getFieldName() {
+    return fieldName;
+  }
+
+  public void setFieldName(String fieldName) {
+    this.fieldName = fieldName;
+  }
+
+  public String getTerm() {
+    return term;
+  }
+
+  public void setValue(String term) {
+    this.term = term;
+  }
+}

http://git-wip-us.apache.org/repos/asf/incubator-blur/blob/36e3c85d/blur-command/src/test/java/org/apache/blur/command/DocFreqCommandTest.java
----------------------------------------------------------------------
diff --git a/blur-command/src/test/java/org/apache/blur/command/DocFreqCommandTest.java b/blur-command/src/test/java/org/apache/blur/command/DocFreqCommandTest.java
new file mode 100644
index 0000000..5980a48
--- /dev/null
+++ b/blur-command/src/test/java/org/apache/blur/command/DocFreqCommandTest.java
@@ -0,0 +1,56 @@
+package org.apache.blur.command;
+
+import static org.junit.Assert.assertEquals;
+
+import java.io.IOException;
+import java.util.Map;
+
+import org.junit.BeforeClass;
+import org.junit.Test;
+
+import com.google.common.collect.Lists;
+import com.google.common.collect.Maps;
+
+/**
+ * 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.
+ */
+public class DocFreqCommandTest {
+  private static IndexContext ctx;
+
+  @BeforeClass
+  public static void init() {
+    ctx = CoreTestContext.newSimpleAlpaNumContext();
+  }
+
+  @Test
+  public void termInAllDocsShouldBeCorrect() throws IOException {
+    Long returned = new DocFreqCommand("val", "val").execute(ctx);
+    Long expected = 26l;
+
+    assertEquals(expected, returned);
+  }
+  
+  @Test
+  public void singleDocFreq() throws IOException {
+    Long returned = new DocFreqCommand("alpha", "aa").execute(ctx);
+    Long expected = 1l;
+        
+    assertEquals(expected, returned);    
+  }
+  
+
+
+}


Mime
View raw message