org.hibernate.search.query.engine.impl
Class HSQueryImpl

java.lang.Object
  extended by org.hibernate.search.query.engine.impl.HSQueryImpl
All Implemented Interfaces:
Serializable, ProjectionConstants, HSQuery

public class HSQueryImpl
extends Object
implements HSQuery, Serializable

Author:
Emmanuel Bernard , Hardy Ferentschik
See Also:
Serialized Form

Field Summary
 
Fields inherited from interface org.hibernate.search.ProjectionConstants
DOCUMENT, DOCUMENT_ID, EXPLANATION, ID, OBJECT_CLASS, SCORE, SPATIAL_DISTANCE, THIS
 
Constructor Summary
HSQueryImpl(SearchFactoryImplementor searchFactoryImplementor)
           
 
Method Summary
 void afterDeserialise(SearchFactoryImplementor searchFactoryImplementor)
          afterDeserialise.
 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
 HSQuery filter(org.apache.lucene.search.Filter filter)
          Allows to use lucene filters.
 HSQuery firstResult(int firstResult)
          Set the first element to retrieve.
 FacetManagerImpl getFacetManager()
           
 Set<Class<?>> getIndexedTargetedEntities()
          Set of indexed entities corresponding to the class hierarchy of the targeted entities
 org.apache.lucene.search.Query getLuceneQuery()
           
 String[] getProjectedFields()
           
 SearchFactoryImplementor getSearchFactoryImplementor()
          getSearchFactoryImplementor.
 List<Class<?>> getTargetedEntities()
          List of targeted entities as described by the user
 TimeoutManager getTimeoutManager()
           
 HSQuery luceneQuery(org.apache.lucene.search.Query query)
          Defines the underlying Lucene query
 HSQuery maxResults(int maxResults)
          Set the maximum number of elements to retrieve.
 HSQuery 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).
 DocumentExtractor queryDocumentExtractor()
          DocumentExtractor returns a traverser over the full-text results (EntityInfo) This operation is lazy bound: - the query is executed - results are not retrieved until actually requested DocumentExtractor objects *must* be closed when the results are no longer traversed.
 List<EntityInfo> queryEntityInfos()
          Execute the Lucene query and return the list of EntityInfos populated with metadata and projection.
 int queryResultSize()
           
 HSQuery setSpatialParameters(Point center, String fieldName)
          setSpatialParameters.
 HSQuery sort(org.apache.lucene.search.Sort sort)
          Lets Lucene sort the results.
 HSQuery targetedEntities(List<Class<?>> classes)
          Defines the targeted entities.
 HSQuery timeoutExceptionFactory(TimeoutExceptionFactory exceptionFactory)
          Define the timeout exception factory to customize the exception returned by the user.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

HSQueryImpl

public HSQueryImpl(SearchFactoryImplementor searchFactoryImplementor)
Method Detail

afterDeserialise

public void afterDeserialise(SearchFactoryImplementor searchFactoryImplementor)
Description copied from interface: HSQuery

afterDeserialise.

Specified by:
afterDeserialise in interface HSQuery
Parameters:
searchFactoryImplementor - a SearchFactoryImplementor object.

setSpatialParameters

public HSQuery setSpatialParameters(Point center,
                                    String fieldName)
Description copied from interface: HSQuery

setSpatialParameters.

Specified by:
setSpatialParameters in interface HSQuery
Parameters:
center - center of the spatial search
fieldName - name ot the spatial field
Returns:
this to allow for method chaining

luceneQuery

public HSQuery luceneQuery(org.apache.lucene.search.Query query)
Description copied from interface: HSQuery
Defines the underlying Lucene query

Specified by:
luceneQuery in interface HSQuery
Parameters:
query - the Lucene query
Returns:
this to allow method chaining

targetedEntities

public HSQuery targetedEntities(List<Class<?>> classes)
Description copied from interface: HSQuery
Defines the targeted entities. This helps to reduce the number of targeted indexes.

Specified by:
targetedEntities in interface HSQuery
Parameters:
classes - the list of classes (indexes) targeted by this query
Returns:
this to allow for method chaining

sort

public HSQuery sort(org.apache.lucene.search.Sort sort)
Description copied from interface: HSQuery
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.

Specified by:
sort in interface HSQuery
Parameters:
sort - The Lucene sort object.
Returns:
this to allow for method chaining

filter

public HSQuery filter(org.apache.lucene.search.Filter filter)
Description copied from interface: HSQuery
Allows to use lucene filters. Semi-deprecated? a preferred way is to use the @FullTextFilterDef approach

Specified by:
filter in interface HSQuery
Parameters:
filter - The Lucene filter.
Returns:
this to allow for method chaining

timeoutExceptionFactory

public HSQuery timeoutExceptionFactory(TimeoutExceptionFactory exceptionFactory)
Description copied from interface: HSQuery
Define the timeout exception factory to customize the exception returned by the user. Defaults to returning QueryTimeoutException

Specified by:
timeoutExceptionFactory in interface HSQuery
Parameters:
exceptionFactory - the timeout exception factory to use
Returns:
this to allow for method chaining

projection

public HSQuery projection(String... fields)
Description copied from interface: HSQuery
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:
projection in interface HSQuery
Parameters:
fields - the projected field names
Returns:
this to allow for method chaining

firstResult

public HSQuery firstResult(int firstResult)
Description copied from interface: HSQuery
Set the first element to retrieve. If not set, elements will be retrieved beginning from element 0.

Specified by:
firstResult in interface HSQuery
Parameters:
firstResult - a element number, numbered from 0
Returns:
this to allow for method chaining

maxResults

public HSQuery maxResults(int maxResults)
Description copied from interface: HSQuery
Set the maximum number of elements to retrieve. If not set, there is no limit to the number of elements retrieved.

Specified by:
maxResults in interface HSQuery
Parameters:
maxResults - the maximum number of elements
Returns:
this in order to allow method chaining

getTargetedEntities

public List<Class<?>> getTargetedEntities()
List of targeted entities as described by the user

Specified by:
getTargetedEntities in interface HSQuery
Returns:
the targeted entity types

getIndexedTargetedEntities

public Set<Class<?>> getIndexedTargetedEntities()
Set of indexed entities corresponding to the class hierarchy of the targeted entities

Specified by:
getIndexedTargetedEntities in interface HSQuery

getProjectedFields

public String[] getProjectedFields()
Specified by:
getProjectedFields in interface HSQuery
Returns:
the projected field names

getTimeoutManager

public TimeoutManager getTimeoutManager()
Specified by:
getTimeoutManager in interface HSQuery
Returns:
the timeout manager. Make sure to wrap your HSQuery usage around a timeoutManager.start() and timeoutManager.stop().

getFacetManager

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

getLuceneQuery

public org.apache.lucene.search.Query getLuceneQuery()
Specified by:
getLuceneQuery in interface HSQuery
Returns:
the underlying Lucene query

queryEntityInfos

public List<EntityInfo> queryEntityInfos()
Description copied from interface: HSQuery
Execute the Lucene query and return the list of EntityInfos populated with metadata and projection. ProjectionConstants.THIS if projected is
not
populated. It is the responsibility of the object source integration.

Specified by:
queryEntityInfos in interface HSQuery
Returns:
list of EntityInfos populated with metadata and projection

queryDocumentExtractor

public DocumentExtractor queryDocumentExtractor()
DocumentExtractor returns a traverser over the full-text results (EntityInfo) This operation is lazy bound: - the query is executed - results are not retrieved until actually requested DocumentExtractor objects *must* be closed when the results are no longer traversed.

Specified by:
queryDocumentExtractor in interface HSQuery
Returns:
the DocumentExtractor instance

queryResultSize

public int queryResultSize()
Specified by:
queryResultSize in interface HSQuery
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

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

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

enableFullTextFilter

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

Specified by:
enableFullTextFilter in interface HSQuery
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: HSQuery
Disable a given filter by its name.

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

getSearchFactoryImplementor

public SearchFactoryImplementor getSearchFactoryImplementor()
Description copied from interface: HSQuery

getSearchFactoryImplementor.

Specified by:
getSearchFactoryImplementor in interface HSQuery
Returns:
the SearchFactoryImplementor instance


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