ILIAS  trunk Revision v12.0_alpha-16-g3e876e53c80
SearchStateHandlerImpl.php
Go to the documentation of this file.
1<?php
2
19declare(strict_types=1);
20
22
27use ILIAS\HTTP\Services as HTTP;
28use ILIAS\Refinery\Factory as Refinery;
32
34{
35 public function __construct(
36 protected ilSearchSettings $settings,
37 protected LOMServices $lom_services,
38 HTTP $http,
40 ) {
42 }
43
44 public function fetchRequestedRemoteSearchTerm(): string
45 {
46 if ($this->http->wrapper()->post()->has('queryString')) {
47 $term = $this->http->wrapper()->post()->retrieve(
48 'queryString',
49 $this->refinery->kindlyTo()->string()
50 );
51 $qp = new ilLuceneQueryParser($term);
52 $qp->parseAutoWildcard();
53 return $qp->getQuery();
54 }
55 return '';
56 }
57
58 public function fetchFilter(URI $action): ilSearchFilterGUI
59 {
60 return new ilSearchFilterGUI($action, true);
61 }
62
63 public function fetchCache(int $usr_id): ilUserSearchCache
64 {
65 $cache = ilUserSearchCache::_getInstance($usr_id);
66 $cache->switchSearchType(ilUserSearchCache::LUCENE_DEFAULT);
67 return $cache;
68 }
69
70 public function loadFilterToCache(ilSearchFilterGUI $filter, ilUserSearchCache $cache): void
71 {
72 $search_filter_data = $filter->getData();
73
74 $cache->setRoot((int) ($search_filter_data['search_scope'] ?? ROOT_FOLDER_ID));
75
76 $creation_filter = [];
77 if (
78 $this->settings->isDateFilterEnabled() &&
79 isset($search_filter_data['search_date'])
80 ) {
81 $creation_filter['date_start'] = $search_filter_data['search_date'][0];
82 $creation_filter['date_end'] = $search_filter_data['search_date'][1];
83 }
84 $cache->setCreationFilter($creation_filter);
85
86 $types_from_filter = (array) ($search_filter_data['search_type'] ?? []);
87
88 $enabled_types = [];
89 foreach ($this->settings->getEnabledLuceneItemFilterDefinitions() as $type => $data) {
90 if (in_array($type, $types_from_filter)) {
91 $enabled_types[$type] = 1;
92 }
93 }
94 $cache->setItemFilter($enabled_types);
95
96 $enabled_mime_types = [];
97 foreach ($this->settings->getEnabledLuceneMimeFilterDefinitions() as $mime_type => $data) {
98 if (in_array($mime_type, $types_from_filter)) {
99 $enabled_mime_types[$mime_type] = 1;
100 }
101 }
102 $cache->setMimeFilter($enabled_mime_types);
103
104 $copyright_filter = [];
105 if (
106 $this->lom_services->copyrightHelper()->isCopyrightSelectionActive() &&
107 isset($search_filter_data['search_copyright'])
108 ) {
109 $copyright_filter = $search_filter_data['search_copyright'];
110 }
111 $cache->setCopyrightFilter(...$copyright_filter);
112 }
113}
Builds data types.
Definition: Factory.php:36
The scope of this class is split ilias-conform URI's into components.
Definition: URI.php:35
Class Services.
Definition: Services.php:38
fetchRequestedRemoteSearchTerm()
propably needs to be replaced with a completely different mechanism when switching to KS
loadFilterToCache(ilSearchFilterGUI $filter, ilUserSearchCache $cache)
__construct(protected ilSearchSettings $settings, protected LOMServices $lom_services, HTTP $http, Refinery $refinery)
Class for storing search result.
setCreationFilter(array $a_filter)
setItemFilter(array $a_filter)
setMimeFilter(array $a_filter)
setRoot(int $a_root)
set root node of search
static _getInstance(int $a_usr_id)
setCopyrightFilter(string ... $copyright_identifiers)
const ROOT_FOLDER_ID
Definition: constants.php:32
$http
Definition: deliver.php:30
static http()
Fetches the global http state from ILIAS.
__construct(Container $dic, ilPlugin $plugin)
@inheritDoc