[infinispan-commits] Infinispan SVN: r2198 - in branches/4.1.x/query/src: main/java/org/infinispan/query/impl and 1 other directories.
infinispan-commits at lists.jboss.org
infinispan-commits at lists.jboss.org
Wed Aug 11 10:19:21 EDT 2010
Author: manik.surtani at jboss.com
Date: 2010-08-11 10:19:21 -0400 (Wed, 11 Aug 2010)
New Revision: 2198
Modified:
branches/4.1.x/query/src/main/java/org/infinispan/query/QueryFactory.java
branches/4.1.x/query/src/main/java/org/infinispan/query/impl/CacheQueryImpl.java
branches/4.1.x/query/src/test/java/org/infinispan/query/blackbox/AbstractLocalQueryTest.java
branches/4.1.x/query/src/test/java/org/infinispan/query/blackbox/LocalCacheTest.java
branches/4.1.x/query/src/test/java/org/infinispan/query/blackbox/MarshalledValueQueryTest.java
Log:
[ISPN-593] (Add ability to filter a query with a list of types)
Modified: branches/4.1.x/query/src/main/java/org/infinispan/query/QueryFactory.java
===================================================================
--- branches/4.1.x/query/src/main/java/org/infinispan/query/QueryFactory.java 2010-08-11 14:13:50 UTC (rev 2197)
+++ branches/4.1.x/query/src/main/java/org/infinispan/query/QueryFactory.java 2010-08-11 14:19:21 UTC (rev 2198)
@@ -45,14 +45,17 @@
searchFactory = qh.getSearchFactory();
}
+
/**
- * This is a simple method that will just return a {@link CacheQuery}
+ * This is a simple method that will just return a {@link CacheQuery}, filtered according to a set of classes passed
+ * in. If no classes are passed in, it is assumed that no type filtering is performed.
*
* @param luceneQuery - {@link org.apache.lucene.search.Query}
- * @return the query result
+ * @param classes - only return results of type that matches this list of acceptable types
+ * @return the query object which can be used to iterate through results
*/
- public CacheQuery getQuery(Query luceneQuery) {
- return new CacheQueryImpl(luceneQuery, searchFactory, cache);
+ public CacheQuery getQuery(Query luceneQuery, Class<?>... classes) {
+ return new CacheQueryImpl(luceneQuery, searchFactory, cache, classes);
}
/**
Modified: branches/4.1.x/query/src/main/java/org/infinispan/query/impl/CacheQueryImpl.java
===================================================================
--- branches/4.1.x/query/src/main/java/org/infinispan/query/impl/CacheQueryImpl.java 2010-08-11 14:13:50 UTC (rev 2197)
+++ branches/4.1.x/query/src/main/java/org/infinispan/query/impl/CacheQueryImpl.java 2010-08-11 14:19:21 UTC (rev 2198)
@@ -91,8 +91,11 @@
this.luceneQuery = luceneQuery;
this.cache = cache;
this.searchFactory = searchFactory;
- this.targetedEntities = this.searchFactory.getIndexedTypesPolymorphic(classes);
-
+ if (classes == null || classes.length == 0) {
+ this.targetedEntities = this.searchFactory.getIndexedTypesPolymorphic(new Class[]{});
+ } else {
+ this.targetedEntities = this.searchFactory.getIndexedTypesPolymorphic(classes);
+ }
}
Modified: branches/4.1.x/query/src/test/java/org/infinispan/query/blackbox/AbstractLocalQueryTest.java
===================================================================
--- branches/4.1.x/query/src/test/java/org/infinispan/query/blackbox/AbstractLocalQueryTest.java 2010-08-11 14:13:50 UTC (rev 2197)
+++ branches/4.1.x/query/src/test/java/org/infinispan/query/blackbox/AbstractLocalQueryTest.java 2010-08-11 14:19:21 UTC (rev 2198)
@@ -35,12 +35,15 @@
import org.infinispan.query.QueryFactory;
import org.infinispan.query.QueryIterator;
import org.infinispan.query.backend.QueryHelper;
+import org.infinispan.query.test.AnotherGrassEater;
import org.infinispan.query.test.Person;
import org.infinispan.test.SingleCacheManagerTest;
import org.testng.annotations.AfterMethod;
import java.util.List;
+import static java.util.Arrays.asList;
+
public abstract class AbstractLocalQueryTest extends SingleCacheManagerTest {
protected Person person1;
protected Person person2;
@@ -48,6 +51,7 @@
protected Person person4;
protected Person person5;
protected Person person6;
+ protected AnotherGrassEater anotherGrassEater;
protected QueryParser queryParser;
protected Query luceneQuery;
protected CacheQuery cacheQuery;
@@ -55,8 +59,9 @@
protected String key1 = "Navin";
protected String key2 = "BigGoat";
protected String key3 = "MiniGoat";
+ protected String anotherGrassEaterKey = "anotherGrassEaterKey";
- protected Cache<Object, Person> cache;
+ protected Cache<Object, Object> cache;
protected QueryHelper qh;
@AfterMethod(alwaysRun = true)
@@ -274,10 +279,12 @@
queries[1] = new TermQuery(navin);
luceneQuery = queries[0].combine(queries);
+// luceneQuery = new TermQuery(goat).combine(new Query[]{new TermQuery(navin)});
cacheQuery = new QueryFactory(cache, qh).getQuery(luceneQuery);
// We know that we've got all 3 hits.
- assert cacheQuery.getResultSize() == 3;
+ System.out.println("****** Res " + cacheQuery.list());
+ assert cacheQuery.getResultSize() == 3 : "Expected 3, got " + cacheQuery.getResultSize();
cache.clear();
@@ -285,4 +292,24 @@
assert cacheQuery.getResultSize() == 0;
}
+
+ public void testTypeFiltering() throws ParseException {
+ queryParser = new QueryParser("blurb", new StandardAnalyzer());
+ luceneQuery = queryParser.parse("grass");
+ cacheQuery = new QueryFactory(cache, qh).getQuery(luceneQuery);
+
+ found = cacheQuery.list();
+
+ assert found.size() == 2;
+ assert found.containsAll(asList(person2, anotherGrassEater));
+
+ queryParser = new QueryParser("blurb", new StandardAnalyzer());
+ luceneQuery = queryParser.parse("grass");
+ cacheQuery = new QueryFactory(cache, qh).getQuery(luceneQuery, AnotherGrassEater.class);
+
+ found = cacheQuery.list();
+
+ assert found.size() == 1;
+ assert found.get(0).equals(anotherGrassEater);
+ }
}
Modified: branches/4.1.x/query/src/test/java/org/infinispan/query/blackbox/LocalCacheTest.java
===================================================================
--- branches/4.1.x/query/src/test/java/org/infinispan/query/blackbox/LocalCacheTest.java 2010-08-11 14:13:50 UTC (rev 2197)
+++ branches/4.1.x/query/src/test/java/org/infinispan/query/blackbox/LocalCacheTest.java 2010-08-11 14:19:21 UTC (rev 2198)
@@ -24,6 +24,7 @@
import org.infinispan.config.Configuration;
import org.infinispan.manager.EmbeddedCacheManager;
import org.infinispan.query.helper.TestQueryHelperFactory;
+import org.infinispan.query.test.AnotherGrassEater;
import org.infinispan.query.test.Person;
import org.infinispan.test.fwk.TestCacheManagerFactory;
import org.testng.annotations.BeforeMethod;
@@ -55,7 +56,7 @@
public void setUp() throws Exception {
cache = cacheManager.getCache();
- qh = TestQueryHelperFactory.createTestQueryHelperInstance(cache, Person.class);
+ qh = TestQueryHelperFactory.createTestQueryHelperInstance(cache, Person.class, AnotherGrassEater.class);
person1 = new Person();
person1.setName("Navin Surtani");
@@ -73,11 +74,11 @@
person5.setName("Smelly Cat");
person5.setBlurb("Eats fish");
- //Put the 3 created objects in the cache.
+ anotherGrassEater = new AnotherGrassEater("Another grass-eater", "Eats grass");
+
cache.put(key1, person1);
cache.put(key2, person2);
cache.put(key3, person3);
-
-
+ cache.put(anotherGrassEaterKey, anotherGrassEater);
}
}
Modified: branches/4.1.x/query/src/test/java/org/infinispan/query/blackbox/MarshalledValueQueryTest.java
===================================================================
--- branches/4.1.x/query/src/test/java/org/infinispan/query/blackbox/MarshalledValueQueryTest.java 2010-08-11 14:13:50 UTC (rev 2197)
+++ branches/4.1.x/query/src/test/java/org/infinispan/query/blackbox/MarshalledValueQueryTest.java 2010-08-11 14:19:21 UTC (rev 2198)
@@ -33,7 +33,7 @@
*/
- at Test(groups="functional")
+ at Test(groups="functional", testName = "query.blackbox.MarshalledValueQueryTest")
public class MarshalledValueQueryTest extends LocalCacheTest {
@Override
protected void enhanceConfig(Configuration c) {
More information about the infinispan-commits
mailing list