Code Coverage |
||||||||||
Lines |
Functions and Methods |
Classes and Traits |
||||||||
Total | |
40.74% |
22 / 54 |
|
0.00% |
0 / 7 |
CRAP | |
0.00% |
0 / 1 |
Options | |
40.74% |
22 / 54 |
|
0.00% |
0 / 7 |
191.15 | |
0.00% |
0 / 1 |
__construct | |
45.83% |
22 / 48 |
|
0.00% |
0 / 1 |
98.92 | |||
getSearchAction | |
0.00% |
0 / 1 |
|
0.00% |
0 / 1 |
2 | |||
getAdvancedSearchAction | |
0.00% |
0 / 1 |
|
0.00% |
0 / 1 |
2 | |||
getFacetListAction | |
0.00% |
0 / 1 |
|
0.00% |
0 / 1 |
2 | |||
getEmptySearchRelevanceOverride | |
0.00% |
0 / 1 |
|
0.00% |
0 / 1 |
2 | |||
getMaxTopicRecommendations | |
0.00% |
0 / 1 |
|
0.00% |
0 / 1 |
2 | |||
setMaxTopicRecommendations | |
0.00% |
0 / 1 |
|
0.00% |
0 / 1 |
2 |
1 | <?php |
2 | |
3 | /** |
4 | * Summon Search Options |
5 | * |
6 | * PHP version 8 |
7 | * |
8 | * Copyright (C) Villanova University 2011. |
9 | * |
10 | * This program is free software; you can redistribute it and/or modify |
11 | * it under the terms of the GNU General Public License version 2, |
12 | * as published by the Free Software Foundation. |
13 | * |
14 | * This program is distributed in the hope that it will be useful, |
15 | * but WITHOUT ANY WARRANTY; without even the implied warranty of |
16 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
17 | * GNU General Public License for more details. |
18 | * |
19 | * You should have received a copy of the GNU General Public License |
20 | * along with this program; if not, write to the Free Software |
21 | * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA |
22 | * |
23 | * @category VuFind |
24 | * @package Search_Summon |
25 | * @author Demian Katz <demian.katz@villanova.edu> |
26 | * @license http://opensource.org/licenses/gpl-2.0.php GNU General Public License |
27 | * @link https://vufind.org Main Page |
28 | */ |
29 | |
30 | namespace VuFind\Search\Summon; |
31 | |
32 | use function count; |
33 | |
34 | /** |
35 | * Summon Search Options |
36 | * |
37 | * @category VuFind |
38 | * @package Search_Summon |
39 | * @author Demian Katz <demian.katz@villanova.edu> |
40 | * @license http://opensource.org/licenses/gpl-2.0.php GNU General Public License |
41 | * @link https://vufind.org Main Page |
42 | */ |
43 | class Options extends \VuFind\Search\Base\Options |
44 | { |
45 | use \VuFind\Config\Feature\ExplodeSettingTrait; |
46 | use \VuFind\Search\Options\ViewOptionsTrait; |
47 | |
48 | /** |
49 | * Maximum number of topic recommendations to show (false for none) |
50 | * |
51 | * @var int|bool |
52 | */ |
53 | protected $maxTopicRecommendations = false; |
54 | |
55 | /** |
56 | * Relevance sort override for empty searches |
57 | * |
58 | * @var string |
59 | */ |
60 | protected $emptySearchRelevanceOverride = null; |
61 | |
62 | /** |
63 | * Constructor |
64 | * |
65 | * @param \VuFind\Config\PluginManager $configLoader Config loader |
66 | */ |
67 | public function __construct(\VuFind\Config\PluginManager $configLoader) |
68 | { |
69 | parent::__construct($configLoader); |
70 | $this->searchIni = $this->facetsIni = 'Summon'; |
71 | // Load facet preferences: |
72 | $facetSettings = $configLoader->get($this->facetsIni); |
73 | if ( |
74 | isset($facetSettings->Advanced_Facet_Settings->translated_facets) |
75 | && count($facetSettings->Advanced_Facet_Settings->translated_facets) > 0 |
76 | ) { |
77 | $this->setTranslatedFacets( |
78 | $facetSettings->Advanced_Facet_Settings->translated_facets->toArray() |
79 | ); |
80 | } |
81 | if (isset($facetSettings->Advanced_Facet_Settings->special_facets)) { |
82 | $this->specialAdvancedFacets |
83 | = $facetSettings->Advanced_Facet_Settings->special_facets; |
84 | } |
85 | |
86 | // Load the search configuration file: |
87 | $searchSettings = $configLoader->get($this->searchIni); |
88 | |
89 | // Set up limit preferences |
90 | if (isset($searchSettings->General->default_limit)) { |
91 | $this->defaultLimit = $searchSettings->General->default_limit; |
92 | } |
93 | if (isset($searchSettings->General->limit_options)) { |
94 | $this->limitOptions = $this->explodeListSetting($searchSettings->General->limit_options); |
95 | } |
96 | |
97 | // Set up highlighting preference |
98 | if (isset($searchSettings->General->highlighting)) { |
99 | $this->highlight = $searchSettings->General->highlighting; |
100 | } |
101 | |
102 | // Set up spelling preference |
103 | if (isset($searchSettings->Spelling->enabled)) { |
104 | $this->spellcheck = $searchSettings->Spelling->enabled; |
105 | } |
106 | |
107 | // Load search preferences: |
108 | if (isset($searchSettings->General->default_filters)) { |
109 | $this->defaultFilters = $searchSettings->General->default_filters |
110 | ->toArray(); |
111 | } |
112 | if (isset($searchSettings->General->result_limit)) { |
113 | $this->resultLimit = $searchSettings->General->result_limit; |
114 | } else { |
115 | $this->resultLimit = 400; // default |
116 | } |
117 | |
118 | // Search handler setup: |
119 | if (isset($searchSettings->Basic_Searches)) { |
120 | foreach ($searchSettings->Basic_Searches as $key => $value) { |
121 | $this->basicHandlers[$key] = $value; |
122 | } |
123 | } |
124 | if (isset($searchSettings->Advanced_Searches)) { |
125 | foreach ($searchSettings->Advanced_Searches as $key => $value) { |
126 | $this->advancedHandlers[$key] = $value; |
127 | } |
128 | } |
129 | |
130 | // Load sort preferences: |
131 | if (isset($searchSettings->Sorting)) { |
132 | foreach ($searchSettings->Sorting as $key => $value) { |
133 | $this->sortOptions[$key] = $value; |
134 | } |
135 | } |
136 | if (isset($searchSettings->General->default_sort)) { |
137 | $this->defaultSort = $searchSettings->General->default_sort; |
138 | } |
139 | if ( |
140 | isset($searchSettings->DefaultSortingByType) |
141 | && count($searchSettings->DefaultSortingByType) > 0 |
142 | ) { |
143 | foreach ($searchSettings->DefaultSortingByType as $key => $val) { |
144 | $this->defaultSortByHandler[$key] = $val; |
145 | } |
146 | } |
147 | if (isset($searchSettings->General->empty_search_relevance_override)) { |
148 | $this->emptySearchRelevanceOverride |
149 | = $searchSettings->General->empty_search_relevance_override; |
150 | } |
151 | |
152 | // Load autocomplete preferences: |
153 | $this->configureAutocomplete($searchSettings); |
154 | |
155 | // Set up views |
156 | $this->initViewOptions($searchSettings); |
157 | |
158 | // Load list view for result (controls AJAX embedding vs. linking) |
159 | if (isset($searchSettings->List->view)) { |
160 | $this->listviewOption = $searchSettings->List->view; |
161 | } |
162 | } |
163 | |
164 | /** |
165 | * Return the route name for the search results action. |
166 | * |
167 | * @return string |
168 | */ |
169 | public function getSearchAction() |
170 | { |
171 | return 'summon-search'; |
172 | } |
173 | |
174 | /** |
175 | * Return the route name of the action used for performing advanced searches. |
176 | * Returns false if the feature is not supported. |
177 | * |
178 | * @return string|bool |
179 | */ |
180 | public function getAdvancedSearchAction() |
181 | { |
182 | return 'summon-advanced'; |
183 | } |
184 | |
185 | /** |
186 | * Return the route name for the facet list action. Returns false to cover |
187 | * unimplemented support. |
188 | * |
189 | * @return string|bool |
190 | */ |
191 | public function getFacetListAction() |
192 | { |
193 | return 'summon-facetlist'; |
194 | } |
195 | |
196 | /** |
197 | * Get the relevance sort override for empty searches. |
198 | * |
199 | * @return string Sort field or null if not set |
200 | */ |
201 | public function getEmptySearchRelevanceOverride() |
202 | { |
203 | return $this->emptySearchRelevanceOverride; |
204 | } |
205 | |
206 | /** |
207 | * Get the maximum number of topic recommendations (false for none) |
208 | * |
209 | * @return bool|int |
210 | */ |
211 | public function getMaxTopicRecommendations() |
212 | { |
213 | return $this->maxTopicRecommendations; |
214 | } |
215 | |
216 | /** |
217 | * Set the maximum number of topic recommendations (false for none) |
218 | * |
219 | * @param bool|int $max New maximum setting |
220 | * |
221 | * @return void |
222 | */ |
223 | public function setMaxTopicRecommendations($max) |
224 | { |
225 | $this->maxTopicRecommendations = $max; |
226 | } |
227 | } |