-
Notifications
You must be signed in to change notification settings - Fork 242
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
HSEARCH-3591 Add an API to mix imperative and declarative style when …
…building composite sorts See in particular IndexSearchDocumentRepositoryImpl#searchAroundMe to get an idea of why we need this.
- Loading branch information
Showing
8 changed files
with
358 additions
and
64 deletions.
There are no files selected for viewing
35 changes: 35 additions & 0 deletions
35
engine/src/main/java/org/hibernate/search/engine/search/dsl/sort/CompositeSortContext.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,35 @@ | ||
/* | ||
* Hibernate Search, full-text search for your domain model | ||
* | ||
* License: GNU Lesser General Public License (LGPL), version 2.1 or later | ||
* See the lgpl.txt file in the root directory or <http://www.gnu.org/licenses/lgpl-2.1.html>. | ||
*/ | ||
package org.hibernate.search.engine.search.dsl.sort; | ||
|
||
import org.hibernate.search.engine.search.SearchSort; | ||
|
||
/** | ||
* The context used when defining a composite sort explicitly | ||
* (not using {@link NonEmptySortContext#then()}). | ||
*/ | ||
public interface CompositeSortContext extends NonEmptySortContext { | ||
|
||
/** | ||
* Add an element to the composite sort based on a previously-built {@link SearchSort}. | ||
* | ||
* @param searchSort The predicate that must match. | ||
* @return {@code this}, for method chaining. | ||
*/ | ||
CompositeSortContext add(SearchSort searchSort); | ||
|
||
/** | ||
* Add an element to the composite sort based on an almost-built {@link SearchSort}. | ||
* | ||
* @param terminalContext The terminal context allowing to retrieve a {@link SearchSort}. | ||
* @return {@code this}, for method chaining. | ||
*/ | ||
default CompositeSortContext add(SearchSortTerminalContext terminalContext) { | ||
return add( terminalContext.toSort() ); | ||
} | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
38 changes: 38 additions & 0 deletions
38
.../main/java/org/hibernate/search/engine/search/dsl/sort/impl/CompositeSortContextImpl.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,38 @@ | ||
/* | ||
* Hibernate Search, full-text search for your domain model | ||
* | ||
* License: GNU Lesser General Public License (LGPL), version 2.1 or later | ||
* See the lgpl.txt file in the root directory or <http://www.gnu.org/licenses/lgpl-2.1.html>. | ||
*/ | ||
package org.hibernate.search.engine.search.dsl.sort.impl; | ||
|
||
import org.hibernate.search.engine.search.SearchSort; | ||
import org.hibernate.search.engine.search.dsl.sort.CompositeSortContext; | ||
import org.hibernate.search.engine.search.dsl.sort.SearchSortFactoryContext; | ||
import org.hibernate.search.engine.search.dsl.sort.spi.SearchSortDslContext; | ||
|
||
class CompositeSortContextImpl<B> implements CompositeSortContext { | ||
|
||
private SearchSortDslContext<?, B> dslContext; | ||
|
||
CompositeSortContextImpl(SearchSortDslContext<?, B> dslContext) { | ||
this.dslContext = dslContext; | ||
} | ||
|
||
@Override | ||
public CompositeSortContext add(SearchSort searchSort) { | ||
dslContext = dslContext.append( dslContext.getFactory().toImplementation( searchSort ) ); | ||
return this; | ||
} | ||
|
||
@Override | ||
public SearchSortFactoryContext then() { | ||
return new DefaultSearchSortFactoryContext<>( dslContext ); | ||
} | ||
|
||
@Override | ||
public SearchSort toSort() { | ||
return dslContext.toSort(); | ||
} | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.