[jbosscache-commits] JBoss Cache SVN: r6018 - searchable/trunk/src/main/java/org/jboss/cache/search.

jbosscache-commits at lists.jboss.org jbosscache-commits at lists.jboss.org
Wed Jun 25 06:53:33 EDT 2008


Author: navssurtani
Date: 2008-06-25 06:53:33 -0400 (Wed, 25 Jun 2008)
New Revision: 6018

Added:
   searchable/trunk/src/main/java/org/jboss/cache/search/QueryResultIteratorImpl.java
Modified:
   searchable/trunk/src/main/java/org/jboss/cache/search/CacheQuery.java
   searchable/trunk/src/main/java/org/jboss/cache/search/CacheQueryImpl.java
   searchable/trunk/src/main/java/org/jboss/cache/search/SearchableCache.java
Log:
Created QueryResultIteratorImpl and fixed CacheQueryImpl

Modified: searchable/trunk/src/main/java/org/jboss/cache/search/CacheQuery.java
===================================================================
--- searchable/trunk/src/main/java/org/jboss/cache/search/CacheQuery.java	2008-06-25 09:32:57 UTC (rev 6017)
+++ searchable/trunk/src/main/java/org/jboss/cache/search/CacheQuery.java	2008-06-25 10:53:33 UTC (rev 6018)
@@ -14,7 +14,7 @@
 {
    List<Object> list();
 
-   QueryResultIterator iterator();
+   QueryResultIterator iterate();
 
    void setFirstResult(int index);
 

Modified: searchable/trunk/src/main/java/org/jboss/cache/search/CacheQueryImpl.java
===================================================================
--- searchable/trunk/src/main/java/org/jboss/cache/search/CacheQueryImpl.java	2008-06-25 09:32:57 UTC (rev 6017)
+++ searchable/trunk/src/main/java/org/jboss/cache/search/CacheQueryImpl.java	2008-06-25 10:53:33 UTC (rev 6018)
@@ -5,41 +5,43 @@
 import org.apache.lucene.index.IndexReader;
 import org.apache.lucene.index.Term;
 import org.apache.lucene.search.*;
-import org.apache.lucene.search.Query;
-import org.apache.lucene.search.Filter;
-import org.hibernate.*;
-import org.hibernate.annotations.common.util.ReflectHelper;
-import org.hibernate.impl.AbstractQueryImpl;
-import org.hibernate.impl.CriteriaImpl;
-import org.hibernate.type.Type;
-import org.hibernate.transform.ResultTransformer;
+import org.hibernate.Criteria;
+import org.hibernate.HibernateException;
+import org.hibernate.LockMode;
+import org.hibernate.ScrollableResults;
 import org.hibernate.search.FullTextFilter;
 import org.hibernate.search.FullTextQuery;
 import org.hibernate.search.SearchException;
-import org.hibernate.search.engine.*;
+import org.hibernate.search.engine.DocumentBuilder;
+import org.hibernate.search.engine.DocumentExtractor;
+import org.hibernate.search.engine.FilterDef;
+import org.hibernate.search.engine.SearchFactoryImplementor;
 import org.hibernate.search.filter.ChainedFilter;
 import org.hibernate.search.filter.FilterKey;
 import org.hibernate.search.impl.SearchFactoryImpl;
 import org.hibernate.search.query.FullTextFilterImpl;
-import org.hibernate.search.query.IteratorImpl;
 import org.hibernate.search.reader.ReaderProvider;
 import static org.hibernate.search.reader.ReaderProviderHelper.getIndexReaders;
 import org.hibernate.search.store.DirectoryProvider;
+import org.hibernate.transform.ResultTransformer;
 import org.jboss.cache.Cache;
 
 import java.io.IOException;
-import java.io.Serializable;
 import java.lang.reflect.InvocationTargetException;
-import java.util.*;
-import java.math.BigDecimal;
-import java.math.BigInteger;
+import java.util.ArrayList;
+import java.util.Collections;
+import java.util.HashMap;
+import java.util.HashSet;
+import java.util.List;
+import java.util.Map;
+import java.util.Set;
 
 /**
  * @author Navin Surtani  - navin at surtani.org
  *         <p/>
  *         Implementation class of the FullTextQuery interface in Hibernate Search.
  */
-public class CacheQueryImpl extends AbstractQueryImpl implements FullTextQuery
+public class CacheQueryImpl implements CacheQuery
 {
    private Cache cache;
    private Class[] classes;
@@ -62,7 +64,6 @@
 
    public CacheQueryImpl(Query luceneQuery, SearchFactoryImpl searchFactory, Cache cache)
    {
-      super(luceneQuery.toString(), null, null, null);
       this.luceneQuery = luceneQuery;
       this.cache = cache;
       entityLoader = new CacheEntityLoader(cache);
@@ -82,31 +83,8 @@
    }
 
 
-   /**
-    * Allows to let lucene sort the results.
-    *
-    * @param sort
-    * @return
-    */
-   public FullTextQuery setSort(Sort sort)
-   {
-      this.sort = sort;
-      return this;
-   }
 
    /**
-    * Allows to use lucene filters.
-    *
-    * @param filter
-    * @return
-    */
-   public FullTextQuery setFilter(Filter filter)
-   {
-      this.filter = filter;
-      return this;
-   }
-
-   /**
     * @return The result size of the query.
     */
    public int getResultSize()
@@ -141,6 +119,11 @@
       return this.resultSize;
    }
 
+   public void setSort(Sort s)
+   {
+      sort = s;
+   }
+
    /**
     * This method is not supported in JBossCache Searchable and should not be called.
     */
@@ -212,16 +195,15 @@
     * @param firstResult
     * @return
     */
-   public FullTextQuery setFirstResult(int firstResult)
+   public void setFirstResult(int firstResult)
    {
       if (firstResult < 0) {
          throw new IllegalArgumentException("'first' pagination parameter less than 0");
       }
       this.firstResult = firstResult;
-      return this;
    }
 
-   public Iterator iterate() throws HibernateException
+   public QueryResultIterator iterate() throws HibernateException
    {
       List list;
       IndexSearcher searcher = buildSearcher(searchFactory);
@@ -251,15 +233,12 @@
       }
 
       finally {
-         try {
+
             closeSearcher(searcher, searchFactory.getReaderProvider());
-         }
-         catch (SearchException e) {
-            log.warn("Unable to properly close searcher during lucene query: " + getQueryString(), e);
-         }
+
       }
 
-      return new SearchResultIterator(list, entityLoader);
+      return new QueryResultIteratorImpl(list, entityLoader);
    }
 
    public ScrollableResults scroll() throws HibernateException
@@ -296,11 +275,8 @@
       return null;
    }
 
-   public ScrollableResults scroll(ScrollMode scrollMode) throws HibernateException
-   {
-      return null;  // TODO: Implement me!!!
-   }
 
+
    /**
     * Returns a the results from the query as a List object.
     *
@@ -345,12 +321,9 @@
 
       }
       finally {
-         try {
             closeSearcher(searcher, searchFactory.getReaderProvider());
-         }
-         catch (SearchException e) {
-            log.warn("Unable to properly close searcher during lucene query: " + getQueryString(), e);
-         }
+
+
       }
 
    }
@@ -421,22 +394,20 @@
       throw new UnsupportedOperationException(" This method is not supported in JBossCache Searchable");
    }
 
-   public FullTextQuery setMaxResults(int maxResults)
+   public void setMaxResults(int maxResults)
    {
       if (maxResults < 0) {
          throw new IllegalArgumentException("'max' pagination parameter less than 0");
       }
       this.maxResults = maxResults;
-      return this;
    }
 
-   public FullTextQuery setFetchSize(int fetchSize)
+   public void setFetchSize(int fetchSize)
    {
       if (fetchSize <= 0) {
          throw new IllegalArgumentException("'fetch size' parameter less than or equals to 0");
       }
       this.fetchSize = fetchSize;
-      return this;
    }
 
    public org.hibernate.Query setLockMode(String alias, LockMode lockMode)

Added: searchable/trunk/src/main/java/org/jboss/cache/search/QueryResultIteratorImpl.java
===================================================================
--- searchable/trunk/src/main/java/org/jboss/cache/search/QueryResultIteratorImpl.java	                        (rev 0)
+++ searchable/trunk/src/main/java/org/jboss/cache/search/QueryResultIteratorImpl.java	2008-06-25 10:53:33 UTC (rev 6018)
@@ -0,0 +1,116 @@
+package org.jboss.cache.search;
+
+import org.jboss.cache.Cache;
+
+import java.util.List;
+
+/**
+ * This is the implementation class for the interface QueryResultIterator. It is what is returned when the iterate()
+ * method is run on a CacheQuery instance.
+ *
+ * @author Navin Surtani  - navin at surtani.org
+ */
+public class QueryResultIteratorImpl implements QueryResultIterator
+{
+   private Cache cache;
+   private int index = 0;
+   //private final int size;
+   private Object next;
+   private int nextObjectIndex = -1;
+   private List<Object> list;
+
+   public QueryResultIteratorImpl(List list, CacheEntityLoader entityLoader)
+   {
+      this.list = list;
+   }
+
+   public void jumpToResult(int index) throws IndexOutOfBoundsException
+   {
+      //TODO: Implement
+   }
+
+   public void first()
+   {
+      //TODO: Implement
+   }
+
+   public void last()
+   {
+      //TODO: Implement
+   }
+
+   public void afterFirst()
+   {
+      //TODO: Implement
+   }
+
+   public void beforeLast()
+   {
+      //TODO: Implement
+   }
+
+   public boolean isFirst()
+   {
+      return false;  //TODO: Implement
+   }
+
+   public boolean isLast()
+   {
+      return false;  //TODO: Implement
+   }
+
+   public boolean isAfterFirst()
+   {
+      return false;  //TODO: Implement
+   }
+
+   public boolean isBeforeLast()
+   {
+      return false;  //TODO: Implement
+   }
+
+   public boolean hasNext()
+   {
+      return false;  //TODO: Implement
+   }
+
+   public Object next()
+   {
+      return null;  //TODO: Implement
+   }
+
+   public boolean hasPrevious()
+   {
+      return false;  //TODO: Implement
+   }
+
+   public Object previous()
+   {
+      return null;  //TODO: Implement
+   }
+
+   public int nextIndex()
+   {
+      return 0;  //TODO: Implement
+   }
+
+   public int previousIndex()
+   {
+      return 0;  //TODO: Implement
+   }
+
+   public void remove()
+   {
+      //TODO: Implement
+   }
+
+   public void set(Object o)
+   {
+      //TODO: Implement
+   }
+
+   public void add(Object o)
+   {
+      //TODO: Implement
+   }
+}

Modified: searchable/trunk/src/main/java/org/jboss/cache/search/SearchableCache.java
===================================================================
--- searchable/trunk/src/main/java/org/jboss/cache/search/SearchableCache.java	2008-06-25 09:32:57 UTC (rev 6017)
+++ searchable/trunk/src/main/java/org/jboss/cache/search/SearchableCache.java	2008-06-25 10:53:33 UTC (rev 6018)
@@ -1,7 +1,6 @@
 package org.jboss.cache.search;
 
 import org.apache.lucene.search.Query;
-import org.hibernate.search.FullTextQuery;
 import org.jboss.cache.Cache;
 
 /**
@@ -17,20 +16,20 @@
 {
 
    /**
-    * Creates a FullTextQuery object from a luceneQuery.
+    * Creates a CacheQuery object from a luceneQuery.
     *
     * @param luceneQuery
     * @return
     */
-   public FullTextQuery createQuery(Query luceneQuery);
+   public CacheQuery createQuery(Query luceneQuery);
 
    /**
-    * Creates a FullTextQuery from a lucene query and a class array.
+    * Creates a CacheQuery from a lucene query and a class array.
     *
     * @param luceneQuery
     * @param classes
     * @return
     */
-   public FullTextQuery createQuery(Query luceneQuery, Class... classes);
+   public CacheQuery createQuery(Query luceneQuery, Class... classes);
 
 }




More information about the jbosscache-commits mailing list