org.hibernate.search.query.hibernate.impl
Class FullTextQueryImpl

java.lang.Object
  extended by org.hibernate.internal.AbstractQueryImpl
      extended by org.hibernate.search.query.hibernate.impl.FullTextQueryImpl
All Implemented Interfaces:
Query, FullTextQuery, ProjectionConstants

public class FullTextQueryImpl
extends AbstractQueryImpl
implements FullTextQuery

Implementation of FullTextQuery.

Author:
Emmanuel Bernard , Hardy Ferentschik

Field Summary
 
Fields inherited from class org.hibernate.internal.AbstractQueryImpl
parameterMetadata, session
 
Fields inherited from interface org.hibernate.search.ProjectionConstants
DOCUMENT, DOCUMENT_ID, EXPLANATION, ID, OBJECT_CLASS, SCORE, THIS
 
Constructor Summary
FullTextQueryImpl(org.apache.lucene.search.Query query, Class<?>[] classes, SessionImplementor session, ParameterMetadata parameterMetadata)
          Constructs a FullTextQueryImpl instance.
 
Method Summary
 void disableFullTextFilter(String name)
          Disable a given filter by its name.
 FullTextFilter enableFullTextFilter(String name)
          Enable a given filter by its name.
 int executeUpdate()
           
 org.apache.lucene.search.Explanation explain(int documentId)
          Return the Lucene Explanation object describing the score computation for the matching object/document in the current query
 FacetManager getFacetManager()
           
protected  Map getLockModes()
           
 LockOptions getLockOptions()
           
 int getResultSize()
           
 boolean hasPartialResults()
          Experimental API, subject to change or removal
 FullTextQuery initializeObjectsWith(ObjectLookupMethod lookupMethod, DatabaseRetrievalMethod retrievalMethod)
          Refine the strategies used to load entities.
 Iterator iterate()
          Return an iterator on the results.
 FullTextQuery limitExecutionTimeTo(long timeout, TimeUnit timeUnit)
          *Experimental* API, subject to change or removal Limit the time used by Hibernate Search to execute the query.
 List list()
           
 ScrollableResults scroll()
           
 ScrollableResults scroll(ScrollMode scrollMode)
           
 FullTextQuery setCriteriaQuery(Criteria criteria)
          Defines the Database Query used to load the Lucene results.
 FullTextQuery setFetchSize(int fetchSize)
          Defines scrollable result fetch size as well as the JDBC fetch size
 FullTextQuery setFilter(org.apache.lucene.search.Filter filter)
          Allows to use lucene filters.
 FullTextQuery setFirstResult(int firstResult)
          Query.setFirstResult(int)
 Query setLockMode(String alias, LockMode lockMode)
           
 Query setLockOptions(LockOptions lockOptions)
           
 FullTextQuery setMaxResults(int maxResults)
          Query.setMaxResults(int)
 FullTextQuery setProjection(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" (similar to an HQL or a Criteria API projection).
 FullTextQuery setResultTransformer(ResultTransformer transformer)
          defines a result transformer used during projection, the Aliases provided are the projection aliases.
 FullTextQuery setSort(org.apache.lucene.search.Sort sort)
          Allows to let lucene sort the results.
 FullTextQuery setTimeout(int timeout)
           
 FullTextQuery setTimeout(long timeout, TimeUnit timeUnit)
          Define a timeout period for a given unit of time.
<T> T
unwrap(Class<T> type)
           
 
Methods inherited from class org.hibernate.internal.AbstractQueryImpl
after, before, determineType, determineType, determineType, determineType, determineType, expandParameterLists, getCacheMode, getNamedParameterLists, getNamedParameters, getNamedParams, getParameterMetadata, getQueryParameters, getQueryString, getReturnAliases, getReturnTypes, getRowSelection, getSelection, getTypes, getValues, hasNamedParameters, isReadOnly, setBigDecimal, setBigDecimal, setBigInteger, setBigInteger, setBinary, setBinary, setBoolean, setBoolean, setByte, setByte, setCacheable, setCacheMode, setCacheRegion, setCalendar, setCalendar, setCalendarDate, setCalendarDate, setCharacter, setCharacter, setCollectionKey, setComment, setDate, setDate, setDouble, setDouble, setEntity, setEntity, setFloat, setFloat, setFlushMode, setInteger, setInteger, setLocale, setLocale, setLong, setLong, setOptionalEntityName, setOptionalId, setOptionalObject, setParameter, setParameter, setParameter, setParameter, setParameterList, setParameterList, setParameterList, setParameterList, setParameters, setProperties, setProperties, setReadOnly, setSerializable, setSerializable, setShort, setShort, setString, setString, setText, setText, setTime, setTime, setTimestamp, setTimestamp, toString, typeArray, uniqueResult, valueArray, verifyParameters, verifyParameters
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
 
Methods inherited from interface org.hibernate.Query
getNamedParameters, getQueryString, getReturnAliases, getReturnTypes, isReadOnly, setBigDecimal, setBigDecimal, setBigInteger, setBigInteger, setBinary, setBinary, setBoolean, setBoolean, setByte, setByte, setCacheable, setCacheMode, setCacheRegion, setCalendar, setCalendar, setCalendarDate, setCalendarDate, setCharacter, setCharacter, setComment, setDate, setDate, setDouble, setDouble, setEntity, setEntity, setFloat, setFloat, setFlushMode, setInteger, setInteger, setLocale, setLocale, setLong, setLong, setParameter, setParameter, setParameter, setParameter, setParameterList, setParameterList, setParameterList, setParameterList, setParameters, setProperties, setProperties, setReadOnly, setSerializable, setSerializable, setShort, setShort, setString, setString, setText, setText, setTime, setTime, setTimestamp, setTimestamp, uniqueResult
 

Constructor Detail

FullTextQueryImpl

public FullTextQueryImpl(org.apache.lucene.search.Query query,
                         Class<?>[] classes,
                         SessionImplementor session,
                         ParameterMetadata parameterMetadata)
Constructs a FullTextQueryImpl instance.

Parameters:
query - The Lucene query.
classes - Array of classes (must be immutable) used to filter the results to the given class types.
session - Access to the Hibernate session.
parameterMetadata - Additional query metadata.
Method Detail

setSort

public FullTextQuery setSort(org.apache.lucene.search.Sort sort)
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.

Specified by:
setSort in interface FullTextQuery
Parameters:
sort - The lucene sort object.
Returns:
this for method chaining

setFilter

public FullTextQuery setFilter(org.apache.lucene.search.Filter filter)
Allows to use lucene filters. Semi-deprecated? a preferred way is to use the @FullTextFilterDef approach

Specified by:
setFilter in interface FullTextQuery
Parameters:
filter - The lucene filter.
Returns:
this for method chaining

iterate

public Iterator iterate()
                 throws HibernateException
Return an iterator on the results. Retrieve the object one by one (initialize it during the next() operation)

Specified by:
iterate in interface Query
Throws:
HibernateException

scroll

public ScrollableResults scroll()
                         throws HibernateException
Specified by:
scroll in interface Query
Throws:
HibernateException

scroll

public ScrollableResults scroll(ScrollMode scrollMode)
                         throws HibernateException
Specified by:
scroll in interface Query
Throws:
HibernateException

list

public List list()
          throws HibernateException
Specified by:
list in interface Query
Throws:
HibernateException

explain

public org.apache.lucene.search.Explanation explain(int documentId)
Description copied from interface: FullTextQuery
Return the Lucene Explanation object describing the score computation for the matching object/document in the current query

Specified by:
explain in interface FullTextQuery
Parameters:
documentId - Lucene Document id to be explain. This is NOT the object id
Returns:
An Lucene Explanation instance

getResultSize

public int getResultSize()
Specified by:
getResultSize in interface FullTextQuery
Returns:
the number of hits for this search.

Caution: The number of results might be slightly different from list().size() because list() if the index is not in sync with the database at the time of query.


setCriteriaQuery

public FullTextQuery setCriteriaQuery(Criteria criteria)
Description copied from interface: FullTextQuery
Defines the Database Query used to load the Lucene results. Useful to load a given object graph by refining the fetch modes.


setProjection

public FullTextQuery setProjection(String... fields)
Description copied from interface: FullTextQuery
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" (similar to an HQL or a Criteria API projection).

A projectable field must be stored in the Lucene index and use a TwoWayFieldBridge 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[]

Specified by:
setProjection in interface FullTextQuery
Parameters:
fields - list of field names to project on
Returns:
this for method chaining

setFirstResult

public FullTextQuery setFirstResult(int firstResult)
Description copied from interface: FullTextQuery
Query.setFirstResult(int)

Specified by:
setFirstResult in interface Query
Specified by:
setFirstResult in interface FullTextQuery
Overrides:
setFirstResult in class AbstractQueryImpl

setMaxResults

public FullTextQuery setMaxResults(int maxResults)
Description copied from interface: FullTextQuery
Query.setMaxResults(int)

Specified by:
setMaxResults in interface Query
Specified by:
setMaxResults in interface FullTextQuery
Overrides:
setMaxResults in class AbstractQueryImpl

setFetchSize

public FullTextQuery setFetchSize(int fetchSize)
Description copied from interface: FullTextQuery
Defines scrollable result fetch size as well as the JDBC fetch size

Specified by:
setFetchSize in interface Query
Specified by:
setFetchSize in interface FullTextQuery
Overrides:
setFetchSize in class AbstractQueryImpl

setLockOptions

public Query setLockOptions(LockOptions lockOptions)
Specified by:
setLockOptions in interface Query

setResultTransformer

public FullTextQuery setResultTransformer(ResultTransformer transformer)
Description copied from interface: FullTextQuery
defines a result transformer used during projection, the Aliases provided are the projection aliases.

Specified by:
setResultTransformer in interface Query
Specified by:
setResultTransformer in interface FullTextQuery
Overrides:
setResultTransformer in class AbstractQueryImpl

unwrap

public <T> T unwrap(Class<T> type)
Specified by:
unwrap in interface FullTextQuery
Parameters:
type - the type to unwrap
Returns:
the underlying type if possible. If not possible to unwrap to the given type an IllegalArgumentException is thrown. Supported types are:
  • org.apache.lucene.search.Query the underlying lucene query

getLockOptions

public LockOptions getLockOptions()
Specified by:
getLockOptions in class AbstractQueryImpl

executeUpdate

public int executeUpdate()
                  throws HibernateException
Specified by:
executeUpdate in interface Query
Throws:
HibernateException

setLockMode

public Query setLockMode(String alias,
                         LockMode lockMode)
Specified by:
setLockMode in interface Query

getLockModes

protected Map getLockModes()

enableFullTextFilter

public FullTextFilter enableFullTextFilter(String name)
Description copied from interface: FullTextQuery
Enable a given filter by its name.

Specified by:
enableFullTextFilter in interface FullTextQuery
Parameters:
name - the name of the filter to enable
Returns:
Returns a FullTextFilter object that allows filter parameter injection

disableFullTextFilter

public void disableFullTextFilter(String name)
Description copied from interface: FullTextQuery
Disable a given filter by its name.

Specified by:
disableFullTextFilter in interface FullTextQuery
Parameters:
name - the name of the filter to disable.

getFacetManager

public FacetManager getFacetManager()
Specified by:
getFacetManager in interface FullTextQuery
Returns:
return the manager for all faceting related operations

setTimeout

public FullTextQuery setTimeout(int timeout)
Specified by:
setTimeout in interface Query
Overrides:
setTimeout in class AbstractQueryImpl

setTimeout

public FullTextQuery setTimeout(long timeout,
                                TimeUnit timeUnit)
Description copied from interface: FullTextQuery
Define a timeout period for a given unit of time. Note that this is time out is on a best effort basis. When the query goes beyond the timeout, a QueryTimeoutException is raised.

Specified by:
setTimeout in interface FullTextQuery
Parameters:
timeout - time out period
timeUnit - time out unit
Returns:
this to allow method chaining

limitExecutionTimeTo

public FullTextQuery limitExecutionTimeTo(long timeout,
                                          TimeUnit timeUnit)
Description copied from interface: FullTextQuery
*Experimental* API, subject to change or removal Limit the time used by Hibernate Search to execute the query. When the limit is reached, results already fetched are returned. This time limit is a best effort. The query will likely run for longer than the provided time. The time limit only applies to the interactions between Hibernate Search and Lucene. In other words, a query to the database will not be limited. If the limit is reached and all results are not yet fetched, FullTextQuery.hasPartialResults() returns true.

Specified by:
limitExecutionTimeTo in interface FullTextQuery
Parameters:
timeout - time out period
timeUnit - time out unit
Returns:
this to allow method chaining

hasPartialResults

public boolean hasPartialResults()
Description copied from interface: FullTextQuery
Experimental API, subject to change or removal

Specified by:
hasPartialResults in interface FullTextQuery
Returns:
When using FullTextQuery.limitExecutionTimeTo(long, java.util.concurrent.TimeUnit) }, returns true if partial results are returned (ie if the time limit has been reached and the result fetching process has been terminated.

initializeObjectsWith

public FullTextQuery initializeObjectsWith(ObjectLookupMethod lookupMethod,
                                           DatabaseRetrievalMethod retrievalMethod)
Description copied from interface: FullTextQuery
Refine the strategies used to load entities. The lookup method defines whether or not to lookup first in the second level cache or the persistence context before trying to initialize objects from the database. Defaults to SKIP. The database retrieval method defines how objects are loaded from the database. Defaults to QUERY. Note that Hibernate Search can deviate from these choices when it makes sense.

Specified by:
initializeObjectsWith in interface FullTextQuery


Copyright © 2006-2012 Red Hat Middleware, LLC. All Rights Reserved