geode-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From hiteshkhame...@apache.org
Subject [90/97] [abbrv] incubator-geode git commit: GEODE-11: Passing down defaultField to query parser
Date Wed, 15 Jun 2016 16:43:11 GMT
GEODE-11: Passing down defaultField to query parser


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

Branch: refs/heads/GEODE-1372
Commit: d5dae19b2d595403ddc1d2344e5fa3cf0bbc32a6
Parents: 79cba4d
Author: Jason Huynh <huynhja@gmail.com>
Authored: Tue Jun 14 08:13:07 2016 -0700
Committer: Jason Huynh <huynhja@gmail.com>
Committed: Tue Jun 14 14:56:42 2016 -0700

----------------------------------------------------------------------
 .../cache/lucene/LuceneQueryFactory.java        |  3 +-
 .../cache/lucene/LuceneQueryProvider.java       |  1 +
 .../lucene/internal/LuceneQueryFactoryImpl.java |  4 +--
 .../cache/lucene/internal/LuceneQueryImpl.java  |  3 +-
 .../lucene/internal/StringQueryProvider.java    | 11 +++++--
 ...IndexCreationPersistenceIntegrationTest.java | 33 ++++++++++----------
 .../LuceneIndexMaintenanceIntegrationTest.java  | 14 ++++-----
 .../gemfire/cache/lucene/LuceneQueriesBase.java | 29 ++++++++++++++++-
 .../lucene/LuceneQueriesIntegrationTest.java    | 27 ++++++++--------
 ...LuceneQueriesPersistenceIntegrationTest.java | 15 +--------
 .../LuceneQueryFactoryImplJUnitTest.java        |  6 ++--
 .../LuceneQueryImplIntegrationTest.java         |  5 ++-
 .../internal/StringQueryProviderJUnitTest.java  | 19 ++++++++---
 .../LuceneFunctionContextJUnitTest.java         |  3 +-
 .../distributed/LuceneFunctionJUnitTest.java    |  4 +--
 .../TopEntriesFunctionCollectorJUnitTest.java   |  6 ++--
 .../IndexRepositoryImplPerformanceTest.java     |  2 +-
 .../cache/lucene/test/LuceneTestUtilities.java  |  1 +
 18 files changed, 109 insertions(+), 77 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/incubator-geode/blob/d5dae19b/geode-lucene/src/main/java/com/gemstone/gemfire/cache/lucene/LuceneQueryFactory.java
----------------------------------------------------------------------
diff --git a/geode-lucene/src/main/java/com/gemstone/gemfire/cache/lucene/LuceneQueryFactory.java
b/geode-lucene/src/main/java/com/gemstone/gemfire/cache/lucene/LuceneQueryFactory.java
index 198961a..a7844a2 100644
--- a/geode-lucene/src/main/java/com/gemstone/gemfire/cache/lucene/LuceneQueryFactory.java
+++ b/geode-lucene/src/main/java/com/gemstone/gemfire/cache/lucene/LuceneQueryFactory.java
@@ -76,12 +76,13 @@ public interface LuceneQueryFactory {
    * @param regionName region name
    * @param indexName index name
    * @param queryString query string in lucene QueryParser's syntax
+   * @param defaultField default field used by the Lucene Query Parser
    * @param <K> the key type in the query results
    * @param <V> the value type in the query results
    * @return LuceneQuery object
    * @throws ParseException
    */
-  public <K, V> LuceneQuery<K, V> create(String indexName, String regionName,
String queryString) 
+  public <K, V> LuceneQuery<K, V> create(String indexName, String regionName,
String queryString, String defaultField)
       throws ParseException;
 
   /**

http://git-wip-us.apache.org/repos/asf/incubator-geode/blob/d5dae19b/geode-lucene/src/main/java/com/gemstone/gemfire/cache/lucene/LuceneQueryProvider.java
----------------------------------------------------------------------
diff --git a/geode-lucene/src/main/java/com/gemstone/gemfire/cache/lucene/LuceneQueryProvider.java
b/geode-lucene/src/main/java/com/gemstone/gemfire/cache/lucene/LuceneQueryProvider.java
index ef60158..92a3a1c 100644
--- a/geode-lucene/src/main/java/com/gemstone/gemfire/cache/lucene/LuceneQueryProvider.java
+++ b/geode-lucene/src/main/java/com/gemstone/gemfire/cache/lucene/LuceneQueryProvider.java
@@ -42,4 +42,5 @@ public interface LuceneQueryProvider extends Serializable {
    * @throws QueryException if the provider fails to construct the query object
    */
   public Query getQuery(LuceneIndex index) throws QueryException;
+
 }

http://git-wip-us.apache.org/repos/asf/incubator-geode/blob/d5dae19b/geode-lucene/src/main/java/com/gemstone/gemfire/cache/lucene/internal/LuceneQueryFactoryImpl.java
----------------------------------------------------------------------
diff --git a/geode-lucene/src/main/java/com/gemstone/gemfire/cache/lucene/internal/LuceneQueryFactoryImpl.java
b/geode-lucene/src/main/java/com/gemstone/gemfire/cache/lucene/internal/LuceneQueryFactoryImpl.java
index 385b226..62b4f56 100644
--- a/geode-lucene/src/main/java/com/gemstone/gemfire/cache/lucene/internal/LuceneQueryFactoryImpl.java
+++ b/geode-lucene/src/main/java/com/gemstone/gemfire/cache/lucene/internal/LuceneQueryFactoryImpl.java
@@ -48,8 +48,8 @@ public class LuceneQueryFactoryImpl implements LuceneQueryFactory {
   }
 
   @Override
-  public <K, V> LuceneQuery<K, V> create(String indexName, String regionName,
String queryString) {
-    return create(indexName, regionName, new StringQueryProvider(queryString));
+  public <K, V> LuceneQuery<K, V> create(String indexName, String regionName,
String queryString, String defaultField) {
+    return create(indexName, regionName, new StringQueryProvider(queryString, defaultField));
   }
   
   public <K, V> LuceneQuery<K, V> create(String indexName, String regionName,
LuceneQueryProvider provider) {

http://git-wip-us.apache.org/repos/asf/incubator-geode/blob/d5dae19b/geode-lucene/src/main/java/com/gemstone/gemfire/cache/lucene/internal/LuceneQueryImpl.java
----------------------------------------------------------------------
diff --git a/geode-lucene/src/main/java/com/gemstone/gemfire/cache/lucene/internal/LuceneQueryImpl.java
b/geode-lucene/src/main/java/com/gemstone/gemfire/cache/lucene/internal/LuceneQueryImpl.java
index a876b40..c6b8878 100644
--- a/geode-lucene/src/main/java/com/gemstone/gemfire/cache/lucene/internal/LuceneQueryImpl.java
+++ b/geode-lucene/src/main/java/com/gemstone/gemfire/cache/lucene/internal/LuceneQueryImpl.java
@@ -42,8 +42,9 @@ public class LuceneQueryImpl<K, V> implements LuceneQuery<K, V>
{
   /* the lucene Query object to be wrapped here */
   private LuceneQueryProvider query;
   private Region<K, V> region;
+  private String defaultField;
   
-  public LuceneQueryImpl(String indexName, Region<K, V> region, LuceneQueryProvider
provider, String[] projectionFields, 
+  public LuceneQueryImpl(String indexName, Region<K, V> region, LuceneQueryProvider
provider, String[] projectionFields,
       int limit, int pageSize) {
     this.indexName = indexName;
     this.region = region;

http://git-wip-us.apache.org/repos/asf/incubator-geode/blob/d5dae19b/geode-lucene/src/main/java/com/gemstone/gemfire/cache/lucene/internal/StringQueryProvider.java
----------------------------------------------------------------------
diff --git a/geode-lucene/src/main/java/com/gemstone/gemfire/cache/lucene/internal/StringQueryProvider.java
b/geode-lucene/src/main/java/com/gemstone/gemfire/cache/lucene/internal/StringQueryProvider.java
index 2ccd58d..3f121ec 100644
--- a/geode-lucene/src/main/java/com/gemstone/gemfire/cache/lucene/internal/StringQueryProvider.java
+++ b/geode-lucene/src/main/java/com/gemstone/gemfire/cache/lucene/internal/StringQueryProvider.java
@@ -52,12 +52,15 @@ public class StringQueryProvider implements LuceneQueryProvider, DataSerializabl
   // the following members hold derived objects and need not be serialized
   private transient Query luceneQuery;
 
+  private String defaultField;
+
   public StringQueryProvider() {
-    this(null);
+    this(null, null);
   }
 
-  public StringQueryProvider(String query) {
+  public StringQueryProvider(String query, String defaultField) {
     this.query = query;
+    this.defaultField = defaultField;
   }
 
   @Override
@@ -68,7 +71,7 @@ public class StringQueryProvider implements LuceneQueryProvider, DataSerializabl
       LuceneIndexImpl indexImpl = (LuceneIndexImpl) index;
       StandardQueryParser parser = new StandardQueryParser(indexImpl.getAnalyzer());
       try {
-        luceneQuery = parser.parse(query, fields[0]);
+        luceneQuery = parser.parse(query, defaultField);
         if (logger.isDebugEnabled()) {
           logger.debug("User query " + query + " is parsed to be: " + luceneQuery);
         }
@@ -100,10 +103,12 @@ public class StringQueryProvider implements LuceneQueryProvider, DataSerializabl
   @Override
   public void toData(DataOutput out) throws IOException {
     DataSerializer.writeString(query, out);
+    DataSerializer.writeString(defaultField, out);
   }
 
   @Override
   public void fromData(DataInput in) throws IOException, ClassNotFoundException {
     query = DataSerializer.readString(in);
+    defaultField = DataSerializer.readString(in);
   }
 }

http://git-wip-us.apache.org/repos/asf/incubator-geode/blob/d5dae19b/geode-lucene/src/test/java/com/gemstone/gemfire/cache/lucene/LuceneIndexCreationPersistenceIntegrationTest.java
----------------------------------------------------------------------
diff --git a/geode-lucene/src/test/java/com/gemstone/gemfire/cache/lucene/LuceneIndexCreationPersistenceIntegrationTest.java
b/geode-lucene/src/test/java/com/gemstone/gemfire/cache/lucene/LuceneIndexCreationPersistenceIntegrationTest.java
index 26426ca..552278e 100644
--- a/geode-lucene/src/test/java/com/gemstone/gemfire/cache/lucene/LuceneIndexCreationPersistenceIntegrationTest.java
+++ b/geode-lucene/src/test/java/com/gemstone/gemfire/cache/lucene/LuceneIndexCreationPersistenceIntegrationTest.java
@@ -20,13 +20,22 @@ package com.gemstone.gemfire.cache.lucene;
 
 import static com.gemstone.gemfire.cache.RegionShortcut.*;
 import static com.gemstone.gemfire.cache.lucene.test.LuceneTestUtilities.*;
-import static junitparams.JUnitParamsRunner.$;
+import static junitparams.JUnitParamsRunner.*;
 import static org.junit.Assert.*;
 
 import java.io.File;
 import java.util.concurrent.TimeUnit;
 import java.util.function.Consumer;
 
+import com.jayway.awaitility.Awaitility;
+import junitparams.JUnitParamsRunner;
+import junitparams.Parameters;
+import org.apache.lucene.queryparser.classic.ParseException;
+import org.junit.Rule;
+import org.junit.Test;
+import org.junit.experimental.categories.Category;
+import org.junit.runner.RunWith;
+
 import com.gemstone.gemfire.cache.Region;
 import com.gemstone.gemfire.cache.RegionShortcut;
 import com.gemstone.gemfire.cache.asyncqueue.AsyncEventQueue;
@@ -36,16 +45,6 @@ import com.gemstone.gemfire.internal.cache.GemFireCacheImpl;
 import com.gemstone.gemfire.internal.cache.LocalRegion;
 import com.gemstone.gemfire.test.junit.categories.IntegrationTest;
 import com.gemstone.gemfire.test.junit.rules.DiskDirRule;
-import com.jayway.awaitility.Awaitility;
-
-import org.apache.lucene.queryparser.classic.ParseException;
-import org.junit.Rule;
-import org.junit.Test;
-import org.junit.experimental.categories.Category;
-import org.junit.runner.RunWith;
-
-import junitparams.JUnitParamsRunner;
-import junitparams.Parameters;
 
 /**
  * Tests of lucene index creation that use persistence
@@ -109,7 +108,7 @@ public class LuceneIndexCreationPersistenceIntegrationTest extends LuceneIntegra
     verifyIndexFinishFlushing(cache, INDEX_NAME, REGION_NAME);
     LuceneQuery<Object, Object> query = luceneService.createLuceneQueryFactory()
       .create(INDEX_NAME, REGION_NAME,
-        "field1:world");
+        "field1:world", DEFAULT_FIELD);
     assertEquals(1, query.search().size());
   }
 
@@ -127,7 +126,7 @@ public class LuceneIndexCreationPersistenceIntegrationTest extends LuceneIntegra
       .create(REGION_NAME);
     LuceneQuery<Object, Object> query = luceneService.createLuceneQueryFactory()
       .create(INDEX_NAME, REGION_NAME,
-      "field1:world");
+      "field1:world", DEFAULT_FIELD);
     assertEquals(1, query.search().size());
   }
 
@@ -138,8 +137,8 @@ public class LuceneIndexCreationPersistenceIntegrationTest extends LuceneIntegra
     LuceneServiceProvider.get(this.cache).createIndex(INDEX_NAME+"_2", REGION_NAME, "field2");
     Region region = cache.createRegionFactory(shortcut).create(REGION_NAME);
     region.put("key1", new TestObject());
-    verifyQueryResultSize(INDEX_NAME+"_1", REGION_NAME, "field1:world", 1);
-    verifyQueryResultSize(INDEX_NAME+"_2", REGION_NAME, "field2:field", 1);
+    verifyQueryResultSize(INDEX_NAME+"_1", REGION_NAME, "field1:world", DEFAULT_FIELD, 1);
+    verifyQueryResultSize(INDEX_NAME+"_2", REGION_NAME, "field2:field", DEFAULT_FIELD, 1);
   }
 
   @Test
@@ -160,8 +159,8 @@ public class LuceneIndexCreationPersistenceIntegrationTest extends LuceneIntegra
     });
   }
 
-  private void verifyQueryResultSize(String indexName, String regionName, String queryString,
int size) throws ParseException {
-    LuceneQuery query = luceneService.createLuceneQueryFactory().create(indexName, regionName,
queryString);
+  private void verifyQueryResultSize(String indexName, String regionName, String queryString,
String defaultField, int size) throws ParseException {
+    LuceneQuery query = luceneService.createLuceneQueryFactory().create(indexName, regionName,
queryString, defaultField);
     Awaitility.await().atMost(60, TimeUnit.SECONDS).until(() -> {
       assertEquals(size, query.search().size());
     });

http://git-wip-us.apache.org/repos/asf/incubator-geode/blob/d5dae19b/geode-lucene/src/test/java/com/gemstone/gemfire/cache/lucene/LuceneIndexMaintenanceIntegrationTest.java
----------------------------------------------------------------------
diff --git a/geode-lucene/src/test/java/com/gemstone/gemfire/cache/lucene/LuceneIndexMaintenanceIntegrationTest.java
b/geode-lucene/src/test/java/com/gemstone/gemfire/cache/lucene/LuceneIndexMaintenanceIntegrationTest.java
index af8c51f..05b6990 100644
--- a/geode-lucene/src/test/java/com/gemstone/gemfire/cache/lucene/LuceneIndexMaintenanceIntegrationTest.java
+++ b/geode-lucene/src/test/java/com/gemstone/gemfire/cache/lucene/LuceneIndexMaintenanceIntegrationTest.java
@@ -24,16 +24,16 @@ import static org.junit.Assert.*;
 import java.io.Serializable;
 import java.util.concurrent.TimeUnit;
 
+import com.jayway.awaitility.Awaitility;
+import org.junit.Test;
+import org.junit.experimental.categories.Category;
+
 import com.gemstone.gemfire.cache.Region;
 import com.gemstone.gemfire.cache.RegionShortcut;
 import com.gemstone.gemfire.cache.lucene.internal.LuceneIndexForPartitionedRegion;
 import com.gemstone.gemfire.cache.lucene.internal.LuceneIndexStats;
 import com.gemstone.gemfire.cache.lucene.internal.filesystem.FileSystemStats;
 import com.gemstone.gemfire.test.junit.categories.IntegrationTest;
-import com.jayway.awaitility.Awaitility;
-
-import org.junit.Test;
-import org.junit.experimental.categories.Category;
 
 @Category(IntegrationTest.class)
 public class LuceneIndexMaintenanceIntegrationTest extends LuceneIntegrationTest {
@@ -52,7 +52,7 @@ public class LuceneIndexMaintenanceIntegrationTest extends LuceneIntegrationTest
 
     LuceneIndex index = luceneService.getIndex(INDEX_NAME, REGION_NAME);
     index.waitUntilFlushed(WAIT_FOR_FLUSH_TIME);
-    LuceneQuery query = luceneService.createLuceneQueryFactory().create(INDEX_NAME, REGION_NAME,
"description:\"hello world\"");
+    LuceneQuery query = luceneService.createLuceneQueryFactory().create(INDEX_NAME, REGION_NAME,
"description:\"hello world\"", DEFAULT_FIELD);
     LuceneQueryResults<Integer, TestObject> results = query.search();
     assertEquals(3, results.size());
 
@@ -75,7 +75,7 @@ public class LuceneIndexMaintenanceIntegrationTest extends LuceneIntegrationTest
 
     LuceneIndex index = luceneService.getIndex(INDEX_NAME, REGION_NAME);
     index.waitUntilFlushed(WAIT_FOR_FLUSH_TIME);
-    LuceneQuery query = luceneService.createLuceneQueryFactory().create(INDEX_NAME, REGION_NAME,
"description:\"hello world\"");
+    LuceneQuery query = luceneService.createLuceneQueryFactory().create(INDEX_NAME, REGION_NAME,
"description:\"hello world\"", DEFAULT_FIELD);
     LuceneQueryResults<Integer, TestObject> results = query.search();
     assertEquals(3, results.size());
 
@@ -99,7 +99,7 @@ public class LuceneIndexMaintenanceIntegrationTest extends LuceneIntegrationTest
 
     LuceneIndex index = luceneService.getIndex(INDEX_NAME, REGION_NAME);
     index.waitUntilFlushed(WAIT_FOR_FLUSH_TIME);
-    LuceneQuery query = luceneService.createLuceneQueryFactory().create(INDEX_NAME, REGION_NAME,
"description:\"hello world\"");
+    LuceneQuery query = luceneService.createLuceneQueryFactory().create(INDEX_NAME, REGION_NAME,
"description:\"hello world\"", DEFAULT_FIELD);
     LuceneQueryResults<Integer, TestObject> results = query.search();
     assertEquals(3, results.size());
 

http://git-wip-us.apache.org/repos/asf/incubator-geode/blob/d5dae19b/geode-lucene/src/test/java/com/gemstone/gemfire/cache/lucene/LuceneQueriesBase.java
----------------------------------------------------------------------
diff --git a/geode-lucene/src/test/java/com/gemstone/gemfire/cache/lucene/LuceneQueriesBase.java
b/geode-lucene/src/test/java/com/gemstone/gemfire/cache/lucene/LuceneQueriesBase.java
index 92d8e8b..26cd4aa 100644
--- a/geode-lucene/src/test/java/com/gemstone/gemfire/cache/lucene/LuceneQueriesBase.java
+++ b/geode-lucene/src/test/java/com/gemstone/gemfire/cache/lucene/LuceneQueriesBase.java
@@ -70,6 +70,21 @@ public abstract class LuceneQueriesBase extends LuceneDUnitTest {
   }
 
   @Test
+  public void defaultFieldShouldPropogateCorrectlyThroughFunction() {
+    SerializableRunnableIF createIndex = () -> {
+      LuceneService luceneService = LuceneServiceProvider.get(getCache());
+      luceneService.createIndex(INDEX_NAME, REGION_NAME, "text");
+    };
+    dataStore1.invoke(() -> initDataStore(createIndex));
+    dataStore2.invoke(() -> initDataStore(createIndex));
+    accessor.invoke(() -> initAccessor(createIndex));
+    putDataInRegion(accessor);
+    assertTrue(waitForFlushBeforeExecuteTextSearch(accessor, 60000));
+    executeTextSearch(accessor, "world", "text", 3);
+    executeTextSearch(accessor, "world", "noEntriesMapped", 0);
+  }
+
+  @Test
   public void entriesFlushedToIndexAfterWaitForFlushCalled() {
     SerializableRunnableIF createIndex = () -> {
       LuceneService luceneService = LuceneServiceProvider.get(getCache());
@@ -108,7 +123,7 @@ public abstract class LuceneQueriesBase extends LuceneDUnitTest {
 
       LuceneService service = LuceneServiceProvider.get(cache);
       LuceneQuery<Integer, TestObject> query;
-      query = service.createLuceneQueryFactory().create(INDEX_NAME, REGION_NAME, "text:world");
+      query = service.createLuceneQueryFactory().create(INDEX_NAME, REGION_NAME, "text:world",
DEFAULT_FIELD);
       LuceneQueryResults<Integer, TestObject> results = query.search();
       assertEquals(3, results.size());
       List<LuceneResultStruct<Integer, TestObject>> page = results.getNextPage();
@@ -123,6 +138,18 @@ public abstract class LuceneQueriesBase extends LuceneDUnitTest {
     });
   }
 
+  protected void executeTextSearch(VM vm, String queryString, String defaultField, int expectedResultsSize)
{
+    vm.invoke(() -> {
+      Cache cache = getCache();
+
+      LuceneService service = LuceneServiceProvider.get(cache);
+      LuceneQuery<Integer, TestObject> query;
+      query = service.createLuceneQueryFactory().create(INDEX_NAME, REGION_NAME, queryString,
defaultField);
+      LuceneQueryResults<Integer, TestObject> results = query.search();
+      assertEquals(results.size(), expectedResultsSize);
+    });
+  }
+
   protected void putDataInRegion(VM vm) {
     vm.invoke(() -> {
       final Cache cache = getCache();

http://git-wip-us.apache.org/repos/asf/incubator-geode/blob/d5dae19b/geode-lucene/src/test/java/com/gemstone/gemfire/cache/lucene/LuceneQueriesIntegrationTest.java
----------------------------------------------------------------------
diff --git a/geode-lucene/src/test/java/com/gemstone/gemfire/cache/lucene/LuceneQueriesIntegrationTest.java
b/geode-lucene/src/test/java/com/gemstone/gemfire/cache/lucene/LuceneQueriesIntegrationTest.java
index c26997d..536f5c3 100644
--- a/geode-lucene/src/test/java/com/gemstone/gemfire/cache/lucene/LuceneQueriesIntegrationTest.java
+++ b/geode-lucene/src/test/java/com/gemstone/gemfire/cache/lucene/LuceneQueriesIntegrationTest.java
@@ -16,7 +16,8 @@
  */
 package com.gemstone.gemfire.cache.lucene;
 
-import static com.gemstone.gemfire.cache.lucene.test.LuceneTestUtilities.verifyQueryKeys;
+import static com.gemstone.gemfire.cache.lucene.test.LuceneTestUtilities.*;
+import static javax.swing.Action.DEFAULT;
 import static org.hamcrest.Matchers.isA;
 import static org.junit.Assert.assertEquals;
 
@@ -83,28 +84,28 @@ public class LuceneQueriesIntegrationTest extends LuceneIntegrationTest
{
     // but standard analyzer will parse value "one@three" to be "one three"
     // query will be--fields1:"one three"
     // so C will be hit by query
-    verifyQuery("field1:\"one three\"", "A", "C");
+    verifyQuery("field1:\"one three\"", DEFAULT_FIELD, "A", "C");
     
     // standard analyzer will not tokenize by '_'
     // this query string will be parsed as "one_three"
     // query will be--field1:one_three
-    verifyQuery("field1:one_three");
+    verifyQuery("field1:one_three", DEFAULT_FIELD);
     
     // standard analyzer will tokenize by '@'
     // this query string will be parsed as "one" "three"
     // query will be--field1:one field1:three
-    verifyQuery("field1:one@three", "A", "B", "C");
+    verifyQuery("field1:one@three", DEFAULT_FIELD, "A", "B", "C");
     
     // keyword analyzer, this query will only match the entry that exactly matches
     // this query string will be parsed as "one three"
     // but keyword analyzer will parse one@three to be "one three"
     // query will be--field2:one three
-    verifyQuery("field2:\"one three\"", "A");
+    verifyQuery("field2:\"one three\"", DEFAULT_FIELD, "A");
 
     // keyword analyzer without double quote. It should be the same as 
     // with double quote
     // query will be--field2:one@three
-    verifyQuery("field2:one@three", "C");
+    verifyQuery("field2:one@three", DEFAULT_FIELD, "C");
   }
 
   @Test()
@@ -130,9 +131,9 @@ public class LuceneQueriesIntegrationTest extends LuceneIntegrationTest
{
 
     index.waitUntilFlushed(60000);
 
-    verifyQuery("field1:one AND field2:two_four", "A");
-    verifyQuery("field1:one AND field2:two", "A");
-    verifyQuery("field1:three AND field2:four", "A");
+    verifyQuery("field1:one AND field2:two_four", DEFAULT_FIELD, "A");
+    verifyQuery("field1:one AND field2:two", DEFAULT_FIELD, "A");
+    verifyQuery("field1:three AND field2:four", DEFAULT_FIELD, "A");
   }
 
   @Test()
@@ -150,7 +151,7 @@ public class LuceneQueriesIntegrationTest extends LuceneIntegrationTest
{
     region.put("A", new TestObject(value1, null));
     index.waitUntilFlushed(60000);
 
-    verifyQuery("field1:one", "A");
+    verifyQuery("field1:one", DEFAULT_FIELD, "A");
   }
 
   @Test()
@@ -162,7 +163,7 @@ public class LuceneQueriesIntegrationTest extends LuceneIntegrationTest
{
 
     //Create a query that throws an exception
     final LuceneQuery<Object, Object> query = luceneService.createLuceneQueryFactory().create(INDEX_NAME,
REGION_NAME,
-      index -> {
+      (index) -> {
         throw new QueryException("Bad query");
       });
 
@@ -178,9 +179,9 @@ public class LuceneQueriesIntegrationTest extends LuceneIntegrationTest
{
 
   }
 
-  private void verifyQuery(String query, String ... expectedKeys) throws ParseException {
+  private void verifyQuery(String query, String defaultField, String ... expectedKeys) throws
ParseException {
     final LuceneQuery<String, Object> queryWithStandardAnalyzer = luceneService.createLuceneQueryFactory().create(
-      INDEX_NAME, REGION_NAME, query);
+      INDEX_NAME, REGION_NAME, query, defaultField);
 
     verifyQueryKeys(queryWithStandardAnalyzer, expectedKeys);
   }

http://git-wip-us.apache.org/repos/asf/incubator-geode/blob/d5dae19b/geode-lucene/src/test/java/com/gemstone/gemfire/cache/lucene/LuceneQueriesPersistenceIntegrationTest.java
----------------------------------------------------------------------
diff --git a/geode-lucene/src/test/java/com/gemstone/gemfire/cache/lucene/LuceneQueriesPersistenceIntegrationTest.java
b/geode-lucene/src/test/java/com/gemstone/gemfire/cache/lucene/LuceneQueriesPersistenceIntegrationTest.java
index 4bb67d2..6eb222d 100644
--- a/geode-lucene/src/test/java/com/gemstone/gemfire/cache/lucene/LuceneQueriesPersistenceIntegrationTest.java
+++ b/geode-lucene/src/test/java/com/gemstone/gemfire/cache/lucene/LuceneQueriesPersistenceIntegrationTest.java
@@ -18,35 +18,23 @@
  */
 package com.gemstone.gemfire.cache.lucene;
 
-import static com.gemstone.gemfire.cache.RegionShortcut.*;
 import static com.gemstone.gemfire.cache.lucene.test.LuceneTestUtilities.*;
-import static junitparams.JUnitParamsRunner.*;
 import static org.junit.Assert.*;
 
 import java.io.File;
-import java.util.concurrent.TimeUnit;
-import java.util.function.Consumer;
 
 import com.gemstone.gemfire.cache.EvictionAction;
 import com.gemstone.gemfire.cache.EvictionAlgorithm;
-import com.gemstone.gemfire.cache.Region;
 import com.gemstone.gemfire.cache.RegionFactory;
 import com.gemstone.gemfire.cache.RegionShortcut;
-import com.gemstone.gemfire.cache.asyncqueue.AsyncEventQueue;
 import com.gemstone.gemfire.cache.lucene.internal.LuceneServiceImpl;
 import com.gemstone.gemfire.cache.lucene.internal.repository.serializer.Type1;
-import com.gemstone.gemfire.cache.lucene.test.LuceneTestUtilities;
-import com.gemstone.gemfire.cache.lucene.test.TestObject;
 import com.gemstone.gemfire.internal.cache.EvictionAttributesImpl;
 import com.gemstone.gemfire.internal.cache.GemFireCacheImpl;
-import com.gemstone.gemfire.internal.cache.LocalRegion;
 import com.gemstone.gemfire.internal.cache.PartitionedRegion;
-import com.gemstone.gemfire.test.junit.categories.FlakyTest;
 import com.gemstone.gemfire.test.junit.categories.IntegrationTest;
 import com.gemstone.gemfire.test.junit.rules.DiskDirRule;
-import com.jayway.awaitility.Awaitility;
 
-import org.apache.lucene.queryparser.classic.ParseException;
 import org.junit.Assert;
 import org.junit.Rule;
 import org.junit.Test;
@@ -54,7 +42,6 @@ import org.junit.experimental.categories.Category;
 import org.junit.runner.RunWith;
 
 import junitparams.JUnitParamsRunner;
-import junitparams.Parameters;
 
 /**
  * Tests of lucene index creation that use persistence
@@ -108,7 +95,7 @@ public class LuceneQueriesPersistenceIntegrationTest extends LuceneIntegrationTe
     assertNotNull(chunkRegion);
     Assert.assertTrue(0 < userRegion.getDiskRegionStats().getNumOverflowOnDisk());
 
-    LuceneQuery<Integer, Type1> query = service.createLuceneQueryFactory().create(INDEX_NAME,
REGION_NAME, "s:world");
+    LuceneQuery<Integer, Type1> query = service.createLuceneQueryFactory().create(INDEX_NAME,
REGION_NAME, "s:world", DEFAULT_FIELD);
     LuceneQueryResults<Integer, Type1> results = query.search();
     Assert.assertEquals(3, results.size());
   }

http://git-wip-us.apache.org/repos/asf/incubator-geode/blob/d5dae19b/geode-lucene/src/test/java/com/gemstone/gemfire/cache/lucene/internal/LuceneQueryFactoryImplJUnitTest.java
----------------------------------------------------------------------
diff --git a/geode-lucene/src/test/java/com/gemstone/gemfire/cache/lucene/internal/LuceneQueryFactoryImplJUnitTest.java
b/geode-lucene/src/test/java/com/gemstone/gemfire/cache/lucene/internal/LuceneQueryFactoryImplJUnitTest.java
index 975b92f..1dd4aa2 100644
--- a/geode-lucene/src/test/java/com/gemstone/gemfire/cache/lucene/internal/LuceneQueryFactoryImplJUnitTest.java
+++ b/geode-lucene/src/test/java/com/gemstone/gemfire/cache/lucene/internal/LuceneQueryFactoryImplJUnitTest.java
@@ -18,6 +18,7 @@
  */
 package com.gemstone.gemfire.cache.lucene.internal;
 
+import static com.gemstone.gemfire.cache.lucene.test.LuceneTestUtilities.DEFAULT_FIELD;
 import static org.junit.Assert.*;
 import static org.mockito.Matchers.any;
 import static org.mockito.Mockito.*;
@@ -35,6 +36,7 @@ import com.gemstone.gemfire.test.junit.categories.UnitTest;
 
 @Category(UnitTest.class)
 public class LuceneQueryFactoryImplJUnitTest {
+
   @Rule
   public ExpectedException thrown = ExpectedException.none();
 
@@ -48,7 +50,7 @@ public class LuceneQueryFactoryImplJUnitTest {
     f.setResultLimit(25);
     String[] projection = new String[] {"a", "b"};
     f.setProjectionFields(projection);
-    LuceneQuery<Object, Object> query = f.create("index", "region", new StringQueryProvider("test"));
+    LuceneQuery<Object, Object> query = f.create("index", "region", new StringQueryProvider("test",
DEFAULT_FIELD));
     assertEquals(25, query.getLimit());
     assertEquals(5, query.getPageSize());
     assertArrayEquals(projection, query.getProjectedFieldNames());
@@ -61,7 +63,7 @@ public class LuceneQueryFactoryImplJUnitTest {
     Cache cache = mock(Cache.class);
     LuceneQueryFactoryImpl f = new LuceneQueryFactoryImpl(cache);
     thrown.expect(IllegalArgumentException.class);
-    LuceneQuery<Object, Object> query = f.create("index", "region", new StringQueryProvider("test"));
+    LuceneQuery<Object, Object> query = f.create("index", "region", new StringQueryProvider("test",
DEFAULT_FIELD));
   }
 
 }

http://git-wip-us.apache.org/repos/asf/incubator-geode/blob/d5dae19b/geode-lucene/src/test/java/com/gemstone/gemfire/cache/lucene/internal/LuceneQueryImplIntegrationTest.java
----------------------------------------------------------------------
diff --git a/geode-lucene/src/test/java/com/gemstone/gemfire/cache/lucene/internal/LuceneQueryImplIntegrationTest.java
b/geode-lucene/src/test/java/com/gemstone/gemfire/cache/lucene/internal/LuceneQueryImplIntegrationTest.java
index 262efaa..c2e9b0c 100644
--- a/geode-lucene/src/test/java/com/gemstone/gemfire/cache/lucene/internal/LuceneQueryImplIntegrationTest.java
+++ b/geode-lucene/src/test/java/com/gemstone/gemfire/cache/lucene/internal/LuceneQueryImplIntegrationTest.java
@@ -19,6 +19,7 @@
 
 package com.gemstone.gemfire.cache.lucene.internal;
 
+import static com.gemstone.gemfire.cache.lucene.test.LuceneTestUtilities.DEFAULT_FIELD;
 import static org.junit.Assert.assertEquals;
 import static org.junit.Assert.assertTrue;
 
@@ -29,8 +30,6 @@ import org.junit.Before;
 import org.junit.Test;
 import org.junit.experimental.categories.Category;
 
-import com.gemstone.gemfire.cache.Cache;
-import com.gemstone.gemfire.cache.CacheFactory;
 import com.gemstone.gemfire.cache.Region;
 import com.gemstone.gemfire.cache.RegionShortcut;
 import com.gemstone.gemfire.cache.execute.FunctionAdapter;
@@ -68,7 +67,7 @@ public class LuceneQueryImplIntegrationTest extends LuceneIntegrationTest
{
     TestLuceneFunction function = new TestLuceneFunction();
     FunctionService.registerFunction(function);
 
-    StringQueryProvider provider = new StringQueryProvider();
+    StringQueryProvider provider = new StringQueryProvider(null, DEFAULT_FIELD);
     LuceneQueryImpl<Object, Object> query = new LuceneQueryImpl<>("index", region,
provider, null, LIMIT, 20);
     LuceneQueryResults<Object, Object> results = query.search();
 

http://git-wip-us.apache.org/repos/asf/incubator-geode/blob/d5dae19b/geode-lucene/src/test/java/com/gemstone/gemfire/cache/lucene/internal/StringQueryProviderJUnitTest.java
----------------------------------------------------------------------
diff --git a/geode-lucene/src/test/java/com/gemstone/gemfire/cache/lucene/internal/StringQueryProviderJUnitTest.java
b/geode-lucene/src/test/java/com/gemstone/gemfire/cache/lucene/internal/StringQueryProviderJUnitTest.java
index da6715a..a08875a 100644
--- a/geode-lucene/src/test/java/com/gemstone/gemfire/cache/lucene/internal/StringQueryProviderJUnitTest.java
+++ b/geode-lucene/src/test/java/com/gemstone/gemfire/cache/lucene/internal/StringQueryProviderJUnitTest.java
@@ -18,6 +18,7 @@
  */
 package com.gemstone.gemfire.cache.lucene.internal;
 
+import static com.gemstone.gemfire.cache.lucene.test.LuceneTestUtilities.DEFAULT_FIELD;
 import static org.junit.Assert.assertEquals;
 
 import org.apache.lucene.analysis.Analyzer;
@@ -31,7 +32,6 @@ import org.junit.experimental.categories.Category;
 import org.mockito.Mockito;
 
 import com.gemstone.gemfire.CopyHelper;
-import com.gemstone.gemfire.cache.lucene.LuceneIndex;
 import com.gemstone.gemfire.cache.query.QueryException;
 import com.gemstone.gemfire.test.junit.categories.UnitTest;
 
@@ -53,7 +53,7 @@ public class StringQueryProviderJUnitTest {
 
   @Test
   public void testQueryConstruction() throws QueryException {
-    StringQueryProvider provider = new StringQueryProvider("foo:bar");
+    StringQueryProvider provider = new StringQueryProvider("foo:bar", DEFAULT_FIELD);
     Query query = provider.getQuery(mockIndex);
     Assert.assertNotNull(query);
     assertEquals("foo:bar", query.toString());
@@ -62,7 +62,7 @@ public class StringQueryProviderJUnitTest {
   @Test
   @Ignore("Custom analyzer not yet supported, this is a duplicate test right now")
   public void usesCustomAnalyzer() throws QueryException {
-    StringQueryProvider provider = new StringQueryProvider("findThis");
+    StringQueryProvider provider = new StringQueryProvider("findThis", DEFAULT_FIELD);
     Query query = provider.getQuery(mockIndex);
     Assert.assertNotNull(query);
     assertEquals("field-1:findthis field-2:findthis", query.toString());
@@ -70,15 +70,24 @@ public class StringQueryProviderJUnitTest {
 
   @Test(expected = QueryException.class)
   public void errorsOnMalformedQueryString() throws QueryException {
-    StringQueryProvider provider = new StringQueryProvider("invalid:lucene:query:string");
+    StringQueryProvider provider = new StringQueryProvider("invalid:lucene:query:string",
DEFAULT_FIELD);
     provider.getQuery(mockIndex);
   }
   
   @Test
   public void testSerialization() {
     LuceneServiceImpl.registerDataSerializables();
-    StringQueryProvider provider = new StringQueryProvider("text:search");
+    StringQueryProvider provider = new StringQueryProvider("text:search", DEFAULT_FIELD);
     StringQueryProvider copy = CopyHelper.deepCopy(provider);
     assertEquals("text:search", copy.getQueryString());
   }
+
+  @Test
+  public void defaultFieldParameterShouldBeUsedByQuery() throws QueryException {
+    StringQueryProvider provider = new StringQueryProvider("findThis",  "field-2");
+    Query query = provider.getQuery(mockIndex);
+    Assert.assertNotNull(query);
+    assertEquals("field-2:findthis", query.toString());
+  }
+
 }

http://git-wip-us.apache.org/repos/asf/incubator-geode/blob/d5dae19b/geode-lucene/src/test/java/com/gemstone/gemfire/cache/lucene/internal/distributed/LuceneFunctionContextJUnitTest.java
----------------------------------------------------------------------
diff --git a/geode-lucene/src/test/java/com/gemstone/gemfire/cache/lucene/internal/distributed/LuceneFunctionContextJUnitTest.java
b/geode-lucene/src/test/java/com/gemstone/gemfire/cache/lucene/internal/distributed/LuceneFunctionContextJUnitTest.java
index 39a4dde..3b0870e 100644
--- a/geode-lucene/src/test/java/com/gemstone/gemfire/cache/lucene/internal/distributed/LuceneFunctionContextJUnitTest.java
+++ b/geode-lucene/src/test/java/com/gemstone/gemfire/cache/lucene/internal/distributed/LuceneFunctionContextJUnitTest.java
@@ -18,6 +18,7 @@
  */
 package com.gemstone.gemfire.cache.lucene.internal.distributed;
 
+import static com.gemstone.gemfire.cache.lucene.test.LuceneTestUtilities.DEFAULT_FIELD;
 import static org.junit.Assert.*;
 
 import org.junit.Test;
@@ -46,7 +47,7 @@ public class LuceneFunctionContextJUnitTest {
   public void testSerialization() {
     LuceneServiceImpl.registerDataSerializables();
 
-    LuceneQueryProvider provider = new StringQueryProvider("text");
+    LuceneQueryProvider provider = new StringQueryProvider("text", DEFAULT_FIELD);
     CollectorManager<TopEntriesCollector> manager = new TopEntriesCollectorManager("test");
     LuceneFunctionContext<TopEntriesCollector> context = new LuceneFunctionContext<>(provider,
"testIndex", manager, 123);
 

http://git-wip-us.apache.org/repos/asf/incubator-geode/blob/d5dae19b/geode-lucene/src/test/java/com/gemstone/gemfire/cache/lucene/internal/distributed/LuceneFunctionJUnitTest.java
----------------------------------------------------------------------
diff --git a/geode-lucene/src/test/java/com/gemstone/gemfire/cache/lucene/internal/distributed/LuceneFunctionJUnitTest.java
b/geode-lucene/src/test/java/com/gemstone/gemfire/cache/lucene/internal/distributed/LuceneFunctionJUnitTest.java
index c1a64ae..178fae2 100644
--- a/geode-lucene/src/test/java/com/gemstone/gemfire/cache/lucene/internal/distributed/LuceneFunctionJUnitTest.java
+++ b/geode-lucene/src/test/java/com/gemstone/gemfire/cache/lucene/internal/distributed/LuceneFunctionJUnitTest.java
@@ -19,6 +19,7 @@
 
 package com.gemstone.gemfire.cache.lucene.internal.distributed;
 
+import static com.gemstone.gemfire.cache.lucene.test.LuceneTestUtilities.DEFAULT_FIELD;
 import static org.junit.Assert.*;
 import static org.mockito.Mockito.*;
 
@@ -32,7 +33,6 @@ import com.gemstone.gemfire.cache.execute.FunctionException;
 import com.gemstone.gemfire.cache.execute.ResultSender;
 import com.gemstone.gemfire.cache.lucene.LuceneQueryFactory;
 import com.gemstone.gemfire.cache.lucene.LuceneQueryProvider;
-import com.gemstone.gemfire.cache.lucene.internal.InternalLuceneIndex;
 import com.gemstone.gemfire.cache.lucene.internal.InternalLuceneService;
 import com.gemstone.gemfire.cache.lucene.internal.LuceneIndexImpl;
 import com.gemstone.gemfire.cache.lucene.internal.StringQueryProvider;
@@ -272,7 +272,7 @@ public class LuceneFunctionJUnitTest {
     mockCache = mock(InternalCache.class);
     Analyzer analyzer = new StandardAnalyzer();
     Mockito.doReturn(analyzer).when(mockIndex).getAnalyzer();
-    queryProvider = new StringQueryProvider("gemfire:lucene");
+    queryProvider = new StringQueryProvider("gemfire:lucene", DEFAULT_FIELD);
     
     searchArgs = new LuceneFunctionContext<IndexResultCollector>(queryProvider, "indexName");
 

http://git-wip-us.apache.org/repos/asf/incubator-geode/blob/d5dae19b/geode-lucene/src/test/java/com/gemstone/gemfire/cache/lucene/internal/distributed/TopEntriesFunctionCollectorJUnitTest.java
----------------------------------------------------------------------
diff --git a/geode-lucene/src/test/java/com/gemstone/gemfire/cache/lucene/internal/distributed/TopEntriesFunctionCollectorJUnitTest.java
b/geode-lucene/src/test/java/com/gemstone/gemfire/cache/lucene/internal/distributed/TopEntriesFunctionCollectorJUnitTest.java
index b7709bc..372c5a3 100644
--- a/geode-lucene/src/test/java/com/gemstone/gemfire/cache/lucene/internal/distributed/TopEntriesFunctionCollectorJUnitTest.java
+++ b/geode-lucene/src/test/java/com/gemstone/gemfire/cache/lucene/internal/distributed/TopEntriesFunctionCollectorJUnitTest.java
@@ -19,12 +19,10 @@
 
 package com.gemstone.gemfire.cache.lucene.internal.distributed;
 
-import static org.junit.Assert.assertEquals;
+import static org.junit.Assert.*;
 import static org.mockito.Matchers.any;
-import static org.mockito.Mockito.mock;
-import static org.mockito.Mockito.when;
+import static org.mockito.Mockito.*;
 
-import java.io.IOException;
 import java.util.Collection;
 import java.util.concurrent.CountDownLatch;
 import java.util.concurrent.TimeUnit;

http://git-wip-us.apache.org/repos/asf/incubator-geode/blob/d5dae19b/geode-lucene/src/test/java/com/gemstone/gemfire/cache/lucene/internal/repository/IndexRepositoryImplPerformanceTest.java
----------------------------------------------------------------------
diff --git a/geode-lucene/src/test/java/com/gemstone/gemfire/cache/lucene/internal/repository/IndexRepositoryImplPerformanceTest.java
b/geode-lucene/src/test/java/com/gemstone/gemfire/cache/lucene/internal/repository/IndexRepositoryImplPerformanceTest.java
index 15ef449..5e1a104 100644
--- a/geode-lucene/src/test/java/com/gemstone/gemfire/cache/lucene/internal/repository/IndexRepositoryImplPerformanceTest.java
+++ b/geode-lucene/src/test/java/com/gemstone/gemfire/cache/lucene/internal/repository/IndexRepositoryImplPerformanceTest.java
@@ -74,7 +74,7 @@ public class IndexRepositoryImplPerformanceTest {
   private static int NUM_QUERIES = 500_000;
 
   private StandardAnalyzer analyzer = new StandardAnalyzer();
-  
+
   @Test
   public  void testIndexRepository() throws Exception {
     

http://git-wip-us.apache.org/repos/asf/incubator-geode/blob/d5dae19b/geode-lucene/src/test/java/com/gemstone/gemfire/cache/lucene/test/LuceneTestUtilities.java
----------------------------------------------------------------------
diff --git a/geode-lucene/src/test/java/com/gemstone/gemfire/cache/lucene/test/LuceneTestUtilities.java
b/geode-lucene/src/test/java/com/gemstone/gemfire/cache/lucene/test/LuceneTestUtilities.java
index 0cf8953..6ef93bf 100644
--- a/geode-lucene/src/test/java/com/gemstone/gemfire/cache/lucene/test/LuceneTestUtilities.java
+++ b/geode-lucene/src/test/java/com/gemstone/gemfire/cache/lucene/test/LuceneTestUtilities.java
@@ -42,6 +42,7 @@ import com.gemstone.gemfire.internal.cache.LocalRegion;
 public class LuceneTestUtilities {
   public static final String INDEX_NAME = "index";
   public static final String REGION_NAME = "region";
+  public static final String DEFAULT_FIELD = "text";
 
   public static final String CANNOT_CREATE_LUCENE_INDEX_DIFFERENT_FIELDS = "Cannot create
Lucene index index on region /region with fields [field1, field2] because another member defines
the same index with fields [field1].";
   public static final String CANNOT_CREATE_LUCENE_INDEX_NO_ANALYZER_FIELD2 = "Cannot create
Lucene index index on region /region with no analyzer on field field2 because another member
defines the same index with analyzer org.apache.lucene.analysis.core.KeywordAnalyzer on that
field.";



Mime
View raw message