Return-Path: X-Original-To: archive-asf-public-internal@cust-asf2.ponee.io Delivered-To: archive-asf-public-internal@cust-asf2.ponee.io Received: from cust-asf.ponee.io (cust-asf.ponee.io [163.172.22.183]) by cust-asf2.ponee.io (Postfix) with ESMTP id AFD90200D28 for ; Mon, 23 Oct 2017 19:52:07 +0200 (CEST) Received: by cust-asf.ponee.io (Postfix) id AE23E1609E0; Mon, 23 Oct 2017 17:52:07 +0000 (UTC) Delivered-To: archive-asf-public@cust-asf.ponee.io Received: from mail.apache.org (hermes.apache.org [140.211.11.3]) by cust-asf.ponee.io (Postfix) with SMTP id CB9CA1609DF for ; Mon, 23 Oct 2017 19:52:06 +0200 (CEST) Received: (qmail 26715 invoked by uid 500); 23 Oct 2017 17:52:06 -0000 Mailing-List: contact issues-help@geode.apache.org; run by ezmlm Precedence: bulk List-Help: List-Unsubscribe: List-Post: List-Id: Reply-To: dev@geode.apache.org Delivered-To: mailing list issues@geode.apache.org Received: (qmail 26706 invoked by uid 99); 23 Oct 2017 17:52:05 -0000 Received: from pnap-us-west-generic-nat.apache.org (HELO spamd2-us-west.apache.org) (209.188.14.142) by apache.org (qpsmtpd/0.29) with ESMTP; Mon, 23 Oct 2017 17:52:05 +0000 Received: from localhost (localhost [127.0.0.1]) by spamd2-us-west.apache.org (ASF Mail Server at spamd2-us-west.apache.org) with ESMTP id 40F5E1A0595 for ; Mon, 23 Oct 2017 17:52:05 +0000 (UTC) X-Virus-Scanned: Debian amavisd-new at spamd2-us-west.apache.org X-Spam-Flag: NO X-Spam-Score: -99.202 X-Spam-Level: X-Spam-Status: No, score=-99.202 tagged_above=-999 required=6.31 tests=[KAM_ASCII_DIVIDERS=0.8, RP_MATCHES_RCVD=-0.001, SPF_PASS=-0.001, USER_IN_WHITELIST=-100] autolearn=disabled Received: from mx1-lw-eu.apache.org ([10.40.0.8]) by localhost (spamd2-us-west.apache.org [10.40.0.9]) (amavisd-new, port 10024) with ESMTP id 01hBTmYph1fb for ; Mon, 23 Oct 2017 17:52:03 +0000 (UTC) Received: from mailrelay1-us-west.apache.org (mailrelay1-us-west.apache.org [209.188.14.139]) by mx1-lw-eu.apache.org (ASF Mail Server at mx1-lw-eu.apache.org) with ESMTP id 31FC45FE43 for ; Mon, 23 Oct 2017 17:52:02 +0000 (UTC) Received: from jira-lw-us.apache.org (unknown [207.244.88.139]) by mailrelay1-us-west.apache.org (ASF Mail Server at mailrelay1-us-west.apache.org) with ESMTP id 0D0D4E0F7B for ; Mon, 23 Oct 2017 17:52:01 +0000 (UTC) Received: from jira-lw-us.apache.org (localhost [127.0.0.1]) by jira-lw-us.apache.org (ASF Mail Server at jira-lw-us.apache.org) with ESMTP id 71ED22438E for ; Mon, 23 Oct 2017 17:52:00 +0000 (UTC) Date: Mon, 23 Oct 2017 17:52:00 +0000 (UTC) From: "ASF GitHub Bot (JIRA)" To: issues@geode.apache.org Message-ID: In-Reply-To: References: Subject: [jira] [Commented] (GEODE-3888) Add lucene queries with the java API to the lucene example MIME-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: 7bit X-JIRA-FingerPrint: 30527f35849b9dde25b450d4833f0394 archived-at: Mon, 23 Oct 2017 17:52:07 -0000 [ 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> { - 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.createClientRegionFactory(ClientRegionShortcut.CACHING_PROXY) .create("example-region"); - new Example().accept(region); + insertValues(region); + query(cache); cache.close(); } - @Override - public void accept(Region region) { + private static void query(ClientCache cache) throws LuceneQueryException { + LuceneService lucene = LuceneServiceProvider.get(cache); + LuceneQuery 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 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 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 region = Mocks.region("example-region"); - new Example().accept(region); + public void testInsertEntries() throws Exception { + Map 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)