Package org.hibernate.search
Interface FullTextQuery
- All Superinterfaces:
ProjectionConstants,org.hibernate.Query
- All Known Implementing Classes:
FullTextQueryImpl
The base interface for Lucene powered searches.
-
Field Summary
Fields inherited from interface org.hibernate.search.ProjectionConstants
BOOST, DOCUMENT, DOCUMENT_ID, EXPLANATION, ID, OBJECT_CLASS, SCORE, THIS -
Method Summary
Modifier and TypeMethodDescriptionvoiddisableFullTextFilter(String name) Disable a given filter by its name.enableFullTextFilter(String name) Enable a given filter by its name.explain(int documentId) Return the LuceneExplanationobject describing the score computation for the matching object/document in the current queryintbooleanExperimental API, subject to change or removalinitializeObjectsWith(ObjectLookupMethod lookupMethod, DatabaseRetrievalMethod retrievalMethod) Refine the strategies used to load entities.limitExecutionTimeTo(long timeout, TimeUnit timeUnit) *Experimental* API, subject to change or removal Limit the time used by Hibernate Search to execute the query.setCriteriaQuery(org.hibernate.Criteria criteria) Defines the Database Query used to load the Lucene results.setFetchSize(int i) Defines scrollable result fetch size as well as the JDBC fetch sizeAllows to use lucene filters.setFirstResult(int firstResult) Query.setFirstResult(int)setMaxResults(int maxResults) Query.setMaxResults(int)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).defines a result transformer used during projection, the Aliases provided are the projection aliases.Allows to let lucene sort the results.setTimeout(long timeout, TimeUnit timeUnit) Define a timeout period for a given unit of time.<T> TMethods inherited from interface org.hibernate.Query
executeUpdate, getNamedParameters, getQueryString, getReturnAliases, getReturnTypes, isReadOnly, 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, setLockOptions, 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 Details
-
setSort
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
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
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
- Parameters:
criteria- Hibernate criteria query used to load results- Returns:
thisfor method chaining
-
setProjection
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 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[]- Parameters:
fields- list of field names to project on- Returns:
thisfor method chaining
-
enableFullTextFilter
Enable a given filter by its name.- Parameters:
name- the name of the filter to enable- Returns:
- Returns a
FullTextFilterobject that allows filter parameter injection - Throws:
SearchException- in case the filter with the specified name is not defined
-
disableFullTextFilter
Disable a given filter by its name.- Parameters:
name- the name of the filter to disable.
-
getFacetManager
FacetManager getFacetManager()- Returns:
- return the manager for all faceting related operations
-
explain
Return the LuceneExplanationobject 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:
- An Lucene
Explanationinstance
-
setFirstResult
Query.setFirstResult(int)- Specified by:
setFirstResultin interfaceorg.hibernate.Query
-
setMaxResults
Query.setMaxResults(int)- Specified by:
setMaxResultsin interfaceorg.hibernate.Query
-
setFetchSize
Defines scrollable result fetch size as well as the JDBC fetch size- Specified by:
setFetchSizein interfaceorg.hibernate.Query
-
setResultTransformer
defines a result transformer used during projection, the Aliases provided are the projection aliases.- Specified by:
setResultTransformerin interfaceorg.hibernate.Query
-
unwrap
- Parameters:
type- the type to unwrap- Returns:
- the underlying type if possible. If not possible to unwrap to the given type an
IllegalArgumentExceptionis thrown. Supported types are:- org.apache.lucene.search.Query the underlying lucene query
-
setTimeout
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, aQueryTimeoutExceptionis raised.- Parameters:
timeout- time out periodtimeUnit- time out unit- Returns:
thisto allow method chaining
-
limitExecutionTimeTo
*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,hasPartialResults()returns true.- Parameters:
timeout- time out periodtimeUnit- time out unit- Returns:
thisto allow method chaining
-
hasPartialResults
boolean hasPartialResults()Experimental API, subject to change or removal- Returns:
- When using
limitExecutionTimeTo(long, java.util.concurrent.TimeUnit)}, returnstrueif partial results are returned (ie if the time limit has been reached and the result fetching process has been terminated.
-
initializeObjectsWith
FullTextQuery initializeObjectsWith(ObjectLookupMethod lookupMethod, DatabaseRetrievalMethod retrievalMethod) 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.
-