Completed
Push — master ( 331875...25ce0f )
by Maxence
01:35
created

SearchRequest::setAuthor()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 5

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
dl 0
loc 5
c 0
b 0
f 0
rs 10
nc 1
cc 1
nop 1
1
<?php
2
declare(strict_types=1);
3
4
5
/**
6
 * FullTextSearch - Full text search framework for Nextcloud
7
 *
8
 * This file is licensed under the Affero General Public License version 3 or
9
 * later. See the COPYING file.
10
 *
11
 * @author Maxence Lange <[email protected]>
12
 * @copyright 2018
13
 * @license GNU AGPL version 3 or any later version
14
 *
15
 * This program is free software: you can redistribute it and/or modify
16
 * it under the terms of the GNU Affero General Public License as
17
 * published by the Free Software Foundation, either version 3 of the
18
 * License, or (at your option) any later version.
19
 *
20
 * This program is distributed in the hope that it will be useful,
21
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
22
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
23
 * GNU Affero General Public License for more details.
24
 *
25
 * You should have received a copy of the GNU Affero General Public License
26
 * along with this program.  If not, see <http://www.gnu.org/licenses/>.
27
 *
28
 */
29
30
31
namespace OCA\FullTextSearch\Model;
32
33
34
use daita\MySmallPhpTools\Traits\TArrayTools;
35
use JsonSerializable;
36
use OCP\FullTextSearch\Model\ISearchRequest;
37
use OCP\FullTextSearch\Model\ISearchRequestSimpleQuery;
38
39
40
/**
41
 * Class SearchRequest
42
 *
43
 * @package OCA\FullTextSearch\Model
44
 */
45
class SearchRequest implements ISearchRequest, JsonSerializable {
46
47
48
	use TArrayTools;
49
50
51
	/** @var array */
52
	private $providers;
53
54
	/** @var string */
55
	private $search;
56
57
	/** @var bool */
58
	private $emptySearch = false;
59
60
	/** @var int */
61
	private $page = 1;
62
63
	/** @var int */
64
	private $size = 10;
65
66
	/** @var string */
67
	private $author;
68
69
	/** @var array */
70
	private $tags = [];
71
72
	/** @var array */
73
	public $metaTags = [];
74
75
	/** @var array */
76
	public $subTags = [];
77
78
	/** @var array */
79
	private $options;
80
81
	/** @var array */
82
	private $parts = [];
83
84
	/** @var array */
85
	private $fields = [];
86
87
	/** @var array */
88
	private $limitFields = [];
89
90
	/** @var array */
91
	private $wildcardFields = [];
92
93
//	/** @var array */
94
//	private $wildcardQueries = [];
95
96
	/** @var array */
97
	private $wildcardFilters = [];
98
99
	/** @var array */
100
	private $regexFilters = [];
101
102
	/** @var array */
103
	private $simpleQueries = [];
104
105
106
	/**
107
	 * SearchRequest constructor.
108
	 */
109
	public function __construct() {
110
	}
111
112
113
	/**
114
	 * @return array
115
	 */
116
	public function getProviders(): array {
117
		return $this->providers;
118
	}
119
120
	/**
121
	 * @param array $providers
122
	 *
123
	 * @return ISearchRequest
0 ignored issues
show
Documentation introduced by
Consider making the return type a bit more specific; maybe use SearchRequest.

This check looks for the generic type array as a return type and suggests a more specific type. This type is inferred from the actual code.

Loading history...
124
	 */
125
	public function setProviders(array $providers): ISearchRequest {
126
		$this->providers = $providers;
127
128
		return $this;
129
	}
130
131
132
	/**
133
	 * @return string
134
	 */
135
	public function getAuthor(): string {
136
		return $this->author;
137
	}
138
139
	/**
140
	 * @param string $author
141
	 *
142
	 * @return ISearchRequest
0 ignored issues
show
Documentation introduced by
Consider making the return type a bit more specific; maybe use SearchRequest.

This check looks for the generic type array as a return type and suggests a more specific type. This type is inferred from the actual code.

Loading history...
143
	 */
144
	public function setAuthor(string $author): ISearchRequest {
145
		$this->author = $author;
146
147
		return $this;
148
	}
149
150
151
	/**
152
	 * @return string
153
	 */
154
	public function getSearch(): string {
155
		return $this->search;
156
	}
157
158
	/**
159
	 * @param string $search
160
	 *
161
	 * @return ISearchRequest
0 ignored issues
show
Documentation introduced by
Consider making the return type a bit more specific; maybe use SearchRequest.

This check looks for the generic type array as a return type and suggests a more specific type. This type is inferred from the actual code.

Loading history...
162
	 */
163
	public function setSearch(string $search): ISearchRequest {
164
		$this->search = $search;
165
166
		return $this;
167
	}
168
169
	/**
170
	 * @param string $search
171
	 *
172
	 * @return ISearchRequest
0 ignored issues
show
Documentation introduced by
Consider making the return type a bit more specific; maybe use SearchRequest.

This check looks for the generic type array as a return type and suggests a more specific type. This type is inferred from the actual code.

Loading history...
173
	 */
174
	public function addSearch(string $search): ISearchRequest {
175
		$this->search .= ' ' . $search;
176
177
		return $this;
178
	}
179
180
181
	/**
182
	 * @return bool
183
	 */
184
	public function isEmptySearch(): bool {
185
		return $this->emptySearch;
186
	}
187
188
	/**
189
	 * @param bool $emptySearch
190
	 *
191
	 * @return ISearchRequest
0 ignored issues
show
Documentation introduced by
Consider making the return type a bit more specific; maybe use SearchRequest.

This check looks for the generic type array as a return type and suggests a more specific type. This type is inferred from the actual code.

Loading history...
192
	 */
193
	public function setEmptySearch(bool $emptySearch): ISearchRequest {
194
		$this->emptySearch = $emptySearch;
195
196
		return $this;
197
	}
198
199
200
	/**
201
	 *
202
	 */
203
	public function cleanSearch(): ISearchRequest {
204
		$search = trim(str_replace('  ', ' ', $this->getSearch()));
205
206
		preg_match_all('/[^?]"(?:\\\\.|[^\\\\"])*"|\S+/', " $search ", $words);
207
		$searchItems = [];
208
		foreach ($words[0] as $word) {
209
			if ($this->searchQueryOptions($word)) {
210
				continue;
211
			}
212
213
			$searchItems[] = $word;
214
		}
215
216
		$this->setSearch(implode(" ", $searchItems));
217
218
		return $this;
219
	}
220
221
222
	/**
223
	 * @param string $word
224
	 *
225
	 * @return bool
226
	 */
227
	private function searchQueryOptions(string $word): bool {
228
		if (($pos = strpos($word, ':')) === false || $pos === 0) {
229
			return false;
230
		}
231
232
		list($kw, $value) = explode(':', $word, 2);
233
234
		$options = ['is', 'show'];
235
		if (in_array($kw, $options)) {
236
			$this->addOption($kw . '_' . $value, '1');
237
238
			return true;
239
		}
240
241
		$valuedOptions = ['in', 'meta'];
242
		if (in_array($kw, $valuedOptions)) {
243
			$this->addMultipleOption($kw, $value);
244
245
			return true;
246
		}
247
248
		$valuedSubOptions = ['and'];
249
		if (in_array($kw, $valuedSubOptions)) {
250
			list($key, $value) = explode(':', $value, 2);
251
			$this->addMultipleOption($kw . ':' . $key, $value);
252
253
			return true;
254
		}
255
256
		return false;
257
	}
258
259
260
	/**
261
	 * @return int
262
	 */
263
	public function getPage(): int {
264
		return $this->page;
265
	}
266
267
	/**
268
	 * @param int $page
269
	 *
270
	 * @return ISearchRequest
0 ignored issues
show
Documentation introduced by
Consider making the return type a bit more specific; maybe use SearchRequest.

This check looks for the generic type array as a return type and suggests a more specific type. This type is inferred from the actual code.

Loading history...
271
	 */
272
	public function setPage(int $page): ISearchRequest {
273
		if ($page < 1) {
274
			$page = 1;
275
		}
276
277
		$this->page = $page;
278
279
		return $this;
280
	}
281
282
283
	/**
284
	 * @return int
285
	 */
286
	public function getSize(): int {
287
		return $this->size;
288
	}
289
290
	/**
291
	 * @param int $size
292
	 *
293
	 * @return ISearchRequest
0 ignored issues
show
Documentation introduced by
Consider making the return type a bit more specific; maybe use SearchRequest.

This check looks for the generic type array as a return type and suggests a more specific type. This type is inferred from the actual code.

Loading history...
294
	 */
295
	public function setSize(int $size): ISearchRequest {
296
		$this->size = $size;
297
298
		return $this;
299
	}
300
301
302
	/**
303
	 * @return array
304
	 */
305
	public function getOptions(): array {
306
		return $this->options;
307
	}
308
309
	/**
310
	 * @param array $options
311
	 *
312
	 * @return ISearchRequest
0 ignored issues
show
Documentation introduced by
Consider making the return type a bit more specific; maybe use SearchRequest.

This check looks for the generic type array as a return type and suggests a more specific type. This type is inferred from the actual code.

Loading history...
313
	 */
314
	public function setOptions(array $options): ISearchRequest {
315
		$this->options = $options;
316
317
		return $this;
318
	}
319
320
	/**
321
	 * @param $option
322
	 * @param $value
323
	 *
324
	 * @return ISearchRequest
0 ignored issues
show
Documentation introduced by
Consider making the return type a bit more specific; maybe use SearchRequest.

This check looks for the generic type array as a return type and suggests a more specific type. This type is inferred from the actual code.

Loading history...
325
	 */
326
	public function addOption(string $option, string $value): ISearchRequest {
327
		$this->options[$option] = $value;
328
329
		return $this;
330
	}
331
332
	/**
333
	 * @param string $option
334
	 * @param array $value
335
	 *
336
	 * @return ISearchRequest
0 ignored issues
show
Documentation introduced by
Consider making the return type a bit more specific; maybe use SearchRequest.

This check looks for the generic type array as a return type and suggests a more specific type. This type is inferred from the actual code.

Loading history...
337
	 */
338
	public function addOptionArray(string $option, array $value): ISearchRequest {
339
		$this->options[$option] = $value;
340
341
		return $this;
342
	}
343
344
	/**
345
	 * @param string $option
346
	 * @param bool $value
347
	 *
348
	 * @return ISearchRequest
0 ignored issues
show
Documentation introduced by
Consider making the return type a bit more specific; maybe use SearchRequest.

This check looks for the generic type array as a return type and suggests a more specific type. This type is inferred from the actual code.

Loading history...
349
	 */
350
	public function addOptionBool(string $option, bool $value): ISearchRequest {
351
		$this->options[$option] = $value;
352
353
		return $this;
354
	}
355
356
	/**
357
	 * @param string $option
358
	 * @param string $value
359
	 *
360
	 * @return ISearchRequest
0 ignored issues
show
Documentation introduced by
Consider making the return type a bit more specific; maybe use SearchRequest.

This check looks for the generic type array as a return type and suggests a more specific type. This type is inferred from the actual code.

Loading history...
361
	 */
362
	public function addMultipleOption(string $option, string $value): ISearchRequest {
363
		if (!array_key_exists($option, $this->options)) {
364
			$this->options[$option] = [];
365
		}
366
367
		$this->options[$option][] = $value;
368
369
		return $this;
370
	}
371
372
	/**
373
	 * @param string $option
374
	 * @param string $default
375
	 *
376
	 * @return string
377
	 */
378
	public function getOption(string $option, string $default = ''): string {
379
		return $this->get($option, $this->options, $default);
380
	}
381
382
383
	/**
384
	 * @param string $option
385
	 * @param array $default
386
	 *
387
	 * @return array
388
	 */
389
	public function getOptionArray(string $option, array $default = []): array {
390
		return $this->getArray($option, $this->options, $default);
391
	}
392
393
394
	/**
395
	 * @param string $part
396
	 *
397
	 * @return ISearchRequest
0 ignored issues
show
Documentation introduced by
Consider making the return type a bit more specific; maybe use SearchRequest.

This check looks for the generic type array as a return type and suggests a more specific type. This type is inferred from the actual code.

Loading history...
398
	 */
399
	public function addPart(string $part): ISearchRequest {
400
		$this->parts[] = $part;
401
402
		return $this;
403
	}
404
405
	/**
406
	 * @return array
407
	 */
408
	public function getParts(): array {
409
		return $this->parts;
410
	}
411
412
413
	/**
414
	 * @param array $parts
415
	 *
416
	 * @return ISearchRequest
0 ignored issues
show
Documentation introduced by
Consider making the return type a bit more specific; maybe use SearchRequest.

This check looks for the generic type array as a return type and suggests a more specific type. This type is inferred from the actual code.

Loading history...
417
	 * @since 15.0.0
418
	 *
419
	 */
420
	public function setParts(array $parts): ISearchRequest {
421
		$this->parts = $parts;
422
423
		return $this;
424
	}
425
426
427
	/**
428
	 * @return array
429
	 */
430
	public function getFields(): array {
431
		return $this->fields;
432
	}
433
434
	/**
435
	 * @param array $fields
436
	 *
437
	 * @return ISearchRequest
0 ignored issues
show
Documentation introduced by
Consider making the return type a bit more specific; maybe use SearchRequest.

This check looks for the generic type array as a return type and suggests a more specific type. This type is inferred from the actual code.

Loading history...
438
	 */
439
	public function setFields(array $fields): ISearchRequest {
440
		$this->fields = $fields;
441
442
		return $this;
443
	}
444
445
446
	/**
447
	 * @param string $field
448
	 *
449
	 * @return ISearchRequest
0 ignored issues
show
Documentation introduced by
Consider making the return type a bit more specific; maybe use SearchRequest.

This check looks for the generic type array as a return type and suggests a more specific type. This type is inferred from the actual code.

Loading history...
450
	 */
451
	public function addLimitField(string $field): ISearchRequest {
452
		array_push($this->limitFields, $field);
453
454
		return $this;
455
	}
456
457
	/**
458
	 * @return array
459
	 */
460
	public function getLimitFields(): array {
461
		return $this->limitFields;
462
	}
463
464
465
	/**
466
	 * @param string $field
467
	 *
468
	 * @return ISearchRequest
0 ignored issues
show
Documentation introduced by
Consider making the return type a bit more specific; maybe use SearchRequest.

This check looks for the generic type array as a return type and suggests a more specific type. This type is inferred from the actual code.

Loading history...
469
	 */
470
	public function addField(string $field): ISearchRequest {
471
		$this->fields[] = $field;
472
473
		return $this;
474
	}
475
476
477
	/**
478
	 * @param string $tag
479
	 *
480
	 * @return ISearchRequest
0 ignored issues
show
Documentation introduced by
Consider making the return type a bit more specific; maybe use SearchRequest.

This check looks for the generic type array as a return type and suggests a more specific type. This type is inferred from the actual code.

Loading history...
481
	 */
482
	public function addTag(string $tag): ISearchRequest {
483
		$this->tags[] = $tag;
484
485
		return $this;
486
	}
487
488
	/**
489
	 * @return array
490
	 */
491
	public function getTags(): array {
492
		return $this->tags;
493
	}
494
495
	/**
496
	 * @param array $tags
497
	 *
498
	 * @return ISearchRequest
0 ignored issues
show
Documentation introduced by
Consider making the return type a bit more specific; maybe use SearchRequest.

This check looks for the generic type array as a return type and suggests a more specific type. This type is inferred from the actual code.

Loading history...
499
	 */
500
	public function setTags(array $tags): ISearchRequest {
501
		$this->tags = $tags;
502
503
		return $this;
504
	}
505
506
507
	/**
508
	 * @param array $tags
509
	 *
510
	 * @return ISearchRequest
0 ignored issues
show
Documentation introduced by
Consider making the return type a bit more specific; maybe use SearchRequest.

This check looks for the generic type array as a return type and suggests a more specific type. This type is inferred from the actual code.

Loading history...
511
	 */
512
	public function setMetaTags(array $tags): ISearchRequest {
513
		$this->metaTags = $tags;
514
515
		return $this;
516
	}
517
518
	/**
519
	 * @return array
520
	 */
521
	public function getMetaTags(): array {
522
		return $this->metaTags;
523
	}
524
525
	/**
526
	 * @param string $tag
527
	 *
528
	 * @return ISearchRequest
0 ignored issues
show
Documentation introduced by
Consider making the return type a bit more specific; maybe use SearchRequest.

This check looks for the generic type array as a return type and suggests a more specific type. This type is inferred from the actual code.

Loading history...
529
	 */
530
	public function addMetaTag(string $tag): ISearchRequest {
531
		$this->metaTags[] = $tag;
532
533
		return $this;
534
	}
535
536
537
	/**
538
	 * @param array $tags
539
	 *
540
	 * @return ISearchRequest
0 ignored issues
show
Documentation introduced by
Consider making the return type a bit more specific; maybe use SearchRequest.

This check looks for the generic type array as a return type and suggests a more specific type. This type is inferred from the actual code.

Loading history...
541
	 */
542
	public function setSubTags(array $tags): ISearchRequest {
543
		$this->subTags = $tags;
544
545
		return $this;
546
	}
547
548
	/**
549
	 * @param bool $formatted
550
	 *
551
	 * @return array
552
	 */
553
	public function getSubTags(bool $formatted = false): array {
554
		if ($formatted === false) {
555
			return $this->subTags;
556
		}
557
558
		$subTags = [];
559
		$ak = array_keys($this->subTags);
560
		foreach ($ak as $source) {
561
			$tags = $this->subTags[$source];
562
			foreach ($tags as $tag) {
563
				$subTags[] = $source . '_' . $tag;
564
			}
565
		}
566
567
		return $subTags;
568
	}
569
570
	/**
571
	 * @param string $source
572
	 * @param string $tag
573
	 *
574
	 * @return ISearchRequest
0 ignored issues
show
Documentation introduced by
Consider making the return type a bit more specific; maybe use SearchRequest.

This check looks for the generic type array as a return type and suggests a more specific type. This type is inferred from the actual code.

Loading history...
575
	 */
576
	public function addSubTag(string $source, string $tag): ISearchRequest {
577
		if (!array_key_exists($source, $this->subTags)) {
578
			$this->subTags[$source] = [];
579
		}
580
581
		$this->subTags[$source][] = $tag;
582
583
		return $this;
584
	}
585
586
587
	/**
588
	 * @param string $field
589
	 *
590
	 * @return ISearchRequest
0 ignored issues
show
Documentation introduced by
Consider making the return type a bit more specific; maybe use SearchRequest.

This check looks for the generic type array as a return type and suggests a more specific type. This type is inferred from the actual code.

Loading history...
591
	 */
592
	public function addWildcardField(string $field): ISearchRequest {
593
		$this->wildcardFields[] = $field;
594
595
		return $this;
596
	}
597
598
599
	/**
600
	 * @return array
601
	 */
602
	public function getWildcardFields(): array {
603
		return $this->wildcardFields;
604
	}
605
606
//
607
//	/**
608
//	 * @param array $query
609
//	 *
610
//	 * @return ISearchRequest
611
//	 */
612
//	public function addWildcardQuery($query) {
613
//		$this->addWildcardQueries([$query]);
614
//
615
//		return $this;
616
//	}
617
//
618
//	/**
619
//	 * @param array $query
620
//	 *
621
//	 * @return ISearchRequest
622
//	 */
623
//	public function addWildcardQueries($query) {
624
//		array_push($this->wildcardQueries, $query);
625
//
626
//		return $this;
627
//	}
628
//
629
//	/**
630
//	 * @return array
631
//	 */
632
//	public function getWildcardQueries() {
633
//		return $this->wildcardQueries;
634
//	}
635
636
637
	/**
638
	 * @param array $filter
639
	 *
640
	 * @return ISearchRequest
0 ignored issues
show
Documentation introduced by
Consider making the return type a bit more specific; maybe use SearchRequest.

This check looks for the generic type array as a return type and suggests a more specific type. This type is inferred from the actual code.

Loading history...
641
	 */
642
	public function addWildcardFilter(array $filter): ISearchRequest {
643
		$this->addWildcardFilters([$filter]);
644
645
		return $this;
646
	}
647
648
	/**
649
	 * @param array $filters
650
	 *
651
	 * @return ISearchRequest
0 ignored issues
show
Documentation introduced by
Consider making the return type a bit more specific; maybe use SearchRequest.

This check looks for the generic type array as a return type and suggests a more specific type. This type is inferred from the actual code.

Loading history...
652
	 */
653
	public function addWildcardFilters(array $filters): ISearchRequest {
654
		array_push($this->wildcardFilters, $filters);
655
656
		return $this;
657
	}
658
659
	/**
660
	 * @return array
661
	 */
662
	public function getWildcardFilters(): array {
663
		return $this->wildcardFilters;
664
	}
665
666
667
	/**
668
	 * @param string $filter
669
	 *
670
	 * @return ISearchRequest
0 ignored issues
show
Documentation introduced by
Consider making the return type a bit more specific; maybe use SearchRequest.

This check looks for the generic type array as a return type and suggests a more specific type. This type is inferred from the actual code.

Loading history...
671
	 */
672
	public function addRegexFilter(string $filter): ISearchRequest {
673
		$this->addRegexFilters([$filter]);
674
675
		return $this;
676
	}
677
678
	/**
679
	 * @param array $filters
680
	 *
681
	 * @return ISearchRequest
0 ignored issues
show
Documentation introduced by
Consider making the return type a bit more specific; maybe use SearchRequest.

This check looks for the generic type array as a return type and suggests a more specific type. This type is inferred from the actual code.

Loading history...
682
	 */
683
	public function addRegexFilters(array $filters): ISearchRequest {
684
		array_push($this->regexFilters, $filters);
685
686
		return $this;
687
	}
688
689
	/**
690
	 * @return array
691
	 */
692
	public function getRegexFilters(): array {
693
		return $this->regexFilters;
694
	}
695
696
697
	/**
698
	 * @param ISearchRequestSimpleQuery $query
699
	 *
700
	 * @return ISearchRequest
0 ignored issues
show
Documentation introduced by
Consider making the return type a bit more specific; maybe use SearchRequest.

This check looks for the generic type array as a return type and suggests a more specific type. This type is inferred from the actual code.

Loading history...
701
	 */
702
	public function addSimpleQuery(ISearchRequestSimpleQuery $query): ISearchRequest {
703
		$this->simpleQueries[] = $query;
704
705
		return $this;
706
	}
707
708
709
	/**
710
	 * @return ISearchRequestSimpleQuery[]
711
	 */
712
	public function getSimpleQueries(): array {
713
		return $this->simpleQueries;
714
	}
715
716
717
	/**
718
	 * @return array
719
	 */
720
	public function jsonSerialize(): array {
721
		return [
722
			'providers' => $this->getProviders(),
723
			'author' => $this->getAuthor(),
724
			'search' => $this->getSearch(),
725
			'empty_search' => $this->isEmptySearch(),
726
			'page' => $this->getPage(),
727
			'size' => $this->getSize(),
728
			'parts' => $this->getParts(),
729
			'queries' => $this->getSimpleQueries(),
730
			'options' => $this->getOptions(),
731
			'metatags' => $this->getMetaTags(),
732
			'subtags' => $this->getSubTags(),
733
			'tags' => $this->getTags()
734
		];
735
	}
736
737
738
	/**
739
	 * @param array $arr
740
	 *
741
	 * @return SearchRequest
742
	 */
743
	public function importFromArray($arr): SearchRequest {
744
		$providers = $arr['providers'];
745
		if (!is_array($providers)) {
746
			$providers = [$providers];
747
		}
748
749
		$this->setProviders($providers);
750
		$this->setAuthor($this->get('author', $arr, ''));
751
		$this->setSearch($this->get('search', $arr, ''));
752
753
		// TODO: remove this in nc19:
754
		if ($this->get('empty_search', $arr, '') === 'true') {
755
			$this->setEmptySearch(true);
756
		} else {
757
			$this->setEmptySearch($this->getBool('empty_search', $arr, false));
758
		}
759
		// END TODO
760
761
//		$this->setEmptySearch($this->getBool('empty_search', $arr, false));
762
		$this->setPage($this->getInt('page', $arr, 0));
763
		$this->setParts($this->getArray('parts', $arr, []));
764
		$this->setSize($this->getInt('size', $arr, 10));
765
		$this->setOptions($this->getArray('options', $arr, []));
766
		$this->setMetaTags($this->getArray('metatags', $arr, []));
767
		$this->setSubTags($this->getArray('subtags', $arr, []));
768
		$this->setTags($this->getArray('tags', $arr, []));
769
770
		return $this;
771
	}
772
773
774
	/**
775
	 * @param string $json
776
	 *
777
	 * @return SearchRequest
778
	 */
779
	public static function fromJSON(string $json): SearchRequest {
780
		$searchRequest = new SearchRequest();
781
		$searchRequest->importFromArray(json_decode($json, true));
782
783
		return $searchRequest;
784
	}
785
786
}
787