Package org.infinispan.query.impl
Class CacheQueryImpl<E>
- java.lang.Object
-
- org.infinispan.query.impl.CacheQueryImpl<E>
-
- All Implemented Interfaces:
Iterable<E>,CacheQuery<E>,IndexedQuery<E>
- Direct Known Subclasses:
ClusteredCacheQueryImpl
public class CacheQueryImpl<E> extends Object implements IndexedQuery<E>
Implementation class of the CacheQuery interface.- Author:
- Navin Surtani, Sanne Grinovero <sanne@hibernate.org> (C) 2011 Red Hat Inc., Marko Luksa
-
-
Field Summary
Fields Modifier and Type Field Description protected org.infinispan.AdvancedCache<?,?>cacheprotected KeyTransformationHandlerkeyTransformationHandlerprotected org.infinispan.query.core.impl.PartitionHandlingSupportpartitionHandlingSupportprotected QueryDefinitionqueryDefinition
-
Constructor Summary
Constructors Constructor Description CacheQueryImpl(org.apache.lucene.search.Query luceneQuery, org.hibernate.search.spi.SearchIntegrator searchFactory, org.infinispan.AdvancedCache<?,?> cache, KeyTransformationHandler keyTransformationHandler, org.hibernate.search.query.engine.spi.TimeoutExceptionFactory timeoutExceptionFactory, Class<?> entity)Create a CacheQueryImpl based on a Lucene query.CacheQueryImpl(org.hibernate.search.query.engine.spi.HSQuery hSearchQuery, org.infinispan.AdvancedCache<?,?> cache, KeyTransformationHandler keyTransformationHandler)Create a CacheQueryImpl based on a HSQuery.CacheQueryImpl(QueryDefinition queryDefinition, org.infinispan.AdvancedCache<?,?> cache, KeyTransformationHandler keyTransformationHandler)
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description IndexedQuery<E>disableFullTextFilter(String name)Disable a given filter by its name.org.hibernate.search.filter.FullTextFilterenableFullTextFilter(String name)Enable a given filter by its name.org.apache.lucene.search.Explanationexplain(int documentId)Return the LuceneExplanationobject describing the score computation for the matching object/document in the current queryIndexedQuery<E>filter(org.apache.lucene.search.Filter filter)Takes in a lucene filter and sets it to the filter field in the class.IndexedQuery<E>firstResult(int firstResult)Sets the the result of the given integer value to the first result.org.hibernate.search.query.engine.spi.FacetManagergetFacetManager()intgetResultSize()Gets the total number of results matching the query, ignoring pagination (firstResult, maxResult).ResultIterator<E>iterator()Returns the results of a search as aResultIterator.ResultIterator<E>iterator(FetchOptions fetchOptions)Returns the results of a search as aResultIterator.List<E>list()Returns the results of a search as a list.IndexedQuery<E>maxResults(int maxResults)Sets the maximum number of results to return from the query.IndexedQuery<Object[]>projection(String... fields)Defines the Lucene field names projected and returned in a query result Each field is converted back to it's object representation, an Object[] being returned for each "row"IndexedQuery<E>sort(org.apache.lucene.search.Sort sort)Allows lucene to sort the results.IndexedQuery<E>timeout(long timeout, TimeUnit timeUnit)Set the timeout for this query.-
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
-
Methods inherited from interface java.lang.Iterable
forEach, spliterator
-
-
-
-
Field Detail
-
cache
protected final org.infinispan.AdvancedCache<?,?> cache
-
keyTransformationHandler
protected final KeyTransformationHandler keyTransformationHandler
-
partitionHandlingSupport
protected final org.infinispan.query.core.impl.PartitionHandlingSupport partitionHandlingSupport
-
queryDefinition
protected QueryDefinition queryDefinition
-
-
Constructor Detail
-
CacheQueryImpl
public CacheQueryImpl(org.apache.lucene.search.Query luceneQuery, org.hibernate.search.spi.SearchIntegrator searchFactory, org.infinispan.AdvancedCache<?,?> cache, KeyTransformationHandler keyTransformationHandler, org.hibernate.search.query.engine.spi.TimeoutExceptionFactory timeoutExceptionFactory, Class<?> entity)Create a CacheQueryImpl based on a Lucene query.
-
CacheQueryImpl
public CacheQueryImpl(QueryDefinition queryDefinition, org.infinispan.AdvancedCache<?,?> cache, KeyTransformationHandler keyTransformationHandler)
-
CacheQueryImpl
public CacheQueryImpl(org.hibernate.search.query.engine.spi.HSQuery hSearchQuery, org.infinispan.AdvancedCache<?,?> cache, KeyTransformationHandler keyTransformationHandler)Create a CacheQueryImpl based on a HSQuery.
-
-
Method Detail
-
filter
public IndexedQuery<E> filter(org.apache.lucene.search.Filter filter)
Takes in a lucene filter and sets it to the filter field in the class.- Specified by:
filterin interfaceCacheQuery<E>- Parameters:
filter- - lucene filter
-
getResultSize
public int getResultSize()
Description copied from interface:CacheQueryGets the total number of results matching the query, ignoring pagination (firstResult, maxResult).- Specified by:
getResultSizein interfaceCacheQuery<E>- Returns:
- The result size of the query.
-
sort
public IndexedQuery<E> sort(org.apache.lucene.search.Sort sort)
Description copied from interface:CacheQueryAllows lucene to sort the results. Integers are sorted in descending order.- Specified by:
sortin interfaceCacheQuery<E>- Specified by:
sortin interfaceIndexedQuery<E>- Parameters:
sort- - lucene sort object
-
enableFullTextFilter
public org.hibernate.search.filter.FullTextFilter enableFullTextFilter(String name)
Enable a given filter by its name.- Specified by:
enableFullTextFilterin interfaceCacheQuery<E>- Parameters:
name- of filter.- Returns:
- a FullTextFilter object.
-
disableFullTextFilter
public IndexedQuery<E> disableFullTextFilter(String name)
Disable a given filter by its name.- Specified by:
disableFullTextFilterin interfaceCacheQuery<E>- Parameters:
name- of filter.
-
firstResult
public IndexedQuery<E> firstResult(int firstResult)
Sets the the result of the given integer value to the first result.- Specified by:
firstResultin interfaceCacheQuery<E>- Specified by:
firstResultin interfaceIndexedQuery<E>- Parameters:
firstResult- index to be set.- Throws:
IllegalArgumentException- if the index given is less than zero.
-
maxResults
public IndexedQuery<E> maxResults(int maxResults)
Description copied from interface:IndexedQuerySets the maximum number of results to return from the query. Used for pagination.- Specified by:
maxResultsin interfaceCacheQuery<E>- Specified by:
maxResultsin interfaceIndexedQuery<E>- Parameters:
maxResults- the maximum number of results to return.
-
iterator
public ResultIterator<E> iterator() throws org.hibernate.search.exception.SearchException
Description copied from interface:CacheQueryReturns the results of a search as aResultIterator. This callsCacheQuery.iterator(FetchOptions fetchOptions)with default FetchOptions; this implies eager loading of all results.
-
iterator
public ResultIterator<E> iterator(FetchOptions fetchOptions) throws org.hibernate.search.exception.SearchException
Description copied from interface:CacheQueryReturns the results of a search as aResultIterator. Warning: the return type is an extension ofIteratorwhich introduces aCloseableIterator.close()method. This close method needs to be invoked when the iteration is complete to avoid resource leakage.- Specified by:
iteratorin interfaceCacheQuery<E>- Parameters:
fetchOptions- how to fetch results (see @link FetchOptions)- Returns:
- a QueryResultIterator which can be used to iterate through the results that were found.
- Throws:
org.hibernate.search.exception.SearchException
-
list
public List<E> list() throws org.hibernate.search.exception.SearchException
Description copied from interface:CacheQueryReturns the results of a search as a list.- Specified by:
listin interfaceCacheQuery<E>- Specified by:
listin interfaceIndexedQuery<E>- Returns:
- the results of a search as a list.
- Throws:
org.hibernate.search.exception.SearchException
-
getFacetManager
public org.hibernate.search.query.engine.spi.FacetManager getFacetManager()
- Specified by:
getFacetManagerin interfaceCacheQuery<E>- Returns:
- return the manager for all faceting related operations
-
explain
public org.apache.lucene.search.Explanation explain(int documentId)
Description copied from interface:CacheQueryReturn the LuceneExplanationobject describing the score computation for the matching object/document in the current query- Specified by:
explainin interfaceCacheQuery<E>- Parameters:
documentId- Lucene Document id to be explain. This is NOT the object key- Returns:
- Lucene Explanation
-
projection
public IndexedQuery<Object[]> projection(String... fields)
Description copied from interface:IndexedQueryDefines the Lucene field names projected and returned in a query result Each field is converted back to it's object representation, an Object[] being returned for each "row" A projectable field must be stored in the Lucene index and use aTwoWayFieldBridgeUnless notified in their JavaDoc, all built-in bridges are two-way. All @DocumentId fields are projectable by design. If the projected field is not a projectable field, null is returned in the object[]- Specified by:
projectionin interfaceCacheQuery<E>- Specified by:
projectionin interfaceIndexedQuery<E>- Parameters:
fields- the projected field names- Returns:
thisto allow for method chaining, but the type parameter now becomesObject[]
-
timeout
public IndexedQuery<E> timeout(long timeout, TimeUnit timeUnit)
Description copied from interface:IndexedQuerySet the timeout for this query. If the query hasn't finished processing before the timeout, an exception will be thrown.- Specified by:
timeoutin interfaceCacheQuery<E>- Specified by:
timeoutin interfaceIndexedQuery<E>- Parameters:
timeout- the timeout durationtimeUnit- the time unit of the timeout parameter- Returns:
-
-