Interface TypedSearchSortFactory<SR>
- Type Parameters:
SR
- Scope root type.
- All Superinterfaces:
SearchSortFactory
- All Known Subinterfaces:
ElasticsearchSearchSortFactory<SR>
,ExtendedSearchSortFactory<SR,
,S, PDF> LuceneSearchSortFactory<SR>
- All Known Implementing Classes:
AbstractSearchSortFactory
Field paths
By default, field paths passed to this DSL are interpreted as absolute, i.e. relative to the index root.
However, a new, "relative" factory can be created with withRoot(String)
:
the new factory interprets paths as relative to the object field passed as argument to the method.
This can be useful when calling reusable methods that can apply the same sort on different object fields that have same structure (same sub-fields).
Such a factory can also transform relative paths into absolute paths using SearchSortFactory.toAbsolutePath(String)
;
this can be useful for native sorts in particular.
Field references
Afield reference
is always represented by the absolute field path and,
if applicable, i.e. when a field reference is typed, a combination of the ValueModel
and the type.
Field references are usually accessed from the generated Hibernate Search's static metamodel classes that describe the index structure.
Such reference provides the information on which search capabilities the particular index field possesses, and allows switching between different
value model representations
.
- Author:
- Emmanuel Bernard emmanuel@hibernate.org
-
Method Summary
Modifier and TypeMethodDescriptionOrder by a sort composed of several elements.composite
(Consumer<? super CompositeSortOptionsCollector<?>> elementContributor) Order by a sort composed of several elements, which will be defined by the given consumer.default DistanceSortOptionsStep
<SR, ?, ? extends TypedSearchPredicateFactory<SR>> Order elements by the distance from the location stored in the specified field to the location specified.DistanceSortOptionsStep
<SR, ?, ? extends TypedSearchPredicateFactory<SR>> Order elements by the distance from the location stored in the specified field to the location specified.default DistanceSortOptionsStep
<SR, ?, ? extends TypedSearchPredicateFactory<SR>> distance
(DistanceSortFieldReference<? super SR> fieldReference, double latitude, double longitude) Order elements by the distance from the location stored in the specified field to the location specified.default DistanceSortOptionsStep
<SR, ?, ? extends TypedSearchPredicateFactory<SR>> distance
(DistanceSortFieldReference<? super SR> fieldReference, GeoPoint location) Order elements by the distance from the location stored in the specified field to the location specified.Create a DSL step allowing multiple attempts to apply extensions one after the other, failing only if none of the extensions is supported.FieldSortOptionsStep
<SR, ?, ? extends TypedSearchPredicateFactory<SR>> Order elements by the value of a specific field.<T> FieldSortOptionsGenericStep
<SR, T, ?, ?, ? extends TypedSearchPredicateFactory<SR>> field
(FieldSortFieldReference<? super SR, T> fieldReference) Order elements by the value of a specific field.Order elements by their internal index order.score()
Order elements by their relevance score.withParameters
(Function<? super NamedValues, ? extends SortFinalStep> sortCreator) Delegating sort that creates the actual sort at query create time and provides access to query parameters.Create a new sort factory whose root for all paths passed to the DSL will be the given object field.Methods inherited from interface org.hibernate.search.engine.search.sort.dsl.SearchSortFactory
extension, toAbsolutePath
-
Method Details
-
score
ScoreSortOptionsStep<SR,?> score()Order elements by their relevance score.The default order is descending, i.e. higher scores come first.
- Specified by:
score
in interfaceSearchSortFactory
- Returns:
- A DSL step where the "score" sort can be defined in more details.
-
indexOrder
SortThenStep<SR> indexOrder()Order elements by their internal index order.- Specified by:
indexOrder
in interfaceSearchSortFactory
- Returns:
- A DSL step where the "index order" sort can be defined in more details.
-
field
Order elements by the value of a specific field.The default order is ascending.
- Specified by:
field
in interfaceSearchSortFactory
- Parameters:
fieldPath
- The path to the index field to sort by.- Returns:
- A DSL step where the "field" sort can be defined in more details.
- Throws:
SearchException
- If the field doesn't exist or cannot be sorted on.
-
field
@Incubating <T> FieldSortOptionsGenericStep<SR,T, field?, ?, ? extends TypedSearchPredicateFactory<SR>> (FieldSortFieldReference<? super SR, T> fieldReference) Order elements by the value of a specific field.The default order is ascending.
- Parameters:
fieldReference
- The field reference representing a definition of the index field to sort by.- Returns:
- A DSL step where the "field" sort can be defined in more details.
- Throws:
SearchException
- If the field doesn't exist or cannot be sorted on.
-
distance
DistanceSortOptionsStep<SR,?, distance? extends TypedSearchPredicateFactory<SR>> (String fieldPath, GeoPoint location) Order elements by the distance from the location stored in the specified field to the location specified.The default order is ascending.
- Specified by:
distance
in interfaceSearchSortFactory
- Parameters:
fieldPath
- The path to the index field containing the location to compute the distance from.location
- The location to which we want to compute the distance.- Returns:
- A DSL step where the "distance" sort can be defined in more details.
- Throws:
SearchException
- If the field type does not constitute a valid location.
-
distance
@Incubating default DistanceSortOptionsStep<SR,?, distance? extends TypedSearchPredicateFactory<SR>> (DistanceSortFieldReference<? super SR> fieldReference, GeoPoint location) Order elements by the distance from the location stored in the specified field to the location specified.The default order is ascending.
- Parameters:
fieldReference
- The field reference representing a definition of the index field containing the location to compute the distance from.location
- The location to which we want to compute the distance.- Returns:
- A DSL step where the "distance" sort can be defined in more details.
- Throws:
SearchException
- If the field type does not constitute a valid location.
-
distance
default DistanceSortOptionsStep<SR,?, distance? extends TypedSearchPredicateFactory<SR>> (String fieldPath, double latitude, double longitude) Order elements by the distance from the location stored in the specified field to the location specified.The default order is ascending.
- Specified by:
distance
in interfaceSearchSortFactory
- Parameters:
fieldPath
- The path to the index field containing the location to compute the distance from.latitude
- The latitude of the location to which we want to compute the distance.longitude
- The longitude of the location to which we want to compute the distance.- Returns:
- A DSL step where the "distance" sort can be defined in more details.
- Throws:
SearchException
- If the field type does not constitute a valid location.
-
distance
@Incubating default DistanceSortOptionsStep<SR,?, distance? extends TypedSearchPredicateFactory<SR>> (DistanceSortFieldReference<? super SR> fieldReference, double latitude, double longitude) Order elements by the distance from the location stored in the specified field to the location specified.The default order is ascending.
- Parameters:
fieldReference
- The field reference representing a definition of the index field containing the location to compute the distance from.latitude
- The latitude of the location to which we want to compute the distance.longitude
- The longitude of the location to which we want to compute the distance.- Returns:
- A DSL step where the "distance" sort can be defined in more details.
- Throws:
SearchException
- If the field type does not constitute a valid location.
-
composite
CompositeSortComponentsStep<SR,?> composite()Order by a sort composed of several elements.Note that, in general, calling this method is not necessary as you can chain sorts by calling
SortThenStep.then()
. This method is mainly useful to mix imperative and declarative style when building sorts. Seecomposite(Consumer)
- Specified by:
composite
in interfaceSearchSortFactory
- Returns:
- A DSL step where the "composite" sort can be defined in more details.
-
composite
Order by a sort composed of several elements, which will be defined by the given consumer.Best used with lambda expressions.
This is mainly useful to mix imperative and declarative style when building sorts, e.g.:
f.composite( c -> { c.add( f.field( "category" ) ); if ( someInput != null ) { c.add( f.distance( "location", someInput.getLatitude(), someInput.getLongitude() ); } c.add( f.indexOrder() ); } )
- Specified by:
composite
in interfaceSearchSortFactory
- Parameters:
elementContributor
- A consumer that will add clauses to the step passed in parameter. Should generally be a lambda expression.- Returns:
- A DSL step where the "composite" sort can be defined in more details.
-
withParameters
@Incubating SortThenStep<SR> withParameters(Function<? super NamedValues, ? extends SortFinalStep> sortCreator) Delegating sort that creates the actual sort at query create time and provides access to query parameters.Which sort exactly to create is defined by a function passed to the arguments of this sort.
- Specified by:
withParameters
in interfaceSearchSortFactory
- Parameters:
sortCreator
- The function defining an actual sort to apply.- Returns:
- A final DSL step in a parameterized sort definition.
-
extension
SearchSortFactoryExtensionIfSupportedStep<SR> extension()Create a DSL step allowing multiple attempts to apply extensions one after the other, failing only if none of the extensions is supported.If you only need to apply a single extension and fail if it is not supported, use the simpler
SearchSortFactory.extension(SearchSortFactoryExtension)
method instead.- Specified by:
extension
in interfaceSearchSortFactory
- Returns:
- A DSL step.
-
withRoot
Create a new sort factory whose root for all paths passed to the DSL will be the given object field.This is used to call reusable methods that can apply the same sort on different object fields that have same structure (same sub-fields).
- Specified by:
withRoot
in interfaceSearchSortFactory
- Parameters:
objectFieldPath
- The path from the current root to an object field that will become the new root.- Returns:
- A new sort factory using the given object field as root.
-