org.hibernate.search.query
Class FullTextQueryImpl

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

public class FullTextQueryImpl
extends org.hibernate.impl.AbstractQueryImpl
implements FullTextQuery

Implementation of FullTextQuery.

Author:
Emmanuel Bernard, Hardy Ferentschik

Field Summary
 
Fields inherited from class org.hibernate.impl.AbstractQueryImpl
parameterMetadata, session
 
Fields inherited from interface org.hibernate.search.ProjectionConstants
BOOST, DOCUMENT, DOCUMENT_ID, EXPLANATION, ID, OBJECT_CLASS, SCORE, THIS
 
Constructor Summary
FullTextQueryImpl(org.apache.lucene.search.Query query, Class[] classes, org.hibernate.engine.SessionImplementor session, org.hibernate.engine.query.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
protected  Map getLockModes()
           
 int getResultSize()
          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.

 Iterator iterate()
          Return an interator on the results.
 List list()
           
 org.hibernate.ScrollableResults scroll()
           
 org.hibernate.ScrollableResults scroll(org.hibernate.ScrollMode scrollMode)
           
 FullTextQuery setCriteriaQuery(org.hibernate.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)
          {link:Query#setFirstResult}
 org.hibernate.Query setLockMode(String alias, org.hibernate.LockMode lockMode)
           
 FullTextQuery setMaxResults(int maxResults)
          {link:Query#setMaxResults}
 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(org.hibernate.transform.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.
 
Methods inherited from class org.hibernate.impl.AbstractQueryImpl
after, before, determineType, determineType, determineType, determineType, determineType, expandParameterLists, getNamedParameterLists, getNamedParameters, getNamedParams, 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, setTimeout, 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, 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, setTimeout, setTimestamp, setTimestamp, uniqueResult
 

Constructor Detail

FullTextQueryImpl

public FullTextQueryImpl(org.apache.lucene.search.Query query,
                         Class[] classes,
                         org.hibernate.engine.SessionImplementor session,
                         org.hibernate.engine.query.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 org.hibernate.HibernateException
Return an interator on the results. Retrieve the object one by one (initialize it during the next() operation)

Specified by:
iterate in interface org.hibernate.Query
Throws:
org.hibernate.HibernateException

scroll

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

scroll

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

list

public List list()
          throws org.hibernate.HibernateException
Specified by:
list in interface org.hibernate.Query
Throws:
org.hibernate.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:
Lucene Explanation

getResultSize

public int getResultSize()
Description copied from 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.

Specified by:
getResultSize in interface FullTextQuery

setCriteriaQuery

public FullTextQuery setCriteriaQuery(org.hibernate.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

No projection (criteria.setProjection() ) allowed, the root entity must be the only returned type No where restriction can be defined either.

Specified by:
setCriteriaQuery in interface FullTextQuery

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

setFirstResult

public FullTextQuery setFirstResult(int firstResult)
Description copied from interface: FullTextQuery
{link:Query#setFirstResult}

Specified by:
setFirstResult in interface org.hibernate.Query
Specified by:
setFirstResult in interface FullTextQuery
Overrides:
setFirstResult in class org.hibernate.impl.AbstractQueryImpl

setMaxResults

public FullTextQuery setMaxResults(int maxResults)
Description copied from interface: FullTextQuery
{link:Query#setMaxResults}

Specified by:
setMaxResults in interface org.hibernate.Query
Specified by:
setMaxResults in interface FullTextQuery
Overrides:
setMaxResults in class org.hibernate.impl.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 org.hibernate.Query
Specified by:
setFetchSize in interface FullTextQuery
Overrides:
setFetchSize in class org.hibernate.impl.AbstractQueryImpl

setResultTransformer

public FullTextQuery setResultTransformer(org.hibernate.transform.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 org.hibernate.Query
Specified by:
setResultTransformer in interface FullTextQuery
Overrides:
setResultTransformer in class org.hibernate.impl.AbstractQueryImpl

executeUpdate

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

setLockMode

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

getLockModes

protected Map getLockModes()
Specified by:
getLockModes in class org.hibernate.impl.AbstractQueryImpl

enableFullTextFilter

public FullTextFilter enableFullTextFilter(String name)
Description copied from interface: FullTextQuery
Enable a given filter by its name. Returns a FullTextFilter object that allows filter parameter injection

Specified by:
enableFullTextFilter in interface FullTextQuery

disableFullTextFilter

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

Specified by:
disableFullTextFilter in interface FullTextQuery