Interface SearchQueryOptionsStep<S extends SearchQueryOptionsStep<?,H,LOS,SF,AF>,H,LOS,SF extends SearchSortFactory,AF extends SearchAggregationFactory>

Type Parameters:
S - The "self" type (the actual exposed type of this step). May be a subtype of SearchQueryOptionsStep with more exposed methods.
H - The type of hits for the created query.
LOS - The type of the initial step of the loading options definition DSL accessible through loading(Consumer).
SF - The type of factory used to create sorts in sort(Function).
AF - The type of factory used to create aggregations in aggregation(AggregationKey, Function).
All Superinterfaces:
SearchFetchable<H>, SearchQueryFinalStep<H>
All Known Subinterfaces:
ElasticsearchSearchQueryOptionsStep<H,LOS>, LuceneSearchQueryOptionsStep<H,LOS>
All Known Implementing Classes:
AbstractExtendedSearchQueryOptionsStep, AbstractSearchQueryOptionsStep

public interface SearchQueryOptionsStep<S extends SearchQueryOptionsStep<?,H,LOS,SF,AF>,H,LOS,SF extends SearchSortFactory,AF extends SearchAggregationFactory> extends SearchQueryFinalStep<H>, SearchFetchable<H>
The final step in a query definition, where optional parameters such as sorts can be set, and where the query can be executed or retrieved as an object.
  • Method Details

    • routing

      S routing(String routingKey)
      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.

      Parameters:
      routingKey - A string key. All shards matching this key will be queried.
      Returns:
      this, for method chaining.
    • routing

      S routing(Collection<String> routingKeys)
      Configure routing of the search query.

      Similar to routing(String), but allows passing multiple keys in a single call.

      Parameters:
      routingKeys - A collection containing zero, one or multiple string keys.
      Returns:
      this, for method chaining.
    • truncateAfter

      S truncateAfter(long timeout, TimeUnit timeUnit)
      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.

      Parameters:
      timeout - Timeout value.
      timeUnit - Timeout unit.
      Returns:
      this, for method chaining.
    • failAfter

      S failAfter(long timeout, TimeUnit timeUnit)
      Stop the query and throw a SearchTimeoutException 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 truncateAfter(long, TimeUnit).

      Parameters:
      timeout - Timeout value.
      timeUnit - Timeout unit.
      Returns:
      this, for method chaining.
    • loading

      S loading(Consumer<? super LOS> loadingOptionsContributor)
      Configure entity loading for this query.
      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

      S sort(SearchSort sort)
      Add a sort to this query.
      Parameters:
      sort - A SearchSort object obtained from the search scope.
      Returns:
      this, for method chaining.
    • sort

      S sort(Function<? super SF,? extends SortFinalStep> sortContributor)
      Add a sort to this query.
      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

      <T> S aggregation(AggregationKey<T> key, SearchAggregation<T> aggregation)
      Add an aggregation to this query.
      Type Parameters:
      T - The type of aggregation values.
      Parameters:
      key - The key that will be used to retrieve the aggregation from the SearchResult.
      aggregation - A SearchAggregation object obtained from the search scope.
      Returns:
      this, for method chaining.
    • aggregation

      <T> S aggregation(AggregationKey<T> key, Function<? super AF,? extends AggregationFinalStep<T>> aggregationContributor)
      Add an aggregation to this query.
      Type Parameters:
      T - The type of aggregation values.
      Parameters:
      key - The key that will be used to retrieve the aggregation from the SearchResult.
      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.
    • totalHitCountThreshold

      S totalHitCountThreshold(long totalHitCountThreshold)
      Allow Hibernate Search to return a lower-bound estimate of the total hit count if it exceeds totalHitCountThreshold.

      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.

      Parameters:
      totalHitCountThreshold - the value below which the hit count is always exact
      Returns:
      this, for method chaining.
      See Also:
    • highlighter

      @Incubating S highlighter(Function<? super SearchHighlighterFactory,? extends HighlighterFinalStep> highlighterContributor)
      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 see highlighter(String, Function).

      Backend specific defaults will be used if no configuration is provided.

      Parameters:
      highlighterContributor - a function that will use a highlighter factory to configure the default highlighter for this query.
      Returns:
      this, for method chaining.
    • highlighter

      @Incubating S highlighter(SearchHighlighter highlighter)
      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 see highlighter(String, Function).

      Backend specific defaults will be used if no configuration is provided.

      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

      @Incubating S highlighter(String highlighterName, Function<? super SearchHighlighterFactory,? extends HighlighterFinalStep> highlighterContributor)
      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.

      Parameters:
      highlighterName - name of the highlighter. Can be referenced when defining a highlight projection.
      highlighterContributor - a function that will use a highlighter factory to configure the named highlighter.
      Returns:
      this, for method chaining.
      See Also:
    • highlighter

      @Incubating S highlighter(String highlighterName, SearchHighlighter highlighter)
      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.

      Parameters:
      highlighterName - name of the highlighter. Can be referenced when defining a highlight projection.
      highlighter - a highlighter obtained from the search scope that will serve as the named highlighter.
      Returns:
      this, for method chaining.
      See Also:
    • param

      @Incubating S param(String parameterName, Object value)
      Add query parameter.

      Query parameters are intended to use in various withParameters(..) to create projections/predicates/sorts/aggregations relying on these query parameters.

      Parameters:
      parameterName - The name of a query parameter.
      value - The value of a query parameter.
      Returns:
      this, for method chaining.