This repository has been archived by the owner on Jan 25, 2021. It is now read-only.
forked from vufind-org/vufind
-
Notifications
You must be signed in to change notification settings - Fork 7
/
Params.php
287 lines (258 loc) · 8.38 KB
/
Params.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
<?php
/**
* Params
*
* PHP version 7
*
* Copyright (C) project swissbib, 2015.
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License version 2,
* as published by the Free Software Foundation.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
*
* @category Swissbib_VuFind
* @package VuFind_Search_Solr
* @author Guenter Hipler <guenter.hipler@unibas.ch>
* @license http://opensource.org/licenses/gpl-2.0.php GNU General Public License
* @link http://www.swissbib.org Main Page
*/
namespace Swissbib\VuFind\Search\Solr;
use Swissbib\Favorites\Manager as SwissbibFavoritesManager;
use Swissbib\VuFind\Search\Helper\TypeLabelMappingHelper;
use VuFind\Auth\Manager as VuFindAuthManager;
use VuFind\Search\Solr\HierarchicalFacetHelper;
use VuFind\Search\Solr\Params as VuFindSolrParams;
use VuFindSearch\ParamBag;
/**
* Class to extend the core VF2 SOLR functionality related to Parameters
*
* @category Swissbib_VuFind
* @package VuFind_Search_Solr
* @author Guenter Hipler <guenter.hipler@unibas.ch>
* @license http://opensource.org/licenses/gpl-2.0.php GNU General Public License
* @link http://www.vufind.org Main Page
*/
class Params extends VuFindSolrParams
{
use \Swissbib\VuFind\Search\Helper\PersonalSettingsHelper;
/**
* DateRange
*
* @var array
*/
protected $dateRange = [
'isActive' => false
];
/**
* VuFindAuthManager
*
* @var VuFindAuthManager
*/
protected $authManager;
/**
* TypeLabelMappingHelper
*
* @var TypeLabelMappingHelper
*/
protected $typeLabelMappingHelper;
/**
* SwissbibFavoritesManager
*
* @var SwissbibFavoritesManager
*/
protected $favoritesManager;
/**
* Constructor
*
* @param \VuFind\Search\Base\Options $options Options to use
* @param \VuFind\Config\PluginManager $configLoader Config loader
* @param VuFindAuthManager $authManager AuthManager
* @param TypeLabelMappingHelper $mappingHelper HelperClass mappings
* @param SwissbibFavoritesManager $favoritesManager favoritesManager
* @param HierarchicalFacetHelper $facetHelper facetHelper
*/
public function __construct($options, \VuFind\Config\PluginManager $configLoader,
VuFindAuthManager $authManager,
TypeLabelMappingHelper $mappingHelper,
SwissbibFavoritesManager $favoritesManager,
HierarchicalFacetHelper $facetHelper = null
) {
parent::__construct(
$options, $configLoader,
$facetHelper
);
$this->authManager = $authManager;
$this->typeLabelMappingHelper = $mappingHelper;
$this->favoritesManager = $favoritesManager;
}
/**
* Override to prevent problems with namespace
* See implementation of parent for details
*
* @return String
*/
public function getSearchClassId()
{
return 'Solr';
}
/**
* Pull the page size parameter or set to default
*
* @param \Laminas\StdLib\Parameters $request Parameter object representing user
* request.
*
* @return void
*/
protected function initLimit($request)
{
//$auth = $this->serviceLocator->get('VuFind\AuthManager');
$defLimit = $this->getOptions()->getDefaultLimit();
$limitOptions = $this->getOptions()->getLimitOptions();
$view = $this->getView();
$this->handleLimit(
$this->authManager, $request, $defLimit, $limitOptions, $view
);
}
/**
* GH: we need this method to call initLimit (which is protected in base
* class and shouldn't be changed only because
* of hacks relaed to silly personal settings (although is possible in the
* current PHP version)
*
* @param \Laminas\StdLib\Parameters $request Request
*
* @return void
*/
public function initLimitAdvancedSearch($request)
{
$this->initLimit($request);
}
/**
* Get the value for which type of sorting to use
*
* @param \Laminas\StdLib\Parameters $request Parameter object representing user
* request.
*
* @return string
*/
protected function initSort($request)
{
//$auth = $this->serviceLocator->get('VuFind\AuthManager');
$defaultSort = $this->getOptions()->getDefaultSortByHandler();
$this->setSort(
$this->handleSort(
$this->authManager, $request, $defaultSort, $this->getSearchClassId()
)
);
}
/**
* Overridden function - we need some more parameters.
*
* @return ParamBag
*/
public function getBackendParameters()
{
$backendParams = parent::getBackendParameters();
//with SOLR 4.3 AND is no longer the default parameter
$backendParams->add("q.op", "AND");
$backendParams = $this->addUserInstitutions($backendParams);
return $backendParams;
}
/**
* GetSpellcheckBackendParameters
*
* @return ParamBag
*/
public function getSpellcheckBackendParameters()
{
$backendParams = parent::getBackendParameters();
$backendParams->remove("spellcheck");
//with SOLR 4.3 AND is no longer the default parameter
$backendParams->add("q.op", "AND");
//we need this homegrown param to control the behaviour of
// InjectSwissbibSpellingListener
//I don't see another possibilty yet
$backendParams->add("swissbibspellcheck", "true");
return $backendParams;
}
/**
* GetTypeLabel
*
* @return string
*/
public function getTypeLabel()
{
return $this->typeLabelMappingHelper
->getLabel($this);
}
/**
* BuildDateRangeFilter
*
* @param string $field field to use for filtering.
* @param string $from year for start of range.
* @param string $to year for end of range.
*
* @return string filter query.
*/
protected function buildDateRangeFilter($field, $from, $to)
{
$this->dateRange['from'] = (int)$from;
$this->dateRange['to'] = (int)$to;
$this->dateRange['isActive'] = true;
return parent::buildDateRangeFilter($field, $from, $to);
}
/**
* Add user institutions as facet queries to backend params
*
* @param ParamBag $backendParams ParamBag
*
* @return ParamBag
*/
protected function addUserInstitutions(ParamBag $backendParams)
{
/**
* FavoriteInstitutions array
*
* @var String[] $favoriteInstitutions
*/
$favoriteInstitutions = $this->favoritesManager->getUserInstitutions();
if (sizeof($favoriteInstitutions) > 0) {
//facet parameter has to be true in case it's false
$backendParams->set("facet", "true");
foreach ($favoriteInstitutions as $institutionCode) {
//GH 19.12.2014: use configuration for index name
//more investigation for a better solution necessary
$backendParams->add("facet.query", "mylibrary:" . $institutionCode);
//$backendParams->add("bq","institution:".$institutionCode "^5000");
}
}
return $backendParams;
}
/**
* GetFacetLabel
*
* @param string $field Facet field name.
* @param string $value Facet value.
* @param string $default Default field name (null for default behavior).
*
* @return string Human-readable description of field.
*/
public function getFacetLabel($field, $value = null, $default = null)
{
switch ($field) {
case 'publishDate':
return 'adv_search_year';
default:
return parent::getFacetLabel($field, $value, $default);
}
}
}