@@ -33,11 +33,9 @@ class SearchService {
33
33
size : isFrontPageSearch ? 15 : 100 ,
34
34
query : {
35
35
bool : {
36
- filter : { } ,
36
+ // filter: {},
37
37
must : [ ] ,
38
38
must_not : [ ]
39
- // should: [
40
- // ]
41
39
}
42
40
} ,
43
41
'sort' : [
@@ -57,55 +55,148 @@ class SearchService {
57
55
}
58
56
} ;
59
57
60
- if ( searchParams . district === undefined || searchParams . district === '' ) {
61
- searchQuery . body . query . bool . filter . geo_distance = {
62
- distance : '7km' ,
63
- 'address.geo' : {
64
- lat : latitude ,
65
- lon : longitude
66
- }
67
- } ;
68
- } else {
69
- searchQuery . body . query . bool . filter . geo_shape = {
70
- 'address.geometry' : {
71
- 'indexed_shape' : {
72
- 'index' : 'stadtteile' ,
73
- 'type' : 'stadtteil' ,
74
- 'id' : ( searchParams . district === undefined ? '' : searchParams . district ) ,
75
- 'path' : 'geometry'
76
- }
77
- }
78
- } ;
79
- }
80
-
81
- if ( ( searchParams . category === 'construction' ) || isFrontPageSearch ) {
82
- searchQuery . body . query . bool . must . push ( {
83
- range : {
84
- date_start : {
85
- gte : '2017-11-01' ,
86
- }
87
- }
88
- }
89
- ) ;
90
- }
91
-
92
- // should: [
93
- // { term: { author: 'kimchy' } },
94
- // { bool: { must: [
95
- // { match: { message: 'this is a test' } },
96
- // { term: { type: 'comment' } }
97
- // ] } }
98
- // ]
58
+ // if (!searchParams.district) {
59
+ // searchQuery.body.query.bool.filter.geo_distance = {
60
+ // distance: '7km',
61
+ // 'address.geo': {
62
+ // lat: latitude,
63
+ // lon: longitude
64
+ // }
65
+ // };
66
+ // }
67
+ // else
68
+ // if (centerLat && centerLon) {
69
+ // console.log("TEST");
70
+ // if (!searchQuery.body.query.bool.must) {
71
+ // searchQuery.body.query.bool.must = []
72
+ // };
73
+ // if (!searchQuery.body.query.bool.should) {
74
+ // searchQuery.body.query.bool.should = []
75
+ // };
76
+ // searchQuery.body.query.bool.should.push({'geo_distance' : {
77
+ // distance: '1km',
78
+ // 'address.geo': {
79
+ // lat: centerLat,
80
+ // lon: centerLon
81
+ // }
82
+ // }
83
+ // });
84
+ //
85
+ // // )
86
+ // // filter.geo_distance = {
87
+ // // distance: '1km',
88
+ // // 'address.geo': {
89
+ // // lat: centerLat,
90
+ // // lon: centerLon
91
+ // // }
92
+ // // };
93
+ // }
99
94
100
- if ( searchParams . searchQuery !== undefined && searchParams . searchQuery !== '' ) {
95
+ // if (searchParams.searchQuery !== undefined && searchParams.searchQuery !== '') {
96
+ if ( searchParams . searchQuery ) {
101
97
searchQuery . body . query . bool . must . push ( { query_string : { 'query' : searchParams . searchQuery } } ) ;
102
98
}
103
- if ( searchParams . category ) {
99
+
100
+ if ( searchParams . category ) {
104
101
searchQuery . body . query . bool . must . push ( { term : { 'type' : searchParams . category } } ) ;
102
+ } else {
103
+
104
+ // searchQuery.body.query.bool.should.push(
105
+ if ( ! searchQuery . body . query . bool . should ) {
106
+ searchQuery . body . query . bool . should = [ ]
107
+ } ;
108
+ // searchQuery.body.query.bool.should.push(
109
+ searchQuery . body . query . bool . should . push (
110
+ {
111
+ "bool" : {
112
+ "must" : [
113
+ {
114
+ "term" : {
115
+ "type" : "construction"
116
+ }
117
+ } ,
118
+ {
119
+ "range" : {
120
+ "date_start" : {
121
+ "gte" : "now" ,
122
+ "lte" : "now+10d"
123
+ }
124
+ }
125
+ } ,
126
+ {
127
+ "geo_distance" : {
128
+ "distance" : "2km" ,
129
+ "address.geo" : {
130
+ "lat" : centerLat ? centerLat : latitude ,
131
+ "lon" : centerLon ? centerLon : longitude
132
+ }
133
+ }
134
+ }
135
+ ]
136
+ }
137
+ } ,
138
+ {
139
+ "bool" : {
140
+ "must_not" : [
141
+ {
142
+ "term" : {
143
+ "type" : "construction"
144
+ }
145
+ }
146
+ ] ,
147
+ "must" : [
148
+ {
149
+ "geo_distance" : {
150
+ "distance" : "2km" ,
151
+ "address.geo" : {
152
+ "lat" : centerLat ? centerLat : latitude ,
153
+ "lon" : centerLon ? centerLon : longitude
154
+ }
155
+ }
156
+ }
157
+ ]
158
+ }
159
+ } ) ;
160
+
161
+
162
+
163
+ // searchQuery.body.query.bool.filter = {
164
+ // "bool": {
165
+ // "should": [
166
+ // {
167
+ // "bool": {
168
+ // "must": [
169
+ // {
170
+ // "term": {
171
+ // "type": "construction"
172
+ // }
173
+ // },
174
+ // {
175
+ // "range": {
176
+ // "date_start": {
177
+ // "gte": "now",
178
+ // "lte": "now+10d"
179
+ // }
180
+ // }
181
+ // }
182
+ // ]
183
+ // }
184
+ // },
185
+ // {
186
+ // "bool": {
187
+ // "must_not": [
188
+ // {
189
+ // "term": {
190
+ // "type": "construction"
191
+ // }
192
+ // }
193
+ // ]
194
+ // }
195
+ // }
196
+ // ]
197
+ // }
198
+ // }
105
199
}
106
- // if ( searchParams.district) {
107
- // searchQuery.body.query.bool.must.push({term: {'address.district': searchParams.district}});
108
- // }
109
200
110
201
client
111
202
. search (
0 commit comments