7
7
8
8
final class SearchFormQueryBuilder implements QueryBuilderInterface
9
9
{
10
+ /**
11
+ * @var string
12
+ */
13
+ private $ organizationParentChildrenIds ;
14
+
15
+ /**
16
+ * @var string
17
+ */
18
+ private $ searchType ;
19
+
10
20
/**
11
21
* @var string
12
22
*/
@@ -72,6 +82,18 @@ final class SearchFormQueryBuilder implements QueryBuilderInterface
72
82
*/
73
83
private $ indexing ;
74
84
85
+ public function organizationParentChildrenIds (array $ organizationParentChildrenIds ): self
86
+ {
87
+ $ this ->organizationParentChildrenIds = $ organizationParentChildrenIds ;
88
+ return $ this ;
89
+ }
90
+
91
+ public function searchType (string $ searchType ): self
92
+ {
93
+ $ this ->searchType = $ searchType ;
94
+ return $ this ;
95
+ }
96
+
75
97
public function query (string $ query ): self
76
98
{
77
99
$ this ->query = $ query ;
@@ -183,47 +205,89 @@ public function buildQuery(): array
183
205
];
184
206
}
185
207
208
+ if (!empty ($ this ->searchType )) {
209
+ if (
210
+ $ this ->searchType === 'my_projects '
211
+ || $ this ->searchType === 'org_projects_admin '
212
+ || $ this ->searchType === 'org_projects_non_admin '
213
+ ) {
214
+ if (!empty ($ this ->organizationIds )) {
215
+ $ queries [] = [
216
+ 'terms ' => [
217
+ 'organization_id ' => $ this ->organizationIds
218
+ ]
219
+ ];
220
+ }
186
221
187
- if (empty ($ this ->organizationIds ) && !empty ($ this ->organizationVisibilityTypeIds )) {
188
- if (in_array (null , $ this ->organizationVisibilityTypeIds , true )) {
189
- $ queries [] = [
190
- 'bool ' => [
191
- 'should ' => [
192
- [
193
- 'terms ' => [
194
- 'organization_visibility_type_id ' => array_values (array_filter ($ this ->organizationVisibilityTypeIds ))
195
- ]
196
- ],
197
- [
198
- 'bool ' => [
199
- 'must_not ' => [
200
- 'exists ' => [
201
- 'field ' => 'organization_visibility_type_id '
202
- ]
222
+ if ($ this ->searchType === 'org_projects_non_admin ' ) {
223
+ $ queries [] = [
224
+ 'bool ' => [
225
+ 'must_not ' => [
226
+ [
227
+ 'terms ' => [
228
+ 'organization_visibility_type_id ' => [config ('constants.private-organization-visibility-type-id ' )]
203
229
]
204
230
]
205
231
]
206
232
]
233
+ ];
234
+ }
235
+ } elseif ($ this ->searchType === 'showcase_projects ' ) {
236
+ // Get all public items
237
+ $ organizationIdsShouldQueries [] = [
238
+ 'terms ' => [
239
+ 'organization_visibility_type_id ' => [config ('constants.public-organization-visibility-type-id ' )]
207
240
]
208
241
];
209
- } else {
210
- $ queries [] = [
242
+
243
+ // Get all global items
244
+ $ globalOrganizationIdsQueries [] = [
211
245
'terms ' => [
212
- 'organization_visibility_type_id ' => $ this ->organizationVisibilityTypeIds
246
+ 'organization_id ' => $ this ->organizationParentChildrenIds
213
247
]
214
248
];
215
- }
216
- } elseif (!empty ($ this ->organizationIds )) {
217
249
218
- $ organizationIdsQueries [] = [
219
- 'terms ' => [
220
- 'organization_id ' => $ this ->organizationIds
221
- ]
222
- ];
250
+ $ globalOrganizationIdsQueries [] = [
251
+ 'terms ' => [
252
+ 'organization_visibility_type_id ' => [config ('constants.global-organization-visibility-type-id ' )]
253
+ ]
254
+ ];
255
+
256
+ $ organizationIdsShouldQueries [] = [
257
+ 'bool ' => [
258
+ 'must ' => $ globalOrganizationIdsQueries
259
+ ]
260
+ ];
261
+
262
+ // Get all protected items
263
+ $ protectedOrganizationIdsQueries [] = [
264
+ 'terms ' => [
265
+ 'organization_id ' => $ this ->organizationIds
266
+ ]
267
+ ];
268
+
269
+ $ protectedOrganizationIdsQueries [] = [
270
+ 'terms ' => [
271
+ 'organization_visibility_type_id ' => [config ('constants.protected-organization-visibility-type-id ' )]
272
+ ]
273
+ ];
274
+
275
+ $ organizationIdsShouldQueries [] = [
276
+ 'bool ' => [
277
+ 'must ' => $ protectedOrganizationIdsQueries
278
+ ]
279
+ ];
223
280
281
+ $ queries [] = [
282
+ 'bool ' => [
283
+ 'should ' => $ organizationIdsShouldQueries
284
+ ]
285
+ ];
286
+ }
287
+ } else {
224
288
if (!empty ($ this ->organizationVisibilityTypeIds )) {
225
289
if (in_array (null , $ this ->organizationVisibilityTypeIds , true )) {
226
- $ organizationIdsQueries [] = [
290
+ $ queries [] = [
227
291
'bool ' => [
228
292
'should ' => [
229
293
[
@@ -244,36 +308,13 @@ public function buildQuery(): array
244
308
]
245
309
];
246
310
} else {
247
- $ organizationIdsQueries [] = [
311
+ $ queries [] = [
248
312
'terms ' => [
249
313
'organization_visibility_type_id ' => $ this ->organizationVisibilityTypeIds
250
314
]
251
315
];
252
316
}
253
-
254
- $ globalPublicVisibilityTypeIds = [config ('constants.global-organization-visibility-type-id ' ), config ('constants.public-organization-visibility-type-id ' )];
255
- $ commonVisibilityTypeIds = array_values (array_intersect ($ this ->organizationVisibilityTypeIds , $ globalPublicVisibilityTypeIds ));
256
-
257
- if (!empty ($ commonVisibilityTypeIds )) {
258
- $ organizationIdsShouldQueries [] = [
259
- 'terms ' => [
260
- 'organization_visibility_type_id ' => $ commonVisibilityTypeIds
261
- ]
262
- ];
263
- }
264
317
}
265
-
266
- $ organizationIdsShouldQueries [] = [
267
- 'bool ' => [
268
- 'must ' => $ organizationIdsQueries
269
- ]
270
- ];
271
-
272
- $ queries [] = [
273
- 'bool ' => [
274
- 'should ' => $ organizationIdsShouldQueries
275
- ]
276
- ];
277
318
}
278
319
279
320
if (!empty ($ this ->subjectIds )) {
0 commit comments