-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathnested_sort.go
92 lines (87 loc) · 2.83 KB
/
nested_sort.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
package es
type nestedSortType Object
// NestedSort creates a new es.nestedSortType object with the specified path.
//
// This function initializes an es.nestedSortType object, which is used to define
// sorting behavior for fields within nested documents. The specified path determines
// which nested field the sorting applies to.
//
// Example usage:
//
// ns := es.NestedSort("user")
// // ns now includes a nestedSortType with the "user" path.
//
// Parameters:
// - path: A string representing the nested field path to sort by.
//
// Returns:
//
// An es.nestedSortType object with the specified path.
func NestedSort(path string) nestedSortType {
return nestedSortType{
"path": path,
}
}
// Filter sets the "filter" parameter in an es.nestedSortType object.
//
// This method applies a filtering condition to the nested sorting, ensuring that
// only documents matching the filter criteria are considered for sorting.
//
// Example usage:
//
// ns := es.NestedSort("user").Filter(es.Term("user.active", true))
// // ns now includes a "filter" parameter with the specified filter.
//
// Parameters:
// - filter: A filter object defining the condition for filtering nested documents.
//
// Returns:
//
// The updated es.nestedSortType object with the "filter" parameter set.
func (ns nestedSortType) Filter(filter any) nestedSortType {
if field, fOk := correctType(filter); fOk {
ns["filter"] = field
}
return ns
}
// MaxChildren sets the "max_children" parameter in an es.nestedSortType object.
//
// This method specifies the maximum number of child documents that will be
// considered when sorting the parent document. It helps control sorting behavior
// in cases where multiple nested documents exist.
//
// Example usage:
//
// ns := es.NestedSort("user").MaxChildren(3)
// // ns now includes a "max_children" parameter with the value 3.
//
// Parameters:
// - maxChildren: An integer representing the maximum number of child documents considered for sorting.
//
// Returns:
//
// The updated es.nestedSortType object with the "max_children" parameter set.
func (ns nestedSortType) MaxChildren(maxChildren int) nestedSortType {
ns["max_children"] = maxChildren
return ns
}
// Nested sets a nested sorting configuration within an es.nestedSortType object.
//
// This method allows defining nested sorting within another nested field, enabling
// multi-level sorting configurations.
//
// Example usage:
//
// ns := es.NestedSort("user").Nested(es.NestedSort("user.address"))
// // ns now includes a "nested" parameter with the specified nested sorting configuration.
//
// Parameters:
// - nested: A nestedSortType object defining the nested sorting behavior.
//
// Returns:
//
// The updated es.nestedSortType object with the "nested" parameter set.
func (ns nestedSortType) Nested(nested nestedSortType) nestedSortType {
ns["nested"] = nested
return ns
}