Package org.infinispan.query
Interface CacheQuery<E>
-
- All Superinterfaces:
Iterable<E>
- All Known Implementing Classes:
org.infinispan.query.impl.CacheQueryImpl
,ClusteredCacheQueryImpl
public interface CacheQuery<E> extends Iterable<E>
A cache-query is what will be returned when the getQuery() method is run onSearchManagerImpl
. This object can have methods such as list, setFirstResult,setMaxResults, setFetchSize, getResultSize and setSort.- Author:
- Manik Surtani, Navin Surtani, Sanne Grinovero <sanne@hibernate.org> (C) 2011 Red Hat Inc., Marko Luksa
- See Also:
SearchManagerImpl.getQuery(org.apache.lucene.search.Query, Class...)
-
-
Method Summary
All Methods Instance Methods Abstract Methods Modifier and Type Method Description CacheQuery<E>
disableFullTextFilter(String name)
Disable a given filter by its name.org.hibernate.search.filter.FullTextFilter
enableFullTextFilter(String name)
Enable a given filter by its name.org.apache.lucene.search.Explanation
explain(int documentId)
Return the LuceneExplanation
object describing the score computation for the matching object/document in the current queryCacheQuery<E>
filter(org.apache.lucene.search.Filter f)
Allows lucene to filter the results.CacheQuery<E>
firstResult(int index)
Sets a result with a given index to the first result.org.hibernate.search.query.engine.spi.FacetManager
getFacetManager()
int
getResultSize()
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.CacheQuery<E>
maxResults(int numResults)
Sets the maximum number of results to the number passed in as a parameter.CacheQuery<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"CacheQuery<E>
sort(org.apache.lucene.search.Sort s)
Allows lucene to sort the results.CacheQuery<E>
timeout(long timeout, TimeUnit timeUnit)
Set the timeout for this query.-
Methods inherited from interface java.lang.Iterable
forEach, spliterator
-
-
-
-
Method Detail
-
list
List<E> list()
Returns the results of a search as a list.- Returns:
- list of objects that were found from the search.
-
iterator
ResultIterator<E> iterator(FetchOptions fetchOptions)
Returns the results of a search as aResultIterator
. Warning: the return type is an extension ofIterator
which introduces aResultIterator.close()
method. This close method needs to be invoked when the iteration is complete to avoid resource leakage.- Parameters:
fetchOptions
- how to fetch results (see @link FetchOptions)- Returns:
- a QueryResultIterator which can be used to iterate through the results that were found.
-
iterator
ResultIterator<E> iterator()
Returns the results of a search as aResultIterator
. This callsiterator(FetchOptions fetchOptions)
with default FetchOptions; this implies eager loading of all results.
-
firstResult
CacheQuery<E> firstResult(int index)
Sets a result with a given index to the first result.- Parameters:
index
- of result to be set to the first.- Throws:
IllegalArgumentException
- if the index given is less than zero.
-
maxResults
CacheQuery<E> maxResults(int numResults)
Sets the maximum number of results to the number passed in as a parameter.- Parameters:
numResults
- that are to be set to the maxResults.
-
getFacetManager
org.hibernate.search.query.engine.spi.FacetManager getFacetManager()
- Returns:
- return the manager for all faceting related operations
-
getResultSize
int getResultSize()
Gets the total number of results matching the query, ignoring pagination (firstResult, maxResult).- Returns:
- total number of results.
-
explain
org.apache.lucene.search.Explanation explain(int documentId)
Return the LuceneExplanation
object describing the score computation for the matching object/document in the current query- Parameters:
documentId
- Lucene Document id to be explain. This is NOT the object key- Returns:
- Lucene Explanation
-
sort
CacheQuery<E> sort(org.apache.lucene.search.Sort s)
Allows lucene to sort the results. Integers are sorted in descending order.- Parameters:
s
- - lucene sort object
-
projection
CacheQuery<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" A projectable field must be stored in the Lucene index and use aTwoWayFieldBridge
Unless 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[]- Parameters:
fields
- the projected field names- Returns:
this
to allow for method chaining, but the type parameter now becomesObject[]
-
enableFullTextFilter
org.hibernate.search.filter.FullTextFilter enableFullTextFilter(String name)
Enable a given filter by its name.- Parameters:
name
- of filter.- Returns:
- a FullTextFilter object.
-
disableFullTextFilter
CacheQuery<E> disableFullTextFilter(String name)
Disable a given filter by its name.- Parameters:
name
- of filter.
-
filter
CacheQuery<E> filter(org.apache.lucene.search.Filter f)
Allows lucene to filter the results.- Parameters:
f
- - lucene filter
-
timeout
CacheQuery<E> timeout(long timeout, TimeUnit timeUnit)
Set the timeout for this query. If the query hasn't finished processing before the timeout, an exception will be thrown.- Parameters:
timeout
- the timeout durationtimeUnit
- the time unit of the timeout parameter- Returns:
-
-