|
18 | 18 | import java.util.Collections;
|
19 | 19 | import java.util.List;
|
20 | 20 |
|
| 21 | +import org.bson.Document; |
21 | 22 | import org.springframework.util.Assert;
|
22 | 23 |
|
23 | 24 | /**
|
@@ -48,6 +49,26 @@ public static ComparisonOperatorFactory valueOf(AggregationExpression expression
|
48 | 49 | return new ComparisonOperatorFactory(expression);
|
49 | 50 | }
|
50 | 51 |
|
| 52 | + /** |
| 53 | + * Obtain the document position (including gaps) relative to others (rank). |
| 54 | + * |
| 55 | + * @return new instance of {@link Rank}. |
| 56 | + * @since 3.3 |
| 57 | + */ |
| 58 | + public static Rank rank() { |
| 59 | + return new Rank(); |
| 60 | + } |
| 61 | + |
| 62 | + /** |
| 63 | + * Obtain the document position (without gaps) relative to others (rank). |
| 64 | + * |
| 65 | + * @return new instance of {@link DenseRank}. |
| 66 | + * @since 3.3 |
| 67 | + */ |
| 68 | + public static DenseRank denseRank() { |
| 69 | + return new DenseRank(); |
| 70 | + } |
| 71 | + |
51 | 72 | public static class ComparisonOperatorFactory {
|
52 | 73 |
|
53 | 74 | private final String fieldReference;
|
@@ -876,4 +897,35 @@ public Ne notEqualToValue(Object value) {
|
876 | 897 | return new Ne(append(value, Expand.KEEP_SOURCE));
|
877 | 898 | }
|
878 | 899 | }
|
| 900 | + |
| 901 | + /** |
| 902 | + * {@link Rank} resolves the current document position (the rank) relative to other documents. If multiple documents |
| 903 | + * occupy the same rank, {@literal $rank} places the document with the subsequent value at a rank with a gap. |
| 904 | + * |
| 905 | + * @author Christoph Strobl |
| 906 | + * @since 3.3 |
| 907 | + */ |
| 908 | + public static class Rank implements AggregationExpression { |
| 909 | + |
| 910 | + @Override |
| 911 | + public Document toDocument(AggregationOperationContext context) { |
| 912 | + return new Document("$rank", new Document()); |
| 913 | + } |
| 914 | + } |
| 915 | + |
| 916 | + /** |
| 917 | + * {@link DenseRank} resolves the current document position (the rank) relative to other documents. If multiple |
| 918 | + * documents occupy the same rank, {@literal $denseRank} places the document with the subsequent value at the next rank without |
| 919 | + * any gaps. |
| 920 | + * |
| 921 | + * @author Christoph Strobl |
| 922 | + * @since 3.3 |
| 923 | + */ |
| 924 | + public static class DenseRank implements AggregationExpression { |
| 925 | + |
| 926 | + @Override |
| 927 | + public Document toDocument(AggregationOperationContext context) { |
| 928 | + return new Document("$denseRank", new Document()); |
| 929 | + } |
| 930 | + } |
879 | 931 | }
|
0 commit comments