Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Defines an important constant for a fallback value #667

Merged
merged 2 commits into from
Dec 11, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
23 changes: 16 additions & 7 deletions src/main/java/sirius/db/es/ElasticQuery.java
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,15 @@
* @param <E> the type of entities to be queried
*/
public class ElasticQuery<E extends ElasticEntity> extends Query<ElasticQuery<E>, E, ElasticConstraint> {

/**
* Defines the fallback value used when no last sort value is present.
*
* @see #searchAfter(String)
* @see #getLastSortValue()
*/
public static final String NO_LAST_SORT_VALUE = "-";

/**
* If we only fetch from a single shard (as we use a routing), we fetch up to {@link #BLOCK_SIZE_FOR_SINGLE_SHARD}
* entities at once and hope to process them within {@link #STREAM_BLOCKWISE_PIT_TTL}.
Expand Down Expand Up @@ -448,15 +457,15 @@ public ElasticQuery<E> searchAfter(List<String> searchAfter) {
* Sets a singular "last sort value" to continue a previous query.
* <p>
* It is recommended to sort by {@link ElasticEntity#ID} when using this. Note that this gracefully
* handles empty values as well as "-" which is properly generated by {@link #getLastSortValue()} if no more
* results are expected.
* handles empty values as well as {@link #NO_LAST_SORT_VALUE} which is properly generated by {@link #getLastSortValue()}
* if no more results are expected.
*
* @param searchAfter the last sort value of the previous result
* @return the query itself for fluent method calls
*/
public ElasticQuery<E> searchAfter(String searchAfter) {
if (Strings.isFilled(searchAfter)) {
if ("-".equals(searchAfter)) {
if (NO_LAST_SORT_VALUE.equals(searchAfter)) {
return this.fail();
}

Expand Down Expand Up @@ -494,17 +503,17 @@ public List<String> getLastSortValues() {
/**
* Obtains the last sort value of this result.
* <p>
* Note that this will automatically return "-" if no more results are expected. Use this in conjunction with
* {@link #searchAfter(String)} and sort queries by {@link ElasticEntity#ID}.
* Note that this will automatically return {@link #NO_LAST_SORT_VALUE} if no more results are expected.
* Use this in conjunction with {@link #searchAfter(String)} and sort queries by {@link ElasticEntity#ID}.
*
* @return the last sort value within this result
*/
public String getLastSortValue() {
if (limit > 0 && Json.getArrayAt(getRawResponse(), HITS_POINTER).size() < limit) {
return "-";
return NO_LAST_SORT_VALUE;
}

return getLastSortValues().stream().filter(Strings::isFilled).findFirst().orElse("-");
return getLastSortValues().stream().filter(Strings::isFilled).findFirst().orElse(NO_LAST_SORT_VALUE);
}

/**
Expand Down
6 changes: 6 additions & 0 deletions src/main/java/sirius/db/mixing/annotations/Length.java
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,12 @@

/**
* Specifies the column length, most probably of string (CHAR) columns.
* <p>
* This annotation has no effect on properties other than a string, except the columns
* definitions for Clickhouse, where the length is used also for other types, for example int,
* to define the int size to use.
*
* @see sirius.db.jdbc.schema.ClickhouseDatabaseDialect
*/
@Documented
@Retention(RetentionPolicy.RUNTIME)
Expand Down
Loading