geode-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From n...@apache.org
Subject geode git commit: GEODE-2956: Trimmed analyzer strings in create index
Date Tue, 23 May 2017 05:02:44 GMT
Repository: geode
Updated Branches:
  refs/heads/develop 8782f0b73 -> d88d2de96


GEODE-2956: Trimmed analyzer strings in create index

	This closes #524


Project: http://git-wip-us.apache.org/repos/asf/geode/repo
Commit: http://git-wip-us.apache.org/repos/asf/geode/commit/d88d2de9
Tree: http://git-wip-us.apache.org/repos/asf/geode/tree/d88d2de9
Diff: http://git-wip-us.apache.org/repos/asf/geode/diff/d88d2de9

Branch: refs/heads/develop
Commit: d88d2de96cea615ba278f3503ea5f7757d3f2e14
Parents: 8782f0b
Author: David Anuta <david.r.anuta@gmail.com>
Authored: Mon May 22 17:10:25 2017 -0700
Committer: nabarunnag <nag@cs.wisc.edu>
Committed: Mon May 22 21:50:03 2017 -0700

----------------------------------------------------------------------
 .../functions/LuceneCreateIndexFunction.java    |  9 ++++--
 .../LuceneIndexCreationIntegrationTest.java     |  2 ++
 .../cli/LuceneIndexCommandsDUnitTest.java       | 33 ++++++++++++++++++++
 3 files changed, 42 insertions(+), 2 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/geode/blob/d88d2de9/geode-lucene/src/main/java/org/apache/geode/cache/lucene/internal/cli/functions/LuceneCreateIndexFunction.java
----------------------------------------------------------------------
diff --git a/geode-lucene/src/main/java/org/apache/geode/cache/lucene/internal/cli/functions/LuceneCreateIndexFunction.java
b/geode-lucene/src/main/java/org/apache/geode/cache/lucene/internal/cli/functions/LuceneCreateIndexFunction.java
index a5ec7d5..9f938a5 100644
--- a/geode-lucene/src/main/java/org/apache/geode/cache/lucene/internal/cli/functions/LuceneCreateIndexFunction.java
+++ b/geode-lucene/src/main/java/org/apache/geode/cache/lucene/internal/cli/functions/LuceneCreateIndexFunction.java
@@ -96,8 +96,13 @@ public class LuceneCreateIndexFunction extends FunctionAdapter implements
Intern
   private Analyzer toAnalyzer(String className) {
     if (className == null)
       className = StandardAnalyzer.class.getCanonicalName();
-    else if (StringUtils.trim(className).equals("") | StringUtils.trim(className).equals("null"))
-      className = StandardAnalyzer.class.getCanonicalName();
+    else {
+      String trimmedClassName = StringUtils.trim(className);
+      if (trimmedClassName.equals("") || trimmedClassName.equals("null"))
+        className = StandardAnalyzer.class.getCanonicalName();
+      else
+        className = trimmedClassName;
+    }
 
     Class<? extends Analyzer> clazz =
         CliUtil.forName(className, LuceneCliStrings.LUCENE_CREATE_INDEX__ANALYZER);

http://git-wip-us.apache.org/repos/asf/geode/blob/d88d2de9/geode-lucene/src/test/java/org/apache/geode/cache/lucene/LuceneIndexCreationIntegrationTest.java
----------------------------------------------------------------------
diff --git a/geode-lucene/src/test/java/org/apache/geode/cache/lucene/LuceneIndexCreationIntegrationTest.java
b/geode-lucene/src/test/java/org/apache/geode/cache/lucene/LuceneIndexCreationIntegrationTest.java
index 2fea5d5..b590afb 100644
--- a/geode-lucene/src/test/java/org/apache/geode/cache/lucene/LuceneIndexCreationIntegrationTest.java
+++ b/geode-lucene/src/test/java/org/apache/geode/cache/lucene/LuceneIndexCreationIntegrationTest.java
@@ -43,6 +43,7 @@ import org.apache.geode.cache.lucene.internal.LuceneIndexImplFactory;
 import org.apache.geode.cache.lucene.internal.LuceneRawIndex;
 import org.apache.geode.cache.lucene.internal.LuceneRawIndexFactory;
 import org.apache.geode.cache.lucene.internal.LuceneServiceImpl;
+import org.apache.geode.cache.lucene.internal.xml.LuceneIndexCreation;
 import org.apache.geode.cache.lucene.test.LuceneTestUtilities;
 import org.apache.geode.cache.lucene.test.TestObject;
 import org.apache.geode.internal.cache.BucketNotFoundException;
@@ -77,6 +78,7 @@ public class LuceneIndexCreationIntegrationTest extends LuceneIntegrationTest
{
   @Rule
   public ExpectedException expectedException = ExpectedException.none();
 
+
   @Test
   public void shouldCreateIndexWriterWithAnalyzersWhenSettingPerFieldAnalyzers()
       throws BucketNotFoundException, InterruptedException {

http://git-wip-us.apache.org/repos/asf/geode/blob/d88d2de9/geode-lucene/src/test/java/org/apache/geode/cache/lucene/internal/cli/LuceneIndexCommandsDUnitTest.java
----------------------------------------------------------------------
diff --git a/geode-lucene/src/test/java/org/apache/geode/cache/lucene/internal/cli/LuceneIndexCommandsDUnitTest.java
b/geode-lucene/src/test/java/org/apache/geode/cache/lucene/internal/cli/LuceneIndexCommandsDUnitTest.java
index 9ef3f28..c96f846 100755
--- a/geode-lucene/src/test/java/org/apache/geode/cache/lucene/internal/cli/LuceneIndexCommandsDUnitTest.java
+++ b/geode-lucene/src/test/java/org/apache/geode/cache/lucene/internal/cli/LuceneIndexCommandsDUnitTest.java
@@ -198,6 +198,39 @@ public class LuceneIndexCommandsDUnitTest extends CliCommandTestBase
{
   }
 
   @Test
+  public void createIndexShouldTrimAnalyzerNames() throws Exception {
+    final VM vm1 = Host.getHost(0).getVM(-1);
+    vm1.invoke(() -> {
+      getCache();
+    });
+
+    List<String> analyzerNames = new ArrayList<>();
+    analyzerNames.add(StandardAnalyzer.class.getCanonicalName());
+    analyzerNames.add(KeywordAnalyzer.class.getCanonicalName());
+    analyzerNames.add(StandardAnalyzer.class.getCanonicalName());
+
+
+    CommandStringBuilder csb = new CommandStringBuilder(LuceneCliStrings.LUCENE_CREATE_INDEX);
+    csb.addOption(LuceneCliStrings.LUCENE__INDEX_NAME, INDEX_NAME);
+    csb.addOption(LuceneCliStrings.LUCENE__REGION_PATH, REGION_NAME);
+    csb.addOption(LuceneCliStrings.LUCENE_CREATE_INDEX__FIELD, "field1,field2,field3");
+    csb.addOption(LuceneCliStrings.LUCENE_CREATE_INDEX__ANALYZER,
+        "\"org.apache.lucene.analysis.standard.StandardAnalyzer, org.apache.lucene.analysis.core.KeywordAnalyzer,
org.apache.lucene.analysis.standard.StandardAnalyzer\"");
+
+    String resultAsString = executeCommandAndLogResult(csb);
+
+    vm1.invoke(() -> {
+      LuceneService luceneService = LuceneServiceProvider.get(getCache());
+      createRegion();
+      final LuceneIndex index = luceneService.getIndex(INDEX_NAME, REGION_NAME);
+      final Map<String, Analyzer> fieldAnalyzers = index.getFieldAnalyzers();
+      assertEquals(StandardAnalyzer.class, fieldAnalyzers.get("field1").getClass());
+      assertEquals(KeywordAnalyzer.class, fieldAnalyzers.get("field2").getClass());
+      assertEquals(StandardAnalyzer.class, fieldAnalyzers.get("field3").getClass());
+    });
+  }
+
+  @Test
   public void createIndexWithoutRegionShouldReturnCorrectResults() throws Exception {
     final VM vm1 = Host.getHost(0).getVM(1);
     vm1.invoke(() -> {


Mime
View raw message