org.hibernate.search
Interface FullTextQuery

All Superinterfaces:
ProjectionConstants, org.hibernate.Query
All Known Implementing Classes:
FullTextQueryImpl

public interface FullTextQuery
extends org.hibernate.Query, ProjectionConstants

The base interface for Lucene powered searches.

Author:
Hardy Ferentschik, Emmanuel Bernard

Field Summary
 
Fields inherited from interface org.hibernate.search.ProjectionConstants
BOOST, DOCUMENT, DOCUMENT_ID, EXPLANATION, ID, OBJECT_CLASS, SCORE, THIS
 
Method Summary
 void disableFullTextFilter(String name)
          Disable a given filter by its name
 FullTextFilter enableFullTextFilter(String name)
          Enable a given filter by its name.
 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
 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.

 FullTextQuery setCriteriaQuery(org.hibernate.Criteria criteria)
          Defines the Database Query used to load the Lucene results.
 FullTextQuery setFetchSize(int i)
          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}
 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 interface org.hibernate.Query
executeUpdate, getNamedParameters, getQueryString, getReturnAliases, getReturnTypes, iterate, list, scroll, scroll, 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, setLockMode, 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
 

Method Detail

setSort

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.

Parameters:
sort - The lucene sort object.
Returns:
this for method chaining

setFilter

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

Parameters:
filter - The lucene filter.
Returns:
this for method chaining

getResultSize

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.


setCriteriaQuery

FullTextQuery setCriteriaQuery(org.hibernate.Criteria criteria)
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.


setProjection

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).

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[]


enableFullTextFilter

FullTextFilter enableFullTextFilter(String name)
Enable a given filter by its name. Returns a FullTextFilter object that allows filter parameter injection


disableFullTextFilter

void disableFullTextFilter(String name)
Disable a given filter by its name


explain

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

Parameters:
documentId - Lucene Document id to be explain. This is NOT the object id
Returns:
Lucene Explanation

setFirstResult

FullTextQuery setFirstResult(int firstResult)
{link:Query#setFirstResult}

Specified by:
setFirstResult in interface org.hibernate.Query

setMaxResults

FullTextQuery setMaxResults(int maxResults)
{link:Query#setMaxResults}

Specified by:
setMaxResults in interface org.hibernate.Query

setFetchSize

FullTextQuery setFetchSize(int i)
Defines scrollable result fetch size as well as the JDBC fetch size

Specified by:
setFetchSize in interface org.hibernate.Query

setResultTransformer

FullTextQuery setResultTransformer(org.hibernate.transform.ResultTransformer transformer)
defines a result transformer used during projection, the Aliases provided are the projection aliases.

Specified by:
setResultTransformer in interface org.hibernate.Query