geode-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From upthewatersp...@apache.org
Subject incubator-geode git commit: Adding gemfire-lucene subdirectory
Date Thu, 13 Aug 2015 00:38:14 GMT
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 <upthewaterspout@apache.org>
Authored: Wed Aug 12 17:37:10 2015 -0700
Committer: Dan Smith <upthewaterspout@apache.org>
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.
+ * <p>
+ * An index is specified using a index name, field names, region name.
+ * <p>
+ * The index name and region name together uniquely identifies the lucene index.
+ * <p>
+ * 
+ * @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<String, Analyzer> 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. 
+ * <p>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}.
+ * <P>
+ * To use this factory configure it with the <code>set</code> 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;
+
+/**
+ * <p>
+ * Defines the interface for a container of lucene query result collected from function
+ * execution.<br>
+ * 
+ * @author Xiaojian Zhou
+ * @since 8.5
+ */
+
+public interface LuceneQueryResults<E> {
+
+  /* get next page of result if pagesize is specified in query, otherwise, return null */
+  public List<E> 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;
+
+/**
+ * <p>
+ * 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}
+ * 
+ * </p>
+ * Example: <br>
+ * 
+ * <pre>
+ * 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}
+ * </pre>
+ * 
+ * @author Xiaojian Zhou
+ *
+ */
+public interface LuceneService {
+  
+  public static LuceneService get(Cache cache) {
+    synchronized(LuceneService.class) {
+      Extensible<Cache> extensible = (Extensible<Cache>) 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<String, Analyzer> 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<LuceneIndex> 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<String> searchableFieldNames;
+  
+  HashSet<String> 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<String, Analyzer> 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> resultType_attr = new HashSet<ResultType>();
+  private Set<String> projection_fields_attr = new HashSet<String>();
+  
+  /* 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<ResultType> resultTypes;
+  
+  // The projected fields are local to a specific index per Query object. 
+  private Set<String> projectedFieldNames;
+  
+  /* the lucene Query object to be wrapped here */
+  private Query query;
+  
+  LuceneQueryImpl(String indexName, String regionName, int limit, int pageSize, Set<ResultType>
resultTypes, 
+      Set<String> 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<E> implements LuceneQueryResults<E>, 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<Cache> {
+  private final Cache cache;
+
+  private final HashMap<String, LuceneIndex>  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<String, LuceneIndex>();
+  }
+  
+  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<LuceneIndex> getAllIndexes() {
+    return indexMap.values();
+  }
+
+  @Override
+  public LuceneIndex createIndex(String indexName, String regionName, 
+      Map<String, Analyzer> 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<Cache> getXmlGenerator() {
+    // TODO Auto-generated method stub
+    return null;
+  }
+
+  @Override
+  public void onCreate(Extensible<Cache> source,
+      Extensible<Cache> target) {
+    // TODO Auto-generated method stub
+    
+  }
+
+}


Mime
View raw message