Author: navssurtani
Date: 2008-06-03 12:22:30 -0400 (Tue, 03 Jun 2008)
New Revision: 5946
Added:
searchable/trunk/src/main/java/org/jboss/cache/search/QueryResult.java
searchable/trunk/src/main/java/org/jboss/cache/search/QueryResultImpl.java
searchable/trunk/src/main/java/org/jboss/cache/search/Transformer.java
Modified:
searchable/trunk/src/main/java/org/jboss/cache/search/SearchableCache.java
searchable/trunk/src/main/java/org/jboss/cache/search/SearchableCacheImpl.java
searchable/trunk/src/main/java/org/jboss/cache/search/SearchableListener.java
Log:
Created QueryResults, QueryResultsImpl and Transformer.
Added: searchable/trunk/src/main/java/org/jboss/cache/search/QueryResult.java
===================================================================
--- searchable/trunk/src/main/java/org/jboss/cache/search/QueryResult.java
(rev 0)
+++ searchable/trunk/src/main/java/org/jboss/cache/search/QueryResult.java 2008-06-03
16:22:30 UTC (rev 5946)
@@ -0,0 +1,72 @@
+package org.jboss.cache.search;
+
+import org.apache.lucene.search.Filter;
+import org.apache.lucene.search.Sort;
+import org.hibernate.search.FullTextFilter;
+import org.hibernate.search.FullTextQuery;
+
+/**
+ * Created by IntelliJ IDEA.
+ * User: navin
+ * Date: Jun 3, 2008
+ * Time: 3:13:27 PM
+ * To change this template use File | Settings | File Templates.
+ */
+public interface QueryResult {
+
+ /**
+ * Allows to let lucene sort the results. This is useful when you have
+ * additional sort requirements on top of the default lucene ranking.
+ * Without lucene sorting you would have to retrieve the full result set and
+ * order the hibernate objects.
+ *
+ * @param sort The lucene sort object.
+ * @return this for method chaining
+ */
+ FullTextQuery setSort(Sort sort);
+
+ /**
+ * Allows to use lucene filters.
+ * Semi-deprecated? a preferred way is to use the @FullTextFilterDef approach
+ *
+ * @param filter The lucene filter.
+ * @return this for method chaining
+ */
+ FullTextQuery setFilter(Filter filter);
+
+ /**
+ * Returns the number of hits for this search
+ * <p/>
+ * Caution:
+ * The number of results might be slightly different from
+ * <code>list().size()</code> because list() if the index is
+ * not in sync with the database at the time of query.
+ */
+ int getResultSize();
+
+ /**
+ * Enable a given filter by its name. Returns a FullTextFilter object that allows
filter parameter injection
+ */
+ FullTextFilter enableFullTextFilter(String name);
+
+ /**
+ * Disable a given filter by its name
+ */
+ void disableFullTextFilter(String name);
+
+ /**
+ * {link:Query#setFirstResult}
+ */
+ FullTextQuery setFirstResult(int firstResult);
+
+ /**
+ * {link:Query#setMaxResults}
+ */
+ FullTextQuery setMaxResults(int maxResults);
+
+ /**
+ * Defines scrollable result fetch size as well as the JDBC fetch size
+ */
+ FullTextQuery setFetchSize(int i);
+
+}
Added: searchable/trunk/src/main/java/org/jboss/cache/search/QueryResultImpl.java
===================================================================
--- searchable/trunk/src/main/java/org/jboss/cache/search/QueryResultImpl.java
(rev 0)
+++ searchable/trunk/src/main/java/org/jboss/cache/search/QueryResultImpl.java 2008-06-03
16:22:30 UTC (rev 5946)
@@ -0,0 +1,67 @@
+package org.jboss.cache.search;
+
+import org.hibernate.search.FullTextQuery;
+import org.hibernate.search.FullTextFilter;
+import org.apache.lucene.search.Sort;
+import org.apache.lucene.search.Filter;
+import org.apache.lucene.search.Query;
+import org.jboss.cache.Cache;
+
+/**
+ * Created by IntelliJ IDEA.
+ * User: navin
+ * Date: Jun 3, 2008
+ * Time: 3:23:25 PM
+ * To change this template use File | Settings | File Templates.
+ */
+public class QueryResultImpl implements QueryResult
+{
+ private Query query;
+ private Cache cache;
+
+ public QueryResultImpl(Query luceneQuery, Cache cache)
+ {
+ this.query = luceneQuery;
+ this.cache = cache;
+ }
+
+ public FullTextQuery setSort(Sort sort)
+ {
+ return null; //To change body of implemented methods use File | Settings | File
Templates.
+ }
+
+ public FullTextQuery setFilter(Filter filter)
+ {
+ return null; //To change body of implemented methods use File | Settings | File
Templates.
+ }
+
+ public int getResultSize()
+ {
+ return 0; //To change body of implemented methods use File | Settings | File
Templates.
+ }
+
+ public FullTextFilter enableFullTextFilter(String name)
+ {
+ return null; //To change body of implemented methods use File | Settings | File
Templates.
+ }
+
+ public void disableFullTextFilter(String name)
+ {
+ //To change body of implemented methods use File | Settings | File Templates.
+ }
+
+ public FullTextQuery setFirstResult(int firstResult)
+ {
+ return null; //To change body of implemented methods use File | Settings | File
Templates.
+ }
+
+ public FullTextQuery setMaxResults(int maxResults)
+ {
+ return null; //To change body of implemented methods use File | Settings | File
Templates.
+ }
+
+ public FullTextQuery setFetchSize(int i)
+ {
+ return null; //To change body of implemented methods use File | Settings | File
Templates.
+ }
+}
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-03
15:33:49 UTC (rev 5945)
+++ searchable/trunk/src/main/java/org/jboss/cache/search/SearchableCache.java 2008-06-03
16:22:30 UTC (rev 5946)
@@ -3,8 +3,6 @@
import org.apache.lucene.search.Query;
import org.jboss.cache.Cache;
-import java.util.List;
-
/**
* Created by IntelliJ IDEA.
* User: navin
@@ -14,7 +12,7 @@
*/
public interface SearchableCache extends Cache
{
- public List find(Query luceneQuery);
+ public QueryResult find(Query luceneQuery);
}
Modified: searchable/trunk/src/main/java/org/jboss/cache/search/SearchableCacheImpl.java
===================================================================
---
searchable/trunk/src/main/java/org/jboss/cache/search/SearchableCacheImpl.java 2008-06-03
15:33:49 UTC (rev 5945)
+++
searchable/trunk/src/main/java/org/jboss/cache/search/SearchableCacheImpl.java 2008-06-03
16:22:30 UTC (rev 5946)
@@ -12,6 +12,7 @@
import org.jboss.cache.config.Configuration;
import org.jgroups.Address;
+import java.util.ArrayList;
import java.util.List;
import java.util.Map;
import java.util.Set;
@@ -33,11 +34,9 @@
this.cache = cache;
}
- public List find(Query luceneQuery)
+ public QueryResult find(Query luceneQuery)
{
- // TODO: Write up find() method. What does HS do when given the Lucene/Hibernate
query ??
-
- return null; //To change body of implemented methods use File | Settings | File
Templates.
+ return new QueryResultImpl(luceneQuery, cache);
}
public Configuration getConfiguration()
Modified: searchable/trunk/src/main/java/org/jboss/cache/search/SearchableListener.java
===================================================================
---
searchable/trunk/src/main/java/org/jboss/cache/search/SearchableListener.java 2008-06-03
15:33:49 UTC (rev 5945)
+++
searchable/trunk/src/main/java/org/jboss/cache/search/SearchableListener.java 2008-06-03
16:22:30 UTC (rev 5946)
@@ -1,12 +1,13 @@
package org.jboss.cache.search;
+import org.hibernate.search.backend.Work;
+import org.hibernate.search.backend.WorkType;
import org.jboss.cache.notifications.annotation.CacheListener;
-import org.jboss.cache.notifications.annotation.NodeCreated;
import org.jboss.cache.notifications.annotation.NodeModified;
-import org.jboss.cache.notifications.annotation.NodeMoved;
-import org.jboss.cache.notifications.annotation.NodeRemoved;
-import org.jboss.cache.notifications.event.NodeEvent;
+import org.jboss.cache.notifications.event.NodeModifiedEvent;
+import java.util.Map;
+
/**
* Created by IntelliJ IDEA.
* User: navin
@@ -18,15 +19,14 @@
@CacheListener
public class SearchableListener
{
-
- @NodeCreated
- @NodeRemoved
+
@NodeModified
- @NodeMoved
- public void updateLuceneIndexes(NodeEvent event)
+ public void updateLuceneIndexes(NodeModifiedEvent event)
{
if (!event.isPre())
{
+
+
// TODO: Update Lucene Indexes. See Hibernate Search's
FullTextEventListener class for details on what to do.
}
else
@@ -34,4 +34,23 @@
// ignore the event.
}
}
+
+ void handlePutData(NodeModifiedEvent event)
+ {
+ Map dataMap = event.getData();
+
+ for (Object key: dataMap.keySet())
+ {
+ String keyString = (String) key;
+ String docId = Transformer.generateId(event.getFqn(), keyString) ;
+
+ new Work (dataMap.get(key), docId, WorkType.DELETE);
+ new Work (dataMap.get(key), docId, WorkType.ADD);
+
+ //TODO: Add to queue.
+
+ }
+
+
+ }
}
Added: searchable/trunk/src/main/java/org/jboss/cache/search/Transformer.java
===================================================================
--- searchable/trunk/src/main/java/org/jboss/cache/search/Transformer.java
(rev 0)
+++ searchable/trunk/src/main/java/org/jboss/cache/search/Transformer.java 2008-06-03
16:22:30 UTC (rev 5946)
@@ -0,0 +1,34 @@
+package org.jboss.cache.search;
+
+import org.jboss.cache.Fqn;
+
+/**
+ * Created by IntelliJ IDEA.
+ * User: navin
+ * Date: Jun 3, 2008
+ * Time: 2:02:57 PM
+ * To change this template use File | Settings | File Templates.
+ */
+public class Transformer
+{
+ public static Fqn getFqn(String docId)
+ {
+ //TODO: Do the dirty work to convert a given document Id into an Fqn.
+ return null;
+ }
+
+ public static String getKey(String docId)
+ {
+ //TODO: Get the document Id to give back a string.
+ return null;
+ }
+
+ public static String generateId(Fqn fqn, String key)
+ {
+ //TODO: Generate the Id from the given Fqn and key pairing to get a unique String.
+ //TODO: Look at HS documentation to see what can be done about non-String keys.
+ return null;
+ }
+
+
+}
Show replies by date