Class AbstractSearchQueryOptionsStep<S extends SearchQueryOptionsStep<S,H,LOS,SF,AF>,H,LOS,PDF extends SearchPredicateFactory,SF extends SearchSortFactory,AF extends SearchAggregationFactory,SC extends SearchQueryIndexScope<?>>
- All Implemented Interfaces:
SearchQueryFinalStep<H>
,SearchQueryOptionsStep<S,
,H, LOS, SF, AF> SearchQueryWhereStep<S,
,H, LOS, PDF> SearchFetchable<H>
- Direct Known Subclasses:
AbstractExtendedSearchQueryOptionsStep
-
Field Summary
Fields -
Constructor Summary
ConstructorsConstructorDescriptionAbstractSearchQueryOptionsStep
(SC scope, SearchQueryBuilder<H> searchQueryBuilder, SearchLoadingContextBuilder<?, LOS> loadingContextBuilder) -
Method Summary
Modifier and TypeMethodDescription<A> S
aggregation
(AggregationKey<A> key, Function<? super AF, ? extends AggregationFinalStep<A>> aggregationContributor) Add an aggregation to this query.<A> S
aggregation
(AggregationKey<A> key, SearchAggregation<A> aggregation) Add an aggregation to this query.protected abstract AF
Stop the query and throw aSearchTimeoutException
after a given timeout.Execute the query and return theSearchResult
, limiting tolimit
hits.fetchAll()
Execute the query and return theSearchResult
, including all hits, without any sort of limit.Execute the query and return all hits as aList
, without any sort of limit.Execute the query and return the hits as aList
, limiting tolimit
hits.Execute the query and return the hits as a single, optional element.long
Execute the query and return the total hit count.highlighter
(String highlighterName, Function<? super SearchHighlighterFactory, ? extends HighlighterFinalStep> highlighterContributor) Configure a named highlighter.highlighter
(String highlighterName, SearchHighlighter highlighter) Configure a named highlighter.highlighter
(Function<? super SearchHighlighterFactory, ? extends HighlighterFinalStep> highlighterContributor) Configure the default highlighter.highlighter
(SearchHighlighter highlighter) Configure the default highlighter.protected abstract SearchHighlighterFactory
Configure entity loading for this query.protected abstract PDF
Configure routing of the search query.routing
(Collection<String> routingKeys) Configure routing of the search query.scroll
(int chunkSize) Execute the query continuously to deliver results in small chunks through aSearchScroll
.sort
(Function<? super SF, ? extends SortFinalStep> sortContributor) Add a sort to this query.sort
(SearchSort sort) Add a sort to this query.protected abstract SF
protected abstract S
thisAsS()
toQuery()
Create aSearchQuery
instance matching the definition given in the previous DSL steps.totalHitCountThreshold
(long totalHitCountThreshold) Allow Hibernate Search to return a lower-bound estimate of the total hit count if it exceedstotalHitCountThreshold
.truncateAfter
(long timeout, TimeUnit timeUnit) Stop the query and return truncated results after a given timeout.where
(BiConsumer<? super PDF, ? super SimpleBooleanPredicateClausesCollector<?>> predicateContributor) Set the predicate for this query.where
(Function<? super PDF, ? extends PredicateFinalStep> predicateContributor) Set the predicate for this query.where
(SearchPredicate predicate) Set the predicate for this query.
-
Field Details
-
scope
-
-
Constructor Details
-
AbstractSearchQueryOptionsStep
public AbstractSearchQueryOptionsStep(SC scope, SearchQueryBuilder<H> searchQueryBuilder, SearchLoadingContextBuilder<?, LOS> loadingContextBuilder)
-
-
Method Details
-
where
Description copied from interface:SearchQueryWhereStep
Set the predicate for this query.- Specified by:
where
in interfaceSearchQueryWhereStep<S extends SearchQueryOptionsStep<S,
H, LOS, SF, AF>, H, LOS, PDF extends SearchPredicateFactory> - Parameters:
predicate
- ASearchPredicate
object obtained from the search scope.- Returns:
- The next step.
-
where
Description copied from interface:SearchQueryWhereStep
Set the predicate for this query.- Specified by:
where
in interfaceSearchQueryWhereStep<S extends SearchQueryOptionsStep<S,
H, LOS, SF, AF>, H, LOS, PDF extends SearchPredicateFactory> - Parameters:
predicateContributor
- A function that will use the factory passed in parameter to create a predicate, returning the final step in the predicate DSL. Should generally be a lambda expression.- Returns:
- The next step.
-
where
public S where(BiConsumer<? super PDF, ? super SimpleBooleanPredicateClausesCollector<?>> predicateContributor) Description copied from interface:SearchQueryWhereStep
Set the predicate for this query.- Specified by:
where
in interfaceSearchQueryWhereStep<S extends SearchQueryOptionsStep<S,
H, LOS, SF, AF>, H, LOS, PDF extends SearchPredicateFactory> - Parameters:
predicateContributor
- A consumer that will use the factory passed in parameter to create predicates and add them as clauses to the collector passed in parameter. Should generally be a lambda expression. The resulting root predicate will have to match all clauses.- Returns:
- The next step.
- See Also:
-
routing
Description copied from interface:SearchQueryOptionsStep
Configure routing of the search query.Useful when indexes are sharded, to limit the number of shards interrogated by the search query.
This method may be called multiple times, in which case all submitted routing keys will be taken into account.
By default, if routing is not configured, all shards will be queried.
- Specified by:
routing
in interfaceSearchQueryOptionsStep<S extends SearchQueryOptionsStep<S,
H, LOS, SF, AF>, H, LOS, PDF extends SearchPredicateFactory, SF extends SearchSortFactory> - Parameters:
routingKey
- A string key. All shards matching this key will be queried.- Returns:
this
, for method chaining.
-
routing
Description copied from interface:SearchQueryOptionsStep
Configure routing of the search query.Similar to
SearchQueryOptionsStep.routing(String)
, but allows passing multiple keys in a single call.- Specified by:
routing
in interfaceSearchQueryOptionsStep<S extends SearchQueryOptionsStep<S,
H, LOS, SF, AF>, H, LOS, PDF extends SearchPredicateFactory, SF extends SearchSortFactory> - Parameters:
routingKeys
- A collection containing zero, one or multiple string keys.- Returns:
this
, for method chaining.
-
truncateAfter
Description copied from interface:SearchQueryOptionsStep
Stop the query and return truncated results after a given timeout.The timeout is handled on a best effort basis: Hibernate Search will *try* to stop the query as soon as possible after the timeout.
- Specified by:
truncateAfter
in interfaceSearchQueryOptionsStep<S extends SearchQueryOptionsStep<S,
H, LOS, SF, AF>, H, LOS, PDF extends SearchPredicateFactory, SF extends SearchSortFactory> - Parameters:
timeout
- Timeout value.timeUnit
- Timeout unit.- Returns:
this
, for method chaining.
-
failAfter
Description copied from interface:SearchQueryOptionsStep
Stop the query and throw aSearchTimeoutException
after a given timeout.The timeout is handled on a best effort basis: Hibernate Search will *try* to stop the query as soon as possible after the timeout. However, this method is more likely to trigger an early stop than
SearchQueryOptionsStep.truncateAfter(long, TimeUnit)
.- Specified by:
failAfter
in interfaceSearchQueryOptionsStep<S extends SearchQueryOptionsStep<S,
H, LOS, SF, AF>, H, LOS, PDF extends SearchPredicateFactory, SF extends SearchSortFactory> - Parameters:
timeout
- Timeout value.timeUnit
- Timeout unit.- Returns:
this
, for method chaining.
-
totalHitCountThreshold
Description copied from interface:SearchQueryOptionsStep
Allow Hibernate Search to return a lower-bound estimate of the total hit count if it exceedstotalHitCountThreshold
.Allowing Hibernate Search to return a lower-bound estimate of the total hit count can lead to significantly fewer index scans and yield significant performance improvements, in particular when sorting by score (the default) on a large result set.
Note this optimization has no effect when also requesting aggregations.
- Specified by:
totalHitCountThreshold
in interfaceSearchQueryOptionsStep<S extends SearchQueryOptionsStep<S,
H, LOS, SF, AF>, H, LOS, PDF extends SearchPredicateFactory, SF extends SearchSortFactory> - Parameters:
totalHitCountThreshold
- the value below which the hit count is always exact- Returns:
this
, for method chaining.- See Also:
-
highlighter
public S highlighter(Function<? super SearchHighlighterFactory, ? extends HighlighterFinalStep> highlighterContributor) Description copied from interface:SearchQueryOptionsStep
Configure the default highlighter.For specifying the fields to highlight see
SearchProjectionFactory.highlight(String)
. For providing field-specific settings to override the ones set here seeSearchQueryOptionsStep.highlighter(String, Function)
.Backend specific defaults will be used if no configuration is provided.
- Specified by:
highlighter
in interfaceSearchQueryOptionsStep<S extends SearchQueryOptionsStep<S,
H, LOS, SF, AF>, H, LOS, PDF extends SearchPredicateFactory, SF extends SearchSortFactory> - Parameters:
highlighterContributor
- a function that will use a highlighter factory to configure the default highlighter for this query.- Returns:
this
, for method chaining.
-
highlighter
Description copied from interface:SearchQueryOptionsStep
Configure the default highlighter.For specifying the fields to highlight see
SearchProjectionFactory.highlight(String)
. For providing field-specific settings to override the ones set here seeSearchQueryOptionsStep.highlighter(String, Function)
.Backend specific defaults will be used if no configuration is provided.
- Specified by:
highlighter
in interfaceSearchQueryOptionsStep<S extends SearchQueryOptionsStep<S,
H, LOS, SF, AF>, H, LOS, PDF extends SearchPredicateFactory, SF extends SearchSortFactory> - Parameters:
highlighter
- a highlighter obtained from the search scope to be used as the default highlighter for this query.- Returns:
this
, for method chaining.
-
highlighter
public S highlighter(String highlighterName, Function<? super SearchHighlighterFactory, ? extends HighlighterFinalStep> highlighterContributor) Description copied from interface:SearchQueryOptionsStep
Configure a named highlighter.Named highlighters are to be referenced in
highlight projections
.Named highlighters override the settings set by a default highlighter if such was configured for this query.
The highlighter type must be the same as the default highlighter's, if a
default highlighter settings was configured
for this query.- Specified by:
highlighter
in interfaceSearchQueryOptionsStep<S extends SearchQueryOptionsStep<S,
H, LOS, SF, AF>, H, LOS, PDF extends SearchPredicateFactory, SF extends SearchSortFactory> - Parameters:
highlighterName
- name of the highlighter. Can be referenced when defining ahighlight projection
.highlighterContributor
- a function that will use a highlighter factory to configure the named highlighter.- Returns:
this
, for method chaining.- See Also:
-
highlighter
Description copied from interface:SearchQueryOptionsStep
Configure a named highlighter.Named highlighters are to be referenced in
highlight projections
.Named highlighters override the settings set by a default highlighter if such was configured for this query.
The highlighter type must be the same as the default highlighter's, if a
default highlighter settings was configured
for this query.- Specified by:
highlighter
in interfaceSearchQueryOptionsStep<S extends SearchQueryOptionsStep<S,
H, LOS, SF, AF>, H, LOS, PDF extends SearchPredicateFactory, SF extends SearchSortFactory> - Parameters:
highlighterName
- name of the highlighter. Can be referenced when defining ahighlight projection
.highlighter
- a highlighter obtained from the search scope that will serve as the named highlighter.- Returns:
this
, for method chaining.- See Also:
-
loading
Description copied from interface:SearchQueryOptionsStep
Configure entity loading for this query.- Specified by:
loading
in interfaceSearchQueryOptionsStep<S extends SearchQueryOptionsStep<S,
H, LOS, SF, AF>, H, LOS, PDF extends SearchPredicateFactory, SF extends SearchSortFactory> - Parameters:
loadingOptionsContributor
- A consumer that will alter the loading options passed in parameter. Should generally be a lambda expression.- Returns:
this
, for method chaining.
-
sort
Description copied from interface:SearchQueryOptionsStep
Add a sort to this query.- Specified by:
sort
in interfaceSearchQueryOptionsStep<S extends SearchQueryOptionsStep<S,
H, LOS, SF, AF>, H, LOS, PDF extends SearchPredicateFactory, SF extends SearchSortFactory> - Parameters:
sort
- ASearchSort
object obtained from the search scope.- Returns:
this
, for method chaining.
-
sort
Description copied from interface:SearchQueryOptionsStep
Add a sort to this query.- Specified by:
sort
in interfaceSearchQueryOptionsStep<S extends SearchQueryOptionsStep<S,
H, LOS, SF, AF>, H, LOS, PDF extends SearchPredicateFactory, SF extends SearchSortFactory> - Parameters:
sortContributor
- A function that will use the factory passed in parameter to create a sort, returning the final step in the sort DSL. Should generally be a lambda expression.- Returns:
this
, for method chaining.
-
aggregation
Description copied from interface:SearchQueryOptionsStep
Add an aggregation to this query.- Specified by:
aggregation
in interfaceSearchQueryOptionsStep<S extends SearchQueryOptionsStep<S,
H, LOS, SF, AF>, H, LOS, PDF extends SearchPredicateFactory, SF extends SearchSortFactory> - Type Parameters:
A
- The type of aggregation values.- Parameters:
key
- The key that will be used toretrieve the aggregation
from theSearchResult
.aggregation
- ASearchAggregation
object obtained from the search scope.- Returns:
this
, for method chaining.
-
aggregation
public <A> S aggregation(AggregationKey<A> key, Function<? super AF, ? extends AggregationFinalStep<A>> aggregationContributor) Description copied from interface:SearchQueryOptionsStep
Add an aggregation to this query.- Specified by:
aggregation
in interfaceSearchQueryOptionsStep<S extends SearchQueryOptionsStep<S,
H, LOS, SF, AF>, H, LOS, PDF extends SearchPredicateFactory, SF extends SearchSortFactory> - Type Parameters:
A
- The type of aggregation values.- Parameters:
key
- The key that will be used toretrieve the aggregation
from theSearchResult
.aggregationContributor
- A function that will use the factory passed in parameter to create an aggregation, returning the final step in the sort DSL. Should generally be a lambda expression.- Returns:
this
, for method chaining.
-
toQuery
Description copied from interface:SearchQueryFinalStep
Create aSearchQuery
instance matching the definition given in the previous DSL steps.Calling this method is generally not necessary as most query execution methods are also implemented by this DSL step, so for example
.toQuery().fetch()
can be replaced with simply.fetch()
.- Specified by:
toQuery
in interfaceSearchQueryFinalStep<S extends SearchQueryOptionsStep<S,
H, LOS, SF, AF>> - Returns:
- The
SearchQuery
resulting from the previous DSL steps.
-
fetchAll
Description copied from interface:SearchFetchable
Execute the query and return theSearchResult
, including all hits, without any sort of limit.SearchFetchable.fetch(Integer)
orSearchFetchable.fetch(Integer, Integer)
should generally be preferred, for performance reasons.- Specified by:
fetchAll
in interfaceSearchFetchable<S extends SearchQueryOptionsStep<S,
H, LOS, SF, AF>> - Returns:
- The
SearchResult
.
-
fetch
Description copied from interface:SearchFetchable
Execute the query and return theSearchResult
, limiting tolimit
hits.- Specified by:
fetch
in interfaceSearchFetchable<S extends SearchQueryOptionsStep<S,
H, LOS, SF, AF>> - Parameters:
limit
- The maximum number of hits to be included in theSearchResult
.null
means no limit.- Returns:
- The
SearchResult
.
-
fetch
Description copied from interface:SearchFetchable
- Specified by:
fetch
in interfaceSearchFetchable<S extends SearchQueryOptionsStep<S,
H, LOS, SF, AF>> - Parameters:
offset
- The number of hits to skip before adding the hits to theSearchResult
.null
means no offset.limit
- The maximum number of hits to be included in theSearchResult
.null
means no limit.- Returns:
- The
SearchResult
.
-
fetchAllHits
Description copied from interface:SearchFetchable
Execute the query and return all hits as aList
, without any sort of limit.SearchFetchable.fetchHits(Integer)
orSearchFetchable.fetchHits(Integer, Integer)
should generally be preferred, for performance reasons.- Specified by:
fetchAllHits
in interfaceSearchFetchable<S extends SearchQueryOptionsStep<S,
H, LOS, SF, AF>> - Returns:
- The query hits.
-
fetchHits
Description copied from interface:SearchFetchable
Execute the query and return the hits as aList
, limiting tolimit
hits.- Specified by:
fetchHits
in interfaceSearchFetchable<S extends SearchQueryOptionsStep<S,
H, LOS, SF, AF>> - Parameters:
limit
- The maximum number of hits to be returned by this method.null
means no limit.- Returns:
- The query hits.
-
fetchHits
Description copied from interface:SearchFetchable
- Specified by:
fetchHits
in interfaceSearchFetchable<S extends SearchQueryOptionsStep<S,
H, LOS, SF, AF>> - Parameters:
offset
- The number of hits to skip.null
means no offset.limit
- The maximum number of hits to be returned by this method.null
means no limit.- Returns:
- The query hits.
-
fetchSingleHit
Description copied from interface:SearchFetchable
Execute the query and return the hits as a single, optional element.- Specified by:
fetchSingleHit
in interfaceSearchFetchable<S extends SearchQueryOptionsStep<S,
H, LOS, SF, AF>> - Returns:
- The single, optional query hit.
-
fetchTotalHitCount
public long fetchTotalHitCount()Description copied from interface:SearchFetchable
Execute the query and return the total hit count.- Specified by:
fetchTotalHitCount
in interfaceSearchFetchable<S extends SearchQueryOptionsStep<S,
H, LOS, SF, AF>> - Returns:
- The total number of matching entities, ignoring pagination settings.
-
scroll
Description copied from interface:SearchFetchable
Execute the query continuously to deliver results in small chunks through aSearchScroll
.Useful to process large datasets.
- Specified by:
scroll
in interfaceSearchFetchable<S extends SearchQueryOptionsStep<S,
H, LOS, SF, AF>> - Parameters:
chunkSize
- The maximum number of hits to be returned for each call toSearchScroll.next()
- Returns:
- The
SearchScroll
.
-
thisAsS
-
predicateFactory
-
sortFactory
-
aggregationFactory
-
highlighterFactory
-