Skip to content

Commit

Permalink
HSEARCH-3863 Add missing option to DistanceSortOptionsStep
Browse files Browse the repository at this point in the history
  • Loading branch information
fax4ever committed Feb 8, 2021
1 parent 8961158 commit fe2fa37
Show file tree
Hide file tree
Showing 3 changed files with 83 additions and 1 deletion.
@@ -0,0 +1,48 @@
/*
* 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.sort.dsl;

import org.hibernate.search.engine.spatial.GeoPoint;

/**
* The step in a sort definition where the behavior on missing values can be set.
*
* @param <N> The type of the next step (returned by {@link DistanceSortMissingValueBehaviorStep#first()}, for example).
*
* @author Emmanuel Bernard emmanuel@hibernate.org
*/
public interface DistanceSortMissingValueBehaviorStep<N> {

/**
* Put documents with missing values last in the sorting.
*
* <p>This instruction is independent of whether the sort is being ascending
* or descending.
*
* @return The next step.
*/
N last();

/**
* Put documents with missing values first in the sorting.
*
* <p>This instruction is independent of whether the sort is being ascending
* or descending.
*
* @return The next step.
*/
N first();

/**
* When documents are missing a value on the sort field, use the given value instead.
*
* @param value The value to use as a default when a document is missing a value on the sort field.
* @return The next step.
*/
N use(GeoPoint value);

}
Expand Up @@ -19,4 +19,12 @@
public interface DistanceSortOptionsStep<S extends DistanceSortOptionsStep<?, PDF>, PDF extends SearchPredicateFactory>
extends SortFinalStep, SortThenStep, SortOrderStep<S>, SortModeStep<S>, SortFilterStep<S, PDF> {

/**
* Start describing the behavior of this sort when a document doesn't
* have any value for the targeted field.
*
* @return The next step.
*/
DistanceSortMissingValueBehaviorStep<S> missing();

}
Expand Up @@ -13,6 +13,7 @@
import org.hibernate.search.engine.search.predicate.dsl.PredicateFinalStep;
import org.hibernate.search.engine.search.predicate.dsl.SearchPredicateFactory;
import org.hibernate.search.engine.search.sort.SearchSort;
import org.hibernate.search.engine.search.sort.dsl.DistanceSortMissingValueBehaviorStep;
import org.hibernate.search.engine.search.sort.dsl.DistanceSortOptionsStep;
import org.hibernate.search.engine.search.sort.dsl.SortOrder;
import org.hibernate.search.engine.search.sort.dsl.spi.AbstractSortThenStep;
Expand All @@ -22,7 +23,8 @@

public class DistanceSortOptionsStepImpl<PDF extends SearchPredicateFactory>
extends AbstractSortThenStep
implements DistanceSortOptionsStep<DistanceSortOptionsStepImpl<PDF>, PDF> {
implements DistanceSortOptionsStep<DistanceSortOptionsStepImpl<PDF>, PDF>,
DistanceSortMissingValueBehaviorStep<DistanceSortOptionsStepImpl<PDF>> {

private final DistanceSortBuilder builder;
private final SearchSortDslContext<?, ? extends PDF> dslContext;
Expand Down Expand Up @@ -61,6 +63,30 @@ public DistanceSortOptionsStepImpl<PDF> filter(SearchPredicate searchPredicate)
return this;
}


@Override
public DistanceSortMissingValueBehaviorStep<DistanceSortOptionsStepImpl<PDF>> missing() {
return this;
}

@Override
public DistanceSortOptionsStepImpl<PDF> first() {
// TODO HSEARCH-3863 builder.missingFirst();
return this;
}

@Override
public DistanceSortOptionsStepImpl<PDF> last() {
// TODO HSEARCH-3863 builder.missingLast();
return this;
}

@Override
public DistanceSortOptionsStepImpl<PDF> use(GeoPoint value) {
// TODO HSEARCH-3863 builder.missingAs( value );
return this;
}

@Override
protected SearchSort build() {
return builder.build();
Expand Down

0 comments on commit fe2fa37

Please sign in to comment.