Interface SearchSortFactory
- All Known Subinterfaces:
ElasticsearchSearchSortFactory
,ExtendedSearchSortFactory<S,
,PDF> LuceneSearchSortFactory
- 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 toAbsolutePath(String)
;
this can be useful for native sorts in particular.
- Author:
- Emmanuel Bernard emmanuel@hibernate.org
-
Method Summary
Modifier and TypeMethodDescriptionOrder by a sort composed of several elements.composite
(Consumer<? super CompositeSortComponentsStep<?>> elementContributor) Order by a sort composed of several elements, which will be defined by the given consumer.default DistanceSortOptionsStep<?,
? extends SearchPredicateFactory> Order elements by the distance from the location stored in the specified field to the location specified.DistanceSortOptionsStep<?,
? extends SearchPredicateFactory> 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.<T> T
extension
(SearchSortFactoryExtension<T> extension) Extend the current factory with the given extension, resulting in an extended factory offering different types of sorts.FieldSortOptionsStep<?,
? extends SearchPredicateFactory> Order elements by the value of a specific field.Order elements by their internal index order.score()
Order elements by their relevance score.toAbsolutePath
(String relativeFieldPath) Create a new sort factory whose root for all paths passed to the DSL will be the given object field.
-
Method Details
-
score
ScoreSortOptionsStep<?> score()Order elements by their relevance score.The default order is descending, i.e. higher scores come first.
- Returns:
- A DSL step where the "score" sort can be defined in more details.
-
indexOrder
SortThenStep indexOrder()Order elements by their internal index order.- 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.
- 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.
-
distance
DistanceSortOptionsStep<?,? extends SearchPredicateFactory> distance(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.
- 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
default DistanceSortOptionsStep<?,? extends SearchPredicateFactory> distance(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.
- 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.
-
composite
CompositeSortComponentsStep<?> 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)
- 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() ); } )
- 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.
-
extension
Extend the current factory with the given extension, resulting in an extended factory offering different types of sorts.- Type Parameters:
T
- The type of factory provided by the extension.- Parameters:
extension
- The extension to the sort DSL.- Returns:
- The extended factory.
- Throws:
SearchException
- If the extension cannot be applied (wrong underlying backend, ...).
-
extension
SearchSortFactoryExtensionIfSupportedStep 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
extension(SearchSortFactoryExtension)
method instead.- 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).
- 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.
-
toAbsolutePath
- Parameters:
relativeFieldPath
- The path to a field, relative to theroot
of this factory.- Returns:
- The absolute path of the field, for use in native sorts for example. Note the path is returned even if the field doesn't exist.
-