Interface SearchSortFactory
-
- All Known Subinterfaces:
ElasticsearchSearchSortFactory
,ExtendedSearchSortFactory<PDF>
,LuceneSearchSortFactory
- All Known Implementing Classes:
DelegatingSearchSortFactory
public interface SearchSortFactory
A factory for search sorts.- Author:
- Emmanuel Bernard emmanuel@hibernate.org
-
-
Method Summary
All Methods Instance Methods Abstract Methods Default Methods Modifier and Type Method Description CompositeSortComponentsStep<?>
composite()
Order by a sort composed of several elements.SortThenStep
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>
distance(String absoluteFieldPath, double latitude, double longitude)
Order elements by the distance from the location stored in the specified field to the location specified.DistanceSortOptionsStep<?,? extends SearchPredicateFactory>
distance(String absoluteFieldPath, GeoPoint location)
Order elements by the distance from the location stored in the specified field to the location specified.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.<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>
field(String absoluteFieldPath)
Order elements by the value of a specific field.SortThenStep
indexOrder()
Order elements by their internal index order.ScoreSortOptionsStep<?>
score()
Order elements by their relevance score.
-
-
-
Method Detail
-
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
FieldSortOptionsStep<?,? extends SearchPredicateFactory> field(String absoluteFieldPath)
Order elements by the value of a specific field.The default order is ascending.
- Parameters:
absoluteFieldPath
- The absolute path 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<?,? extends SearchPredicateFactory> distance(String absoluteFieldPath, 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:
absoluteFieldPath
- The absolute path of the indexed location field to sort by.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 absoluteFieldPath, 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:
absoluteFieldPath
- The absolute path of the indexed location field to sort by.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
SortThenStep composite(Consumer<? super CompositeSortComponentsStep<?>> elementContributor)
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
<T> T extension(SearchSortFactoryExtension<T> 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.
-
-