Interface HSQuery
- All Superinterfaces:
ProjectionConstants
- All Known Implementing Classes:
HSQueryImpl
Defines and executes an Hibernate Search query (wrapping a Lucene query).
Uses fluent APIs to define the query and offer a few alternatives
on how to execute the query.
This object is not meant to be thread safe.
The typical usage is as follow
//get query object
HSQuery query = searchFactoryIngegrator.createHSQuery();
//configure query object
query
.luceneQuery( luceneQuery )
.timeoutExceptionFactory( exceptionFactory )
.targetedEntities( Arrays.asList( classes ) );
[...]
//start timeout counting
query.getTimeoutManager().start();
//query execution and use
List entityInfos = query.getEntityInfos();
[...]
//done with the core of the query
query.getTimeoutManager().stop();
-
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 queryAllows to use lucene filters.firstResult(int firstResult) Set the first element to retrieve.WTF does that do exactlyString[]Deprecated.should be at most SearchFactoryIntegrator, preferably removed altogetherluceneQuery(Query query) Defines the underlying Lucene querymaxResults(Integer maxResults) Set the maximum number of elements to retrieve.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" (similar to an HQL or a Criteria API projection).Execute the Lucene query and return a traversable object over the results.Execute the Lucene query and return the list ofEntityInfos populated with metadata and projection.intLets Lucene sort the results.targetedEntities(List<Class<?>> classes) Defines the targeted entities.timeoutExceptionFactory(TimeoutExceptionFactory exceptionFactory) Define the timeout exception factory to customize the exception returned by the user.
-
Method Details
-
luceneQuery
Defines the underlying Lucene query- Parameters:
query- the Lucene query- Returns:
thisto allow method chaining
-
targetedEntities
Defines the targeted entities. This helps to reduce the number of targeted indexes.- Parameters:
classes- the list of classes (indexes) targeted by this query- Returns:
thisto allow for method chaining
-
sort
Lets Lucene sort the results. This is useful when you have different sort requirements than 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:
thisto allow for method chaining
-
filter
Allows to use lucene filters. Semi-deprecated? a preferred way is to use the @FullTextFilterDef approach- Parameters:
filter- The Lucene filter.- Returns:
thisto allow for method chaining
-
timeoutExceptionFactory
Define the timeout exception factory to customize the exception returned by the user. Defaults to returningQueryTimeoutException- Parameters:
exceptionFactory- the timeout exception factory to use- Returns:
thisto allow for method chaining
-
projection
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- the projected field names- Returns:
thisto allow for method chaining
-
firstResult
Set the first element to retrieve. If not set, elements will be retrieved beginning from element 0.- Parameters:
firstResult- a element number, numbered from 0- Returns:
thisto allow for method chaining
-
maxResults
Set the maximum number of elements to retrieve. If not set, there is no limit to the number of elements retrieved.- Parameters:
maxResults- the maximum number of elements- Returns:
thisin order to allow method chaining
-
getTargetedEntities
- Returns:
- the targeted entity types
-
getIndexedTargetedEntities
WTF does that do exactly -
getProjectedFields
String[] getProjectedFields()- Returns:
- the projected field names
-
getTimeoutManager
TimeoutManager getTimeoutManager()- Returns:
- the timeout manager. Make sure to wrap your HSQuery usage around a
timeoutManager.start()andtimeoutManager.stop().
-
getFacetManager
FacetManager getFacetManager()- Returns:
- return the manager for all faceting related operations
-
getLuceneQuery
Query getLuceneQuery()- Returns:
- the underlying Lucene query
-
queryEntityInfos
List<EntityInfo> queryEntityInfos()Execute the Lucene query and return the list ofEntityInfos populated with metadata and projection.ProjectionConstants.THISif projected is
not populated. It is the responsibility of the object source integration.- Returns:
- list of
EntityInfos populated with metadata and projection
-
queryDocumentExtractor
DocumentExtractor queryDocumentExtractor()Execute the Lucene query and return a traversable object over the results. Results are lazily fetched.ProjectionConstants.THISif projected is
not populated. It is the responsibility of the object source integration. The returnedDocumentExtractor
must be closed by the caller to release Lucene resources.- Returns:
- the
DocumentExtractorinstance
-
queryResultSize
int queryResultSize()- Returns:
- the number of hits for this search Caution: The number of results might be slightly different from what the object source returns if the index is not in sync with the store at the time of query.
-
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:
- Lucene Explanation
-
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
-
disableFullTextFilter
Disable a given filter by its name.- Parameters:
name- the name of the filter to disable.
-
getSearchFactoryImplementor
SearchFactoryImplementor getSearchFactoryImplementor()Deprecated.should be at most SearchFactoryIntegrator, preferably removed altogether- Returns:
- the
SearchFactoryImplementorinstance
-