geode-issues mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From "ASF GitHub Bot (JIRA)" <j...@apache.org>
Subject [jira] [Commented] (GEODE-3888) Add lucene queries with the java API to the lucene example
Date Mon, 23 Oct 2017 17:52:00 GMT

    [ https://issues.apache.org/jira/browse/GEODE-3888?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=16215526#comment-16215526
] 

ASF GitHub Bot commented on GEODE-3888:
---------------------------------------

upthewaterspout closed pull request #28: GEODE-3888: Adding queries with the java API to the
lucene example
URL: https://github.com/apache/geode-examples/pull/28
 
 
   

This is a PR merged from a forked repository.
As GitHub hides the original diff on merge, it is displayed below for
the sake of provenance:

As this is a foreign pull request (from a fork), the diff is supplied
below (as it won't show otherwise due to GitHub magic):

diff --git a/lucene/build.gradle b/lucene/build.gradle
new file mode 100644
index 0000000..d373d3a
--- /dev/null
+++ b/lucene/build.gradle
@@ -0,0 +1,19 @@
+/*
+ * 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.
+ */
+dependencies {
+    compile "org.apache.geode:geode-lucene:$geodeVersion"
+}
\ No newline at end of file
diff --git a/lucene/src/main/java/org/apache/geode/examples/lucene/Example.java b/lucene/src/main/java/org/apache/geode/examples/lucene/Example.java
index 84cfc4b..9c19f5a 100644
--- a/lucene/src/main/java/org/apache/geode/examples/lucene/Example.java
+++ b/lucene/src/main/java/org/apache/geode/examples/lucene/Example.java
@@ -15,6 +15,7 @@
 package org.apache.geode.examples.lucene;
 
 import java.util.Arrays;
+import java.util.Map;
 import java.util.Random;
 import java.util.function.Consumer;
 
@@ -22,9 +23,13 @@
 import org.apache.geode.cache.client.ClientCache;
 import org.apache.geode.cache.client.ClientCacheFactory;
 import org.apache.geode.cache.client.ClientRegionShortcut;
+import org.apache.geode.cache.lucene.LuceneQuery;
+import org.apache.geode.cache.lucene.LuceneQueryException;
+import org.apache.geode.cache.lucene.LuceneService;
+import org.apache.geode.cache.lucene.LuceneServiceProvider;
 
-public class Example implements Consumer<Region<Integer, EmployeeData>> {
-  public static void main(String[] args) {
+public class Example {
+  public static void main(String[] args) throws LuceneQueryException {
     // connect to the locator using default port 10334
     ClientCache cache = new ClientCacheFactory().addPoolLocator("127.0.0.1", 10334)
         .set("log-level", "WARN").create();
@@ -34,12 +39,20 @@ public static void main(String[] args) {
         cache.<Integer, EmployeeData>createClientRegionFactory(ClientRegionShortcut.CACHING_PROXY)
             .create("example-region");
 
-    new Example().accept(region);
+    insertValues(region);
+    query(cache);
     cache.close();
   }
 
-  @Override
-  public void accept(Region<Integer, EmployeeData> region) {
+  private static void query(ClientCache cache) throws LuceneQueryException {
+    LuceneService lucene = LuceneServiceProvider.get(cache);
+    LuceneQuery<Integer, EmployeeData> query = lucene.createLuceneQueryFactory()
+        .create("simpleIndex", "example-region", "firstName:Chris~2", "firstname");
+    System.out.println("Employees with first names like Chris: " + query.findValues());
+  }
+
+
+  public static void insertValues(Map<Integer, EmployeeData> region) {
     // insert values into the region
     String[] firstNames = "Alex,Bertie,Kris,Dale,Frankie,Jamie,Morgan,Pat,Ricky,Taylor".split(",");
     String[] lastNames = "Able,Bell,Call,Driver,Forth,Jive,Minnow,Puts,Reliable,Tack".split(",");
@@ -57,12 +70,5 @@ public void accept(Region<Integer, EmployeeData> region) {
           salary, hoursPerWeek);
       region.put(key, val);
     }
-
-    // count the values in the region
-    int inserted = region.keySetOnServer().size();
-    System.out.println(String.format("Counted %d keys in region %s", inserted, region.getName()));
-
-    // fetch the values in the region
-    region.keySetOnServer().forEach(key -> System.out.println(region.get(key)));
   }
 }
diff --git a/lucene/src/test/java/org/apache/geode/examples/lucene/ExampleTest.java b/lucene/src/test/java/org/apache/geode/examples/lucene/ExampleTest.java
index c3e1013..8e488e5 100644
--- a/lucene/src/test/java/org/apache/geode/examples/lucene/ExampleTest.java
+++ b/lucene/src/test/java/org/apache/geode/examples/lucene/ExampleTest.java
@@ -14,25 +14,20 @@
  */
 package org.apache.geode.examples.lucene;
 
-import static org.assertj.core.api.Assertions.assertThat;
+import static org.junit.Assert.assertEquals;
+
+import java.util.HashMap;
+import java.util.Map;
 
-import org.apache.geode.cache.Region;
-import org.geode.examples.util.Mocks;
-import org.junit.Rule;
 import org.junit.Test;
-import org.junit.contrib.java.lang.system.SystemOutRule;
 
 public class ExampleTest {
 
-  @Rule
-  public SystemOutRule systemOutRule = new SystemOutRule().enableLog();
-
   @Test
-  public void testExample() throws Exception {
-    Region<Integer, EmployeeData> region = Mocks.region("example-region");
-    new Example().accept(region);
+  public void testInsertEntries() throws Exception {
+    Map<Integer, EmployeeData> region = new HashMap<>();
+    Example.insertValues(region);
 
-    assertThat(systemOutRule.getLog()).contains("Counted 10 keys in region");
-    assertThat(systemOutRule.getLog()).contains("Jamie");
+    assertEquals(10, region.size());
   }
 }


 

----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on GitHub and use the
URL above to go to the specific comment.
 
For queries about this service, please contact Infrastructure at:
users@infra.apache.org


> Add lucene queries with the java API to the lucene example
> ----------------------------------------------------------
>
>                 Key: GEODE-3888
>                 URL: https://issues.apache.org/jira/browse/GEODE-3888
>             Project: Geode
>          Issue Type: Bug
>          Components: examples
>            Reporter: Dan Smith
>            Assignee: Dan Smith
>
> The lucene example does not actually demonstrate the java API.



--
This message was sent by Atlassian JIRA
(v6.4.14#64029)

Mime
View raw message