Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
HSEARCH-3476 Add one SearchSort implementation per Elasticsearch sort
Instead of the previous hack consisting in shoving both the building behavior and the sort behavior into the builder in order to have a single ElasticsearchSearchSort implementation that delegates to the builder. Same reason as for predicates, see previous commits.
- Loading branch information
Showing
23 changed files
with
399 additions
and
376 deletions.
There are no files selected for viewing
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
39 changes: 39 additions & 0 deletions
39
...rg/hibernate/search/backend/elasticsearch/search/sort/impl/AbstractElasticsearchSort.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,39 @@ | ||
/* | ||
* 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.backend.elasticsearch.search.sort.impl; | ||
|
||
import java.util.Set; | ||
|
||
import org.hibernate.search.backend.elasticsearch.search.impl.ElasticsearchSearchContext; | ||
import org.hibernate.search.engine.search.sort.spi.SearchSortBuilder; | ||
|
||
public abstract class AbstractElasticsearchSort implements ElasticsearchSearchSort { | ||
|
||
protected final Set<String> indexNames; | ||
|
||
protected AbstractElasticsearchSort(AbstractBuilder builder) { | ||
this( builder.searchContext ); | ||
} | ||
|
||
protected AbstractElasticsearchSort(ElasticsearchSearchContext searchContext) { | ||
indexNames = searchContext.indexes().hibernateSearchIndexNames(); | ||
} | ||
|
||
@Override | ||
public Set<String> indexNames() { | ||
return indexNames; | ||
} | ||
|
||
public abstract static class AbstractBuilder implements SearchSortBuilder { | ||
|
||
protected final ElasticsearchSearchContext searchContext; | ||
|
||
protected AbstractBuilder(ElasticsearchSearchContext searchContext) { | ||
this.searchContext = searchContext; | ||
} | ||
} | ||
} |
27 changes: 0 additions & 27 deletions
27
...rnate/search/backend/elasticsearch/search/sort/impl/AbstractElasticsearchSortBuilder.java
This file was deleted.
Oops, something went wrong.
51 changes: 51 additions & 0 deletions
51
...g/hibernate/search/backend/elasticsearch/search/sort/impl/ElasticsearchCompositeSort.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,51 @@ | ||
/* | ||
* 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.backend.elasticsearch.search.sort.impl; | ||
|
||
import java.util.ArrayList; | ||
import java.util.List; | ||
|
||
import org.hibernate.search.backend.elasticsearch.search.impl.ElasticsearchSearchContext; | ||
import org.hibernate.search.engine.search.sort.SearchSort; | ||
import org.hibernate.search.engine.search.sort.spi.CompositeSortBuilder; | ||
|
||
public class ElasticsearchCompositeSort extends AbstractElasticsearchSort { | ||
|
||
private final List<ElasticsearchSearchSort> elements; | ||
|
||
protected ElasticsearchCompositeSort(Builder builder) { | ||
super( builder ); | ||
elements = builder.elements; | ||
// Ensure illegal attempts to mutate the sort will fail | ||
builder.elements = null; | ||
} | ||
|
||
@Override | ||
public void toJsonSorts(ElasticsearchSearchSortCollector collector) { | ||
for ( ElasticsearchSearchSort element : elements ) { | ||
element.toJsonSorts( collector ); | ||
} | ||
} | ||
|
||
public static class Builder extends AbstractBuilder implements CompositeSortBuilder { | ||
private List<ElasticsearchSearchSort> elements = new ArrayList<>(); | ||
|
||
protected Builder(ElasticsearchSearchContext searchContext) { | ||
super( searchContext ); | ||
} | ||
|
||
@Override | ||
public void add(SearchSort sort) { | ||
elements.add( ElasticsearchSearchSort.from( searchContext, sort ) ); | ||
} | ||
|
||
@Override | ||
public SearchSort build() { | ||
return new ElasticsearchCompositeSort( this ); | ||
} | ||
} | ||
} |
36 changes: 0 additions & 36 deletions
36
...nate/search/backend/elasticsearch/search/sort/impl/ElasticsearchCompositeSortBuilder.java
This file was deleted.
Oops, something went wrong.
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
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
20 changes: 0 additions & 20 deletions
20
...bernate/search/backend/elasticsearch/search/sort/impl/ElasticsearchSearchSortBuilder.java
This file was deleted.
Oops, something went wrong.
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.