1 | "use strict";
|
2 |
|
3 | Object.defineProperty(exports, "__esModule", { value: true });
|
4 | exports.GeoDistanceSearchSort = exports.FieldSearchSort = exports.IdSearchSort = exports.ScoreSearchSort = exports.SearchSort = void 0;
|
5 |
|
6 |
|
7 |
|
8 |
|
9 |
|
10 | class SearchSort {
|
11 | constructor(data) {
|
12 | if (!data) {
|
13 | data = {};
|
14 | }
|
15 | this._data = data;
|
16 | }
|
17 | toJSON() {
|
18 | return this._data;
|
19 | }
|
20 | static score() {
|
21 | return new ScoreSearchSort();
|
22 | }
|
23 | static id() {
|
24 | return new IdSearchSort();
|
25 | }
|
26 | static field(field) {
|
27 | return new FieldSearchSort(field);
|
28 | }
|
29 | static geoDistance(field, lat, lon) {
|
30 | return new GeoDistanceSearchSort(field, lat, lon);
|
31 | }
|
32 | }
|
33 | exports.SearchSort = SearchSort;
|
34 |
|
35 |
|
36 |
|
37 |
|
38 |
|
39 | class ScoreSearchSort extends SearchSort {
|
40 | |
41 |
|
42 |
|
43 | constructor() {
|
44 | super({
|
45 | by: 'score',
|
46 | });
|
47 | }
|
48 | descending(descending) {
|
49 | this._data.desc = descending;
|
50 | return this;
|
51 | }
|
52 | }
|
53 | exports.ScoreSearchSort = ScoreSearchSort;
|
54 |
|
55 |
|
56 |
|
57 |
|
58 |
|
59 | class IdSearchSort extends SearchSort {
|
60 | |
61 |
|
62 |
|
63 | constructor() {
|
64 | super({
|
65 | by: 'id',
|
66 | });
|
67 | }
|
68 | descending(descending) {
|
69 | this._data.desc = descending;
|
70 | return this;
|
71 | }
|
72 | }
|
73 | exports.IdSearchSort = IdSearchSort;
|
74 |
|
75 |
|
76 |
|
77 |
|
78 |
|
79 | class FieldSearchSort extends SearchSort {
|
80 | |
81 |
|
82 |
|
83 | constructor(field) {
|
84 | super({
|
85 | by: 'field',
|
86 | field: field,
|
87 | });
|
88 | }
|
89 | type(type) {
|
90 | this._data.type = type;
|
91 | return this;
|
92 | }
|
93 | mode(mode) {
|
94 | this._data.mode = mode;
|
95 | return this;
|
96 | }
|
97 | missing(missing) {
|
98 | this._data.missing = missing;
|
99 | return this;
|
100 | }
|
101 | descending(descending) {
|
102 | this._data.desc = descending;
|
103 | return this;
|
104 | }
|
105 | }
|
106 | exports.FieldSearchSort = FieldSearchSort;
|
107 |
|
108 |
|
109 |
|
110 |
|
111 |
|
112 | class GeoDistanceSearchSort extends SearchSort {
|
113 | |
114 |
|
115 |
|
116 | constructor(field, lat, lon) {
|
117 | super({
|
118 | by: 'geo_distance',
|
119 | field: field,
|
120 | location: [lon, lat],
|
121 | });
|
122 | }
|
123 | unit(unit) {
|
124 | this._data.unit = unit;
|
125 | return this;
|
126 | }
|
127 | descending(descending) {
|
128 | this._data.desc = descending;
|
129 | return this;
|
130 | }
|
131 | }
|
132 | exports.GeoDistanceSearchSort = GeoDistanceSearchSort;
|