|
5 | 5 |
|
6 | 6 | namespace Nest
|
7 | 7 | {
|
| 8 | + /// <summary> |
| 9 | + /// Sort on a field inside one or more nested objects. |
| 10 | + /// </summary> |
8 | 11 | [InterfaceDataContract]
|
9 | 12 | [ReadAs(typeof(NestedSort))]
|
10 | 13 | public interface INestedSort
|
11 | 14 | {
|
| 15 | + /// <summary> |
| 16 | + /// A filter that the inner objects inside the nested path should match with in order for its field values to be taken into account |
| 17 | + /// by sorting. A common pattern is to repeat the query/filter inside the nested filter or query. |
| 18 | + /// By default no nested filter is active. |
| 19 | + /// </summary> |
12 | 20 | [DataMember(Name = "filter")]
|
13 | 21 | QueryContainer Filter { get; set; }
|
14 | 22 |
|
| 23 | + /// <summary> |
| 24 | + /// Same as top-level nested, but applies to another nested path within the current nested object. |
| 25 | + /// </summary> |
15 | 26 | [DataMember(Name = "nested")]
|
16 | 27 | INestedSort Nested { get; set; }
|
17 | 28 |
|
| 29 | + /// <summary> |
| 30 | + /// Defines on which nested object to sort. The actual sort field must be a direct field inside this nested object. |
| 31 | + /// When sorting by nested field, this field is mandatory. |
| 32 | + /// </summary> |
18 | 33 | [DataMember(Name = "path")]
|
19 | 34 | Field Path { get; set; }
|
| 35 | + |
| 36 | + /// <summary> |
| 37 | + /// The maximum number of children to consider per root document when picking the sort value. Defaults to unlimited. |
| 38 | + /// </summary> |
| 39 | + [DataMember(Name = "max_children")] |
| 40 | + int? MaxChildren { get; set; } |
20 | 41 | }
|
21 | 42 |
|
| 43 | + /// <inheritdoc /> |
22 | 44 | public class NestedSort : INestedSort
|
23 | 45 | {
|
| 46 | + /// <inheritdoc /> |
24 | 47 | public QueryContainer Filter { get; set; }
|
| 48 | + /// <inheritdoc /> |
25 | 49 | public INestedSort Nested { get; set; }
|
| 50 | + /// <inheritdoc /> |
26 | 51 | public Field Path { get; set; }
|
| 52 | + /// <inheritdoc /> |
| 53 | + public int? MaxChildren { get; set; } |
27 | 54 | }
|
28 | 55 |
|
| 56 | + /// <inheritdoc cref="INestedSort"/> |
29 | 57 | public class NestedSortDescriptor<T>
|
30 | 58 | : DescriptorBase<NestedSortDescriptor<T>, INestedSort>, INestedSort where T : class
|
31 | 59 | {
|
32 | 60 | QueryContainer INestedSort.Filter { get; set; }
|
33 | 61 | INestedSort INestedSort.Nested { get; set; }
|
34 | 62 | Field INestedSort.Path { get; set; }
|
| 63 | + int? INestedSort.MaxChildren { get; set; } |
35 | 64 |
|
| 65 | + /// <inheritdoc cref="INestedSort.Path"/> |
36 | 66 | public NestedSortDescriptor<T> Path(Field path) => Assign(path, (a, v) => a.Path = v);
|
37 | 67 |
|
| 68 | + /// <inheritdoc cref="INestedSort.Path"/> |
38 | 69 | public NestedSortDescriptor<T> Path<TValue>(Expression<Func<T, TValue>> objectPath) => Assign(objectPath, (a, v) => a.Path = v);
|
39 | 70 |
|
| 71 | + /// <inheritdoc cref="INestedSort.Filter"/> |
40 | 72 | public NestedSortDescriptor<T> Filter(Func<QueryContainerDescriptor<T>, QueryContainer> filterSelector) =>
|
41 | 73 | Assign(filterSelector, (a, v) => a.Filter = v?.Invoke(new QueryContainerDescriptor<T>()));
|
42 | 74 |
|
| 75 | + /// <inheritdoc cref="INestedSort.Nested"/> |
43 | 76 | public NestedSortDescriptor<T> Nested(Func<NestedSortDescriptor<T>, INestedSort> filterSelector) =>
|
44 | 77 | Assign(filterSelector, (a, v) => a.Nested = v?.Invoke(new NestedSortDescriptor<T>()));
|
| 78 | + |
| 79 | + /// <inheritdoc cref="INestedSort.MaxChildren"/> |
| 80 | + public NestedSortDescriptor<T> MaxChildren(int? maxChildren) => Assign(maxChildren, (a, v) => a.MaxChildren = v); |
45 | 81 | }
|
46 | 82 | }
|
0 commit comments