Return-Path: X-Original-To: apmail-geode-commits-archive@minotaur.apache.org Delivered-To: apmail-geode-commits-archive@minotaur.apache.org Received: from mail.apache.org (hermes.apache.org [140.211.11.3]) by minotaur.apache.org (Postfix) with SMTP id 4A58918C10 for ; Thu, 13 Aug 2015 07:37:40 +0000 (UTC) Received: (qmail 3969 invoked by uid 500); 13 Aug 2015 07:37:40 -0000 Delivered-To: apmail-geode-commits-archive@geode.apache.org Received: (qmail 3937 invoked by uid 500); 13 Aug 2015 07:37:40 -0000 Mailing-List: contact commits-help@geode.incubator.apache.org; run by ezmlm Precedence: bulk List-Help: List-Unsubscribe: List-Post: List-Id: Reply-To: dev@geode.incubator.apache.org Delivered-To: mailing list commits@geode.incubator.apache.org Received: (qmail 3928 invoked by uid 99); 13 Aug 2015 07:37:40 -0000 Received: from Unknown (HELO spamd2-us-west.apache.org) (209.188.14.142) by apache.org (qpsmtpd/0.29) with ESMTP; Thu, 13 Aug 2015 07:37:40 +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 878751A9FB2 for ; Thu, 13 Aug 2015 07:37:39 +0000 (UTC) X-Virus-Scanned: Debian amavisd-new at spamd2-us-west.apache.org X-Spam-Flag: NO X-Spam-Score: 4.301 X-Spam-Level: **** X-Spam-Status: No, score=4.301 tagged_above=-999 required=6.31 tests=[KAM_ASCII_DIVIDERS=0.8, KAM_LAZY_DOMAIN_SECURITY=1, RDNS_NONE=2.5, URIBL_BLOCKED=0.001] autolearn=disabled Received: from mx1-us-west.apache.org ([10.40.0.8]) by localhost (spamd2-us-west.apache.org [10.40.0.9]) (amavisd-new, port 10024) with ESMTP id EcqPhFCoDTSG for ; Thu, 13 Aug 2015 07:37:08 +0000 (UTC) Received: from spamd1-us-west.apache.org (unknown [209.188.14.142]) by mx1-us-west.apache.org (ASF Mail Server at mx1-us-west.apache.org) with ESMTP id BE9C53279B for ; Thu, 13 Aug 2015 03:53:11 +0000 (UTC) Received: from localhost (localhost [127.0.0.1]) by spamd1-us-west.apache.org (ASF Mail Server at spamd1-us-west.apache.org) with ESMTP id 79313DD061 for ; Thu, 13 Aug 2015 03:53:11 +0000 (UTC) X-Virus-Scanned: Debian amavisd-new at spamd1-us-west.apache.org Received: from mx1-us-west.apache.org ([10.40.0.8]) by localhost (spamd1-us-west.apache.org [10.40.0.7]) (amavisd-new, port 10024) with ESMTP id W8uGjox8Kzao for ; Thu, 13 Aug 2015 03:52:58 +0000 (UTC) Received: from spamd1-us-west.apache.org (unknown [209.188.14.142]) by mx1-us-west.apache.org (ASF Mail Server at mx1-us-west.apache.org) with ESMTP id 9A8D032A83 for ; Thu, 13 Aug 2015 02:19:41 +0000 (UTC) Received: from localhost (localhost [127.0.0.1]) by spamd1-us-west.apache.org (ASF Mail Server at spamd1-us-west.apache.org) with ESMTP id 59FCDDCF37 for ; Thu, 13 Aug 2015 02:19:41 +0000 (UTC) X-Virus-Scanned: Debian amavisd-new at spamd1-us-west.apache.org Received: from mx1-us-east.apache.org ([10.40.0.8]) by localhost (spamd1-us-west.apache.org [10.40.0.7]) (amavisd-new, port 10024) with ESMTP id J1uclbejIdWM for ; Thu, 13 Aug 2015 02:19:24 +0000 (UTC) Received: from spamd1-us-west.apache.org (unknown [209.188.14.142]) by mx1-us-east.apache.org (ASF Mail Server at mx1-us-east.apache.org) with ESMTP id 8DC3350F50 for ; Thu, 13 Aug 2015 01:13:33 +0000 (UTC) Received: from localhost (localhost [127.0.0.1]) by spamd1-us-west.apache.org (ASF Mail Server at spamd1-us-west.apache.org) with ESMTP id 1DD75DCE4E for ; Thu, 13 Aug 2015 01:13:33 +0000 (UTC) X-Virus-Scanned: Debian amavisd-new at spamd1-us-west.apache.org Received: from mx1-us-east.apache.org ([10.40.0.8]) by localhost (spamd1-us-west.apache.org [10.40.0.7]) (amavisd-new, port 10024) with ESMTP id U83BMQueg6gJ for ; Thu, 13 Aug 2015 01:13:20 +0000 (UTC) Received: from spamd3-us-west.apache.org (unknown [209.188.14.142]) by mx1-us-east.apache.org (ASF Mail Server at mx1-us-east.apache.org) with ESMTP id DD8F551490 for ; Thu, 13 Aug 2015 00:58:02 +0000 (UTC) Received: from localhost (localhost [127.0.0.1]) by spamd3-us-west.apache.org (ASF Mail Server at spamd3-us-west.apache.org) with ESMTP id 8417D1A16CE for ; Thu, 13 Aug 2015 00:58:02 +0000 (UTC) X-Virus-Scanned: Debian amavisd-new at spamd3-us-west.apache.org Received: from mx1-us-west.apache.org ([10.40.0.8]) by localhost (spamd3-us-west.apache.org [10.40.0.10]) (amavisd-new, port 10024) with ESMTP id Bph_jbayNC_r for ; Thu, 13 Aug 2015 00:57:51 +0000 (UTC) Received: from spamd1-us-west.apache.org (unknown [209.188.14.142]) by mx1-us-west.apache.org (ASF Mail Server at mx1-us-west.apache.org) with ESMTP id 55DDB32773 for ; Thu, 13 Aug 2015 00:48:37 +0000 (UTC) Received: from localhost (localhost [127.0.0.1]) by spamd1-us-west.apache.org (ASF Mail Server at spamd1-us-west.apache.org) with ESMTP id E59BEDCEB4 for ; Thu, 13 Aug 2015 00:48:36 +0000 (UTC) X-Virus-Scanned: Debian amavisd-new at spamd1-us-west.apache.org Received: from mx1-us-east.apache.org ([10.40.0.8]) by localhost (spamd1-us-west.apache.org [10.40.0.7]) (amavisd-new, port 10024) with ESMTP id GZ5ETtNcTSp7 for ; Thu, 13 Aug 2015 00:48:22 +0000 (UTC) Received: from mail.apache.org (hermes.apache.org [140.211.11.3]) by mx1-us-east.apache.org (ASF Mail Server at mx1-us-east.apache.org) with SMTP id 6E9E442F66 for ; Thu, 13 Aug 2015 00:38:15 +0000 (UTC) Received: (qmail 20957 invoked by uid 99); 13 Aug 2015 00:38:14 -0000 Received: from git1-us-west.apache.org (HELO git1-us-west.apache.org) (140.211.11.23) by apache.org (qpsmtpd/0.29) with ESMTP; Thu, 13 Aug 2015 00:38:14 +0000 Received: by git1-us-west.apache.org (ASF Mail Server at git1-us-west.apache.org, from userid 33) id 8506CE0332; Thu, 13 Aug 2015 00:38:14 +0000 (UTC) Content-Type: text/plain; charset="us-ascii" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit From: upthewaterspout@apache.org To: commits@geode.incubator.apache.org Message-Id: <7bdb3d2023db42ccbb0dec0ebec3ab2c@git.apache.org> X-Mailer: ASF-Git Admin Mailer Subject: incubator-geode git commit: Adding gemfire-lucene subdirectory Date: Thu, 13 Aug 2015 00:38:14 +0000 (UTC) Repository: incubator-geode Updated Branches: refs/heads/feature/GEODE-11 5974ffc8e -> a92a47912 Adding gemfire-lucene subdirectory I forgot to add these files in my last checkin, so the LuceneService was simply gone in the previous revision. These files were moved out of gemfire-core. Project: http://git-wip-us.apache.org/repos/asf/incubator-geode/repo Commit: http://git-wip-us.apache.org/repos/asf/incubator-geode/commit/a92a4791 Tree: http://git-wip-us.apache.org/repos/asf/incubator-geode/tree/a92a4791 Diff: http://git-wip-us.apache.org/repos/asf/incubator-geode/diff/a92a4791 Branch: refs/heads/feature/GEODE-11 Commit: a92a4791275756578d75da888db85afb31c3c998 Parents: 5974ffc Author: Dan Smith Authored: Wed Aug 12 17:37:10 2015 -0700 Committer: Dan Smith Committed: Wed Aug 12 17:37:10 2015 -0700 ---------------------------------------------------------------------- gemfire-lucene/build.gradle | 9 ++ .../gemfire/cache/lucene/LuceneIndex.java | 50 ++++++++ .../gemfire/cache/lucene/LuceneQuery.java | 37 ++++++ .../cache/lucene/LuceneQueryFactory.java | 121 +++++++++++++++++++ .../cache/lucene/LuceneQueryResults.java | 29 +++++ .../cache/lucene/LuceneResultStruct.java | 59 +++++++++ .../gemfire/cache/lucene/LuceneService.java | 120 ++++++++++++++++++ .../cache/lucene/internal/LuceneIndexImpl.java | 54 +++++++++ .../lucene/internal/LuceneQueryFactoryImpl.java | 88 ++++++++++++++ .../cache/lucene/internal/LuceneQueryImpl.java | 62 ++++++++++ .../lucene/internal/LuceneQueryResultsImpl.java | 66 ++++++++++ .../lucene/internal/LuceneResultStructImpl.java | 45 +++++++ .../lucene/internal/LuceneServiceImpl.java | 99 +++++++++++++++ 13 files changed, 839 insertions(+) ---------------------------------------------------------------------- http://git-wip-us.apache.org/repos/asf/incubator-geode/blob/a92a4791/gemfire-lucene/build.gradle ---------------------------------------------------------------------- diff --git a/gemfire-lucene/build.gradle b/gemfire-lucene/build.gradle new file mode 100644 index 0000000..b360c59 --- /dev/null +++ b/gemfire-lucene/build.gradle @@ -0,0 +1,9 @@ +dependencies { + provided project(':gemfire-core') + compile 'org.apache.lucene:lucene-analyzers-common:5.0.0' + compile 'org.apache.lucene:lucene-core:5.0.0' + compile 'org.apache.lucene:lucene-queries:5.0.0' + compile 'org.apache.lucene:lucene-queryparser:5.0.0' + + testCompile project(path: ':gemfire-junit', configuration: 'testOutput') +} http://git-wip-us.apache.org/repos/asf/incubator-geode/blob/a92a4791/gemfire-lucene/src/main/java/com/gemstone/gemfire/cache/lucene/LuceneIndex.java ---------------------------------------------------------------------- diff --git a/gemfire-lucene/src/main/java/com/gemstone/gemfire/cache/lucene/LuceneIndex.java b/gemfire-lucene/src/main/java/com/gemstone/gemfire/cache/lucene/LuceneIndex.java new file mode 100644 index 0000000..9b08b05 --- /dev/null +++ b/gemfire-lucene/src/main/java/com/gemstone/gemfire/cache/lucene/LuceneIndex.java @@ -0,0 +1,50 @@ +/*========================================================================= + * Copyright (c) 2002-2014 Pivotal Software, Inc. All Rights Reserved. + * This product is protected by U.S. and international copyright + * and intellectual property laws. Pivotal products are covered by + * more patents listed at http://www.pivotal.io/patents. + *======================================================================== + */ + +package com.gemstone.gemfire.cache.lucene; + +import java.util.Map; +import java.util.Set; + +import org.apache.lucene.analysis.Analyzer; + + +/** + * An lucene index is built over the data stored in a GemFire Region. + *

+ * An index is specified using a index name, field names, region name. + *

+ * The index name and region name together uniquely identifies the lucene index. + *

+ * + * @author Xiaojian Zhou + * @since 8.5 + */ +public interface LuceneIndex { + + /** + * @return the index name of this index + */ + public String getName(); + + /** + * @return the region name for this index + */ + public String getRegionName(); + + /** + * @return the indexed field names in a Set + */ + public String[] getFieldNames(); + + /** + * @return the field to analyzer map + */ + public Map getFieldAnalyzerMap(); + +} http://git-wip-us.apache.org/repos/asf/incubator-geode/blob/a92a4791/gemfire-lucene/src/main/java/com/gemstone/gemfire/cache/lucene/LuceneQuery.java ---------------------------------------------------------------------- diff --git a/gemfire-lucene/src/main/java/com/gemstone/gemfire/cache/lucene/LuceneQuery.java b/gemfire-lucene/src/main/java/com/gemstone/gemfire/cache/lucene/LuceneQuery.java new file mode 100644 index 0000000..0579eef --- /dev/null +++ b/gemfire-lucene/src/main/java/com/gemstone/gemfire/cache/lucene/LuceneQuery.java @@ -0,0 +1,37 @@ +package com.gemstone.gemfire.cache.lucene; + +import java.util.Set; +import com.gemstone.gemfire.cache.lucene.LuceneQueryFactory.ResultType; + +/** + * Provides wrapper object of Lucene's Query object and execute the search. + *

Instances of this interface are created using + * {@link LuceneQueryFactory#create}. + * + */ +public interface LuceneQuery { + /** + * Execute the search and get results. + */ + public LuceneQueryResults search(); + + /** + * Get page size setting of current query. + */ + public int getPageSize(); + + /** + * Get limit size setting of current query. + */ + public int getLimit(); + + /** + * Get result types setting of current query. + */ + public ResultType[] getResultTypes(); + + /** + * Get projected fields setting of current query. + */ + public String[] getProjectedFieldNames(); +} http://git-wip-us.apache.org/repos/asf/incubator-geode/blob/a92a4791/gemfire-lucene/src/main/java/com/gemstone/gemfire/cache/lucene/LuceneQueryFactory.java ---------------------------------------------------------------------- diff --git a/gemfire-lucene/src/main/java/com/gemstone/gemfire/cache/lucene/LuceneQueryFactory.java b/gemfire-lucene/src/main/java/com/gemstone/gemfire/cache/lucene/LuceneQueryFactory.java new file mode 100644 index 0000000..5636ea4 --- /dev/null +++ b/gemfire-lucene/src/main/java/com/gemstone/gemfire/cache/lucene/LuceneQueryFactory.java @@ -0,0 +1,121 @@ +package com.gemstone.gemfire.cache.lucene; + +import org.apache.lucene.analysis.Analyzer; +import org.apache.lucene.queryparser.classic.ParseException; +import org.apache.lucene.search.Query; + +import com.gemstone.gemfire.cache.Cache; +import com.gemstone.gemfire.cache.DiskStore; + +/** + * Factory for creating instances of {@link LuceneQuery}. + * To get an instance of this factory call {@link LuceneService#createLuceneQueryFactory}. + *

+ * To use this factory configure it with the set methods and then + * call {@link #create} to produce a {@link LuceneQuery} instance. + * + * @author Xiaojian Zhou + * @since 8.5 + */ +public interface LuceneQueryFactory { + + /** + * Default query result limit is 100 + */ + public static final int DEFAULT_LIMIT = 100; + + /** + * Default page size of result is 0, which means no pagination + */ + public static final int DEFAULT_PAGESIZE = 0; + + public enum ResultType { + /** + * Query results only contain value, which is the default setting. + * If field projection is specified, use projected fields' values instead of whole domain object + */ + VALUE, + + /** + * Query results contain score + */ + SCORE, + + /** + * Query results contain key + */ + KEY + }; + + /** + * Set page size for a query result. The default page size is 0 which means no pagination. + * If specified negative value, throw IllegalArgumentException + * @param pageSize + * @return itself + */ + LuceneQueryFactory setPageSize(int pageSize); + + /** + * Set max limit of result for a query + * If specified limit is less or equal to zero, throw IllegalArgumentException + * @param limit + * @return itself + */ + LuceneQueryFactory setResultLimit(int limit); + + /** + * set weather to include SCORE, KEY in result + * + * @param resultTypes + * @return itself + */ + LuceneQueryFactory setResultTypes(ResultType... resultTypes); + + /** + * Set a list of fields for result projection. + * + * @param fieldNames + * @return itself + */ + LuceneQueryFactory setProjectionFields(String... fieldNames); + + /** + * Create wrapper object for lucene's QueryParser object. + * The queryString is using lucene QueryParser's syntax. QueryParser is for easy-to-use + * with human understandable syntax. + * + * @param regionName region name + * @param indexName index name + * @param queryString query string in lucene QueryParser's syntax + * @param analyzer lucene Analyzer to parse the queryString + * @return LuceneQuery object + * @throws ParseException + */ + public LuceneQuery create(String indexName, String regionName, String queryString, + Analyzer analyzer) throws ParseException; + + /** + * Create wrapper object for lucene's QueryParser object using default standard analyzer. + * The queryString is using lucene QueryParser's syntax. QueryParser is for easy-to-use + * with human understandable syntax. + * + * @param regionName region name + * @param indexName index name + * @param queryString query string in lucene QueryParser's syntax + * @return LuceneQuery object + * @throws ParseException + */ + public LuceneQuery create(String indexName, String regionName, String queryString) + throws ParseException; + + /** + * Create wrapper object for lucene's Query object. + * Advanced lucene users can customized their own Query object and directly use in this API. + * + * @param regionName region name + * @param indexName index name + * @param query lucene Query object + * @return LuceneQuery object + */ + public LuceneQuery create(String indexName, String regionName, Query query); +} http://git-wip-us.apache.org/repos/asf/incubator-geode/blob/a92a4791/gemfire-lucene/src/main/java/com/gemstone/gemfire/cache/lucene/LuceneQueryResults.java ---------------------------------------------------------------------- diff --git a/gemfire-lucene/src/main/java/com/gemstone/gemfire/cache/lucene/LuceneQueryResults.java b/gemfire-lucene/src/main/java/com/gemstone/gemfire/cache/lucene/LuceneQueryResults.java new file mode 100644 index 0000000..d660a4b --- /dev/null +++ b/gemfire-lucene/src/main/java/com/gemstone/gemfire/cache/lucene/LuceneQueryResults.java @@ -0,0 +1,29 @@ +package com.gemstone.gemfire.cache.lucene; + +import java.util.Collection; +import java.util.List; + +import com.gemstone.gemfire.cache.execute.ResultSender; +import com.gemstone.gemfire.distributed.DistributedMember; + +/** + *

+ * Defines the interface for a container of lucene query result collected from function + * execution.
+ * + * @author Xiaojian Zhou + * @since 8.5 + */ + +public interface LuceneQueryResults { + + /* get next page of result if pagesize is specified in query, otherwise, return null */ + public List getNextPage(); + + /* Is next page of result available */ + public boolean hasNextPage(); + + /* total number of items */ + public int size(); + +} http://git-wip-us.apache.org/repos/asf/incubator-geode/blob/a92a4791/gemfire-lucene/src/main/java/com/gemstone/gemfire/cache/lucene/LuceneResultStruct.java ---------------------------------------------------------------------- diff --git a/gemfire-lucene/src/main/java/com/gemstone/gemfire/cache/lucene/LuceneResultStruct.java b/gemfire-lucene/src/main/java/com/gemstone/gemfire/cache/lucene/LuceneResultStruct.java new file mode 100644 index 0000000..a5b16b7 --- /dev/null +++ b/gemfire-lucene/src/main/java/com/gemstone/gemfire/cache/lucene/LuceneResultStruct.java @@ -0,0 +1,59 @@ +package com.gemstone.gemfire.cache.lucene; + +import java.util.LinkedList; + +/** + *

+ * Abstract data structure for one item in query result. + * + * @author Xiaojian Zhou + * @since 8.5 + */ +public interface LuceneResultStruct { + /** + * Return the value associated with the given field name + * + * @param fieldName the String name of the field + * @return the value associated with the specified field + * @throws IllegalArgumentException If this struct does not have a field named fieldName + */ + public Object getProjectedField(String fieldName); + + /** + * Return key of the entry + * + * @return key + * @throws IllegalArgumentException If this struct does not contain key + */ + public Object getKey(); + + /** + * Return value of the entry + * + * @return value the whole domain object + * @throws IllegalArgumentException If this struct does not contain value + */ + public Object getValue(); + + /** + * Return score of the query + * + * @return score + * @throws IllegalArgumentException If this struct does not contain score + */ + public Double getScore(); + + /** + * Get the types of values ordered list + * Item in the list could be either ResultType, or field name + * @return the array of result types + */ + public Object[] getNames(); + + /** + * Get the values in same order as result types + * @return the array of values + */ + public Object[] getResultValues(); +} + http://git-wip-us.apache.org/repos/asf/incubator-geode/blob/a92a4791/gemfire-lucene/src/main/java/com/gemstone/gemfire/cache/lucene/LuceneService.java ---------------------------------------------------------------------- diff --git a/gemfire-lucene/src/main/java/com/gemstone/gemfire/cache/lucene/LuceneService.java b/gemfire-lucene/src/main/java/com/gemstone/gemfire/cache/lucene/LuceneService.java new file mode 100644 index 0000000..2c16d05 --- /dev/null +++ b/gemfire-lucene/src/main/java/com/gemstone/gemfire/cache/lucene/LuceneService.java @@ -0,0 +1,120 @@ +package com.gemstone.gemfire.cache.lucene; + +import java.util.Collection; +import java.util.Map; + +import org.apache.lucene.analysis.Analyzer; + +import com.gemstone.gemfire.cache.Cache; +import com.gemstone.gemfire.cache.GemFireCache; +import com.gemstone.gemfire.cache.lucene.internal.LuceneServiceImpl; +import com.gemstone.gemfire.internal.cache.extension.Extensible; + +/** + * LuceneService instance is a singleton for each cache. It will be created in cache + * constructor and get its reference via {@link GemFireCache#getLuceneService()}. + * + * It provides handle for managing the {@link LuceneIndex} and create the {@link LuceneQuery} + * via {@link LuceneQueryFactory} + * + *

+ * Example:
+ * + *
+ * At client and server JVM, initializing cache will create the LuceneServiceImpl object, 
+ * which is a singleton at each JVM. 
+ * 
+ * At each server JVM, for data region to create index, create the index on fields with default analyzer:
+ * LuceneIndex index = luceneService.createIndex(indexName, regionName, "field1", "field2", "field3"); 
+ * or create index on fields with specified analyzer:
+ * LuceneIndex index = luceneService.createIndex(indexName, regionName, analyzerPerField);
+ * 
+ * We can also create index via cache.xml or gfsh.
+ * 
+ * At client side, create query and run the search:
+ * 
+ * LuceneQuery query = luceneService.createLuceneQueryFactory().setLimit(200).setPageSize(20)
+ * .setResultTypes(SCORE, VALUE, KEY).setFieldProjection("field1", "field2")
+ * .create(indexName, regionName, querystring, analyzer);
+ * 
+ * The querystring is using lucene's queryparser syntax, such as "field1:zhou* AND field2:gzhou@pivotal.io"
+ *  
+ * LuceneQueryResults results = query.search();
+ * 
+ * If pagination is not specified:
+ * List list = results.getNextPage(); // return all results in one getNextPage() call
+ * or if paging is specified:
+ * if (results.hasNextPage()) {
+ *   List page = results.nextPage(); // return resules page by page
+ * }
+ * 
+ * The item of the list is either the domain object or instance of {@link LuceneResultStruct}
+ * 
+ * + * @author Xiaojian Zhou + * + */ +public interface LuceneService { + + public static LuceneService get(Cache cache) { + synchronized(LuceneService.class) { + Extensible extensible = (Extensible) cache; + LuceneServiceImpl service = (LuceneServiceImpl) extensible.getExtensionPoint().getExtension(LuceneService.class); + if(service == null) { + service = new LuceneServiceImpl(cache); + extensible.getExtensionPoint().addExtension(LuceneService.class, service); + } + + return service; + } + + } + /** + * Create a lucene index using default analyzer. + * + * @param indexName + * @param regionName + * @param fields + * @return LuceneIndex object + */ + public LuceneIndex createIndex(String indexName, String regionName, String... fields); + + /** + * Create a lucene index using specified analyzer per field + * + * @param indexName index name + * @param regionName region name + * @param analyzerPerField analyzer per field map + * @return LuceneIndex object + * + */ + public LuceneIndex createIndex(String indexName, String regionName, + Map analyzerPerField); + + /** + * Destroy the lucene index + * + * @param index index object + */ + public void destroyIndex(LuceneIndex index); + + /** + * Get the lucene index object specified by region name and index name + * @param indexName index name + * @param regionName region name + * @return LuceneIndex object + */ + public LuceneIndex getIndex(String indexName, String regionName); + + /** + * get all the lucene indexes. + * @return all index objects in a Collection + */ + public Collection getAllIndexes(); + + /** + * create LuceneQueryFactory + * @return LuceneQueryFactory object + */ + public LuceneQueryFactory createLuceneQueryFactory(); +} http://git-wip-us.apache.org/repos/asf/incubator-geode/blob/a92a4791/gemfire-lucene/src/main/java/com/gemstone/gemfire/cache/lucene/internal/LuceneIndexImpl.java ---------------------------------------------------------------------- diff --git a/gemfire-lucene/src/main/java/com/gemstone/gemfire/cache/lucene/internal/LuceneIndexImpl.java b/gemfire-lucene/src/main/java/com/gemstone/gemfire/cache/lucene/internal/LuceneIndexImpl.java new file mode 100644 index 0000000..a7bdd99 --- /dev/null +++ b/gemfire-lucene/src/main/java/com/gemstone/gemfire/cache/lucene/internal/LuceneIndexImpl.java @@ -0,0 +1,54 @@ +package com.gemstone.gemfire.cache.lucene.internal; + +import java.util.HashSet; +import java.util.Map; +import java.util.Set; + +import org.apache.lucene.analysis.Analyzer; + +import com.gemstone.gemfire.cache.lucene.LuceneIndex; + +/* wrapper of IndexWriter */ +public class LuceneIndexImpl implements LuceneIndex { + + /* searchable fields should belong to a specific index + */ + HashSet searchableFieldNames; + + HashSet searchablePDXFieldNames; + + @Override + public String getName() { + // TODO Auto-generated method stub + return null; + } + + @Override + public String getRegionName() { + // TODO Auto-generated method stub + return null; + } + + @Override + public String[] getFieldNames() { + // TODO Auto-generated method stub + return null; + } + + public void initialize() { + // TODO Auto-generated method stub + + } + + public void close() { + // TODO Auto-generated method stub + + } + + @Override + public Map getFieldAnalyzerMap() { + // TODO Auto-generated method stub + return null; + } + +} http://git-wip-us.apache.org/repos/asf/incubator-geode/blob/a92a4791/gemfire-lucene/src/main/java/com/gemstone/gemfire/cache/lucene/internal/LuceneQueryFactoryImpl.java ---------------------------------------------------------------------- diff --git a/gemfire-lucene/src/main/java/com/gemstone/gemfire/cache/lucene/internal/LuceneQueryFactoryImpl.java b/gemfire-lucene/src/main/java/com/gemstone/gemfire/cache/lucene/internal/LuceneQueryFactoryImpl.java new file mode 100644 index 0000000..3bd5b0c --- /dev/null +++ b/gemfire-lucene/src/main/java/com/gemstone/gemfire/cache/lucene/internal/LuceneQueryFactoryImpl.java @@ -0,0 +1,88 @@ +package com.gemstone.gemfire.cache.lucene.internal; + +import java.util.HashSet; +import java.util.Set; + +import org.apache.lucene.analysis.Analyzer; +import org.apache.lucene.analysis.standard.StandardAnalyzer; +import org.apache.lucene.queryparser.classic.ParseException; +import org.apache.lucene.queryparser.classic.QueryParser; +import org.apache.lucene.search.Query; + +import com.gemstone.gemfire.cache.lucene.LuceneIndex; +import com.gemstone.gemfire.cache.lucene.LuceneQuery; +import com.gemstone.gemfire.cache.lucene.LuceneQueryFactory; + +public class LuceneQueryFactoryImpl implements LuceneQueryFactory { + private int limit_attr = DEFAULT_LIMIT; + private int pageSize_attr = DEFAULT_PAGESIZE; + private Set resultType_attr = new HashSet(); + private Set projection_fields_attr = new HashSet(); + + /* reference to the index. One index could have multiple Queries, but one Query must belong + * to one index + */ + private LuceneIndex relatedIndex; + + @Override + public LuceneQueryFactory setPageSize(int pageSize) { + this.pageSize_attr = pageSize; + return this; + } + + @Override + public LuceneQueryFactory setResultLimit(int limit) { + this.limit_attr = limit; + return this; + } + + @Override + public LuceneQueryFactory setResultTypes(ResultType... resultTypes) { + if (resultTypes != null) { + for (ResultType resultType:resultTypes) { + this.resultType_attr.add(resultType); + } + } + return this; + } + + @Override + public LuceneQuery create(String indexName, String regionName, + String queryString, Analyzer analyzer) throws ParseException { + QueryParser parser = new QueryParser(null, analyzer); + Query query = parser.parse(queryString); + LuceneQueryImpl luceneQuery = new LuceneQueryImpl(indexName, regionName, limit_attr, pageSize_attr, + resultType_attr, projection_fields_attr, query); + return luceneQuery; + } + + @Override + public LuceneQuery create(String indexName, String regionName, + String queryString) throws ParseException { + StandardAnalyzer analyzer = new StandardAnalyzer(); + return create(indexName, regionName, queryString, analyzer); + } + + @Override + public LuceneQuery create(String indexName, String regionName, + Query query) { + LuceneQueryImpl luceneQuery = new LuceneQueryImpl(indexName, regionName, limit_attr, pageSize_attr, + resultType_attr, projection_fields_attr, query); + return luceneQuery; + } + + public LuceneIndex getRelatedIndex() { + return this.relatedIndex; + } + + @Override + public LuceneQueryFactory setProjectionFields(String... fieldNames) { + if (fieldNames != null) { + for (String fieldName:fieldNames) { + this.projection_fields_attr.add(fieldName); + } + } + return this; + } + +} http://git-wip-us.apache.org/repos/asf/incubator-geode/blob/a92a4791/gemfire-lucene/src/main/java/com/gemstone/gemfire/cache/lucene/internal/LuceneQueryImpl.java ---------------------------------------------------------------------- diff --git a/gemfire-lucene/src/main/java/com/gemstone/gemfire/cache/lucene/internal/LuceneQueryImpl.java b/gemfire-lucene/src/main/java/com/gemstone/gemfire/cache/lucene/internal/LuceneQueryImpl.java new file mode 100644 index 0000000..04025d3 --- /dev/null +++ b/gemfire-lucene/src/main/java/com/gemstone/gemfire/cache/lucene/internal/LuceneQueryImpl.java @@ -0,0 +1,62 @@ +package com.gemstone.gemfire.cache.lucene.internal; + +import java.util.Set; + +import org.apache.lucene.search.Query; + +import com.gemstone.gemfire.cache.lucene.LuceneQuery; +import com.gemstone.gemfire.cache.lucene.LuceneQueryFactory; +import com.gemstone.gemfire.cache.lucene.LuceneQueryFactory.ResultType; +import com.gemstone.gemfire.cache.lucene.LuceneQueryResults; + +public class LuceneQueryImpl implements LuceneQuery { + private int limit = LuceneQueryFactory.DEFAULT_LIMIT; + private int pageSize = LuceneQueryFactory.DEFAULT_PAGESIZE; + private String indexName; + private String regionName; + private Set resultTypes; + + // The projected fields are local to a specific index per Query object. + private Set projectedFieldNames; + + /* the lucene Query object to be wrapped here */ + private Query query; + + LuceneQueryImpl(String indexName, String regionName, int limit, int pageSize, Set resultTypes, + Set projectionFieldNames, Query query) { + this.indexName = indexName; + this.regionName = regionName; + this.limit = limit; + this.pageSize = pageSize; + this.resultTypes = resultTypes; + this.projectedFieldNames = projectionFieldNames; + this.query = query; + } + + @Override + public LuceneQueryResults search() { + // TODO Auto-generated method stub + return null; + } + + @Override + public int getPageSize() { + return this.pageSize; + } + + @Override + public int getLimit() { + return this.limit; + } + + @Override + public ResultType[] getResultTypes() { + return (ResultType[])this.resultTypes.toArray(); + } + + @Override + public String[] getProjectedFieldNames() { + return (String[])this.projectedFieldNames.toArray(); + } + +} http://git-wip-us.apache.org/repos/asf/incubator-geode/blob/a92a4791/gemfire-lucene/src/main/java/com/gemstone/gemfire/cache/lucene/internal/LuceneQueryResultsImpl.java ---------------------------------------------------------------------- diff --git a/gemfire-lucene/src/main/java/com/gemstone/gemfire/cache/lucene/internal/LuceneQueryResultsImpl.java b/gemfire-lucene/src/main/java/com/gemstone/gemfire/cache/lucene/internal/LuceneQueryResultsImpl.java new file mode 100644 index 0000000..ecb6370 --- /dev/null +++ b/gemfire-lucene/src/main/java/com/gemstone/gemfire/cache/lucene/internal/LuceneQueryResultsImpl.java @@ -0,0 +1,66 @@ +package com.gemstone.gemfire.cache.lucene.internal; + +import java.util.Collection; +import java.util.Iterator; +import java.util.List; +import java.util.concurrent.TimeUnit; + +import com.gemstone.gemfire.cache.execute.FunctionException; +import com.gemstone.gemfire.cache.execute.ResultCollector; +import com.gemstone.gemfire.cache.lucene.LuceneQueryResults; +import com.gemstone.gemfire.cache.lucene.LuceneResultStruct; +import com.gemstone.gemfire.distributed.DistributedMember; + +public class LuceneQueryResultsImpl implements LuceneQueryResults, ResultCollector { + + @Override + public Object getResult() throws FunctionException { + // TODO Auto-generated method stub + return null; + } + + @Override + public Object getResult(long timeout, TimeUnit unit) + throws FunctionException, InterruptedException { + // TODO Auto-generated method stub + return null; + } + + @Override + public void addResult(DistributedMember memberID, + Object resultOfSingleExecution) { + // TODO Auto-generated method stub + + } + + @Override + public void endResults() { + // TODO Auto-generated method stub + + } + + @Override + public void clearResults() { + // TODO Auto-generated method stub + + } + + @Override + public List getNextPage() { + // TODO Auto-generated method stub + return null; + } + + @Override + public boolean hasNextPage() { + // TODO Auto-generated method stub + return false; + } + + @Override + public int size() { + // TODO Auto-generated method stub + return 0; + } + +} http://git-wip-us.apache.org/repos/asf/incubator-geode/blob/a92a4791/gemfire-lucene/src/main/java/com/gemstone/gemfire/cache/lucene/internal/LuceneResultStructImpl.java ---------------------------------------------------------------------- diff --git a/gemfire-lucene/src/main/java/com/gemstone/gemfire/cache/lucene/internal/LuceneResultStructImpl.java b/gemfire-lucene/src/main/java/com/gemstone/gemfire/cache/lucene/internal/LuceneResultStructImpl.java new file mode 100644 index 0000000..0db8f97 --- /dev/null +++ b/gemfire-lucene/src/main/java/com/gemstone/gemfire/cache/lucene/internal/LuceneResultStructImpl.java @@ -0,0 +1,45 @@ +package com.gemstone.gemfire.cache.lucene.internal; + +import java.util.LinkedList; + +import com.gemstone.gemfire.cache.lucene.LuceneResultStruct; + +public class LuceneResultStructImpl implements LuceneResultStruct { + + @Override + public Object getProjectedField(String fieldName) { + // TODO Auto-generated method stub + return null; + } + + @Override + public Object getKey() { + // TODO Auto-generated method stub + return null; + } + + @Override + public Object getValue() { + // TODO Auto-generated method stub + return null; + } + + @Override + public Double getScore() { + // TODO Auto-generated method stub + return null; + } + + @Override + public Object[] getNames() { + // TODO Auto-generated method stub + return null; + } + + @Override + public Object[] getResultValues() { + // TODO Auto-generated method stub + return null; + } + +} http://git-wip-us.apache.org/repos/asf/incubator-geode/blob/a92a4791/gemfire-lucene/src/main/java/com/gemstone/gemfire/cache/lucene/internal/LuceneServiceImpl.java ---------------------------------------------------------------------- diff --git a/gemfire-lucene/src/main/java/com/gemstone/gemfire/cache/lucene/internal/LuceneServiceImpl.java b/gemfire-lucene/src/main/java/com/gemstone/gemfire/cache/lucene/internal/LuceneServiceImpl.java new file mode 100644 index 0000000..864de33 --- /dev/null +++ b/gemfire-lucene/src/main/java/com/gemstone/gemfire/cache/lucene/internal/LuceneServiceImpl.java @@ -0,0 +1,99 @@ +package com.gemstone.gemfire.cache.lucene.internal; + +import java.util.Collection; +import java.util.HashMap; +import java.util.Map; + +import org.apache.lucene.analysis.Analyzer; + +import com.gemstone.gemfire.cache.Cache; +import com.gemstone.gemfire.cache.GemFireCache; +import com.gemstone.gemfire.cache.lucene.LuceneIndex; +import com.gemstone.gemfire.cache.lucene.LuceneQueryFactory; +import com.gemstone.gemfire.cache.lucene.LuceneService; +import com.gemstone.gemfire.internal.cache.GemFireCacheImpl; +import com.gemstone.gemfire.internal.cache.extension.Extensible; +import com.gemstone.gemfire.internal.cache.extension.Extension; +import com.gemstone.gemfire.internal.cache.xmlcache.XmlGenerator; +import com.gemstone.gemfire.internal.i18n.LocalizedStrings; + +/** + * Implementation of LuceneService to create lucene index and query. + * + * @author Xiaojian Zhou + * + * @since 8.5 + */ +public class LuceneServiceImpl implements LuceneService, Extension { + private final Cache cache; + + private final HashMap indexMap; + + public LuceneServiceImpl(final Cache cache) { + if (cache == null) { + throw new IllegalStateException(LocalizedStrings.CqService_CACHE_IS_NULL.toLocalizedString()); + } + GemFireCacheImpl gfc = (GemFireCacheImpl) cache; + gfc.getCancelCriterion().checkCancelInProgress(null); + + this.cache = gfc; + + + // Initialize the Map which maintains indexes + this.indexMap = new HashMap(); + } + + public String getUniqueIndexName(String indexName, String regionName) { + String name = indexName+"#"+regionName.replace('/', '_'); + return name; + } + + @Override + public LuceneIndex createIndex(String indexName, String regionName, String... fields) { + // TODO Auto-generated method stub + return null; + } + + @Override + public LuceneIndex getIndex(String indexName, String regionName) { + return indexMap.get(getUniqueIndexName(indexName, regionName)); + } + + @Override + public Collection getAllIndexes() { + return indexMap.values(); + } + + @Override + public LuceneIndex createIndex(String indexName, String regionName, + Map analyzerPerField) { + // TODO Auto-generated method stub + return null; + } + + @Override + public void destroyIndex(LuceneIndex index) { + LuceneIndexImpl indexImpl = (LuceneIndexImpl)index; + indexMap.remove(getUniqueIndexName(index.getName(), index.getRegionName())); + indexImpl.close(); + } + + @Override + public LuceneQueryFactory createLuceneQueryFactory() { + return new LuceneQueryFactoryImpl(); + } + + @Override + public XmlGenerator getXmlGenerator() { + // TODO Auto-generated method stub + return null; + } + + @Override + public void onCreate(Extensible source, + Extensible target) { + // TODO Auto-generated method stub + + } + +}