Skip to content
Snippets Groups Projects
Commit ab0cbd79 authored by Demian Katz's avatar Demian Katz
Browse files

Fixed bug: facets loaded incorrectly unless in first side position.

parent c2333413
No related merge requests found
...@@ -124,20 +124,20 @@ class GetSideFacets extends \VuFind\AjaxHandler\AbstractBase ...@@ -124,20 +124,20 @@ class GetSideFacets extends \VuFind\AjaxHandler\AbstractBase
// Allow both GET and POST variables: // Allow both GET and POST variables:
$request = $params->fromQuery() + $params->fromPost(); $request = $params->fromQuery() + $params->fromPost();
$results = $this->getFacetResults($request); $configIndex = $request['configIndex'] ?? 0;
$configLocation = $request['location'] ?? 'side';
$results = $this->getFacetResults($request, $configIndex, $configLocation);
if ($results instanceof \VuFind\Search\EmptySet\Results) { if ($results instanceof \VuFind\Search\EmptySet\Results) {
$this->logError('Faceting request failed'); $this->logError('Faceting request failed');
return $this->formatResponse('', self::STATUS_HTTP_ERROR); return $this->formatResponse('', self::STATUS_HTTP_ERROR);
} }
$recommend = $results->getRecommendations($request['location'] ?? 'side'); $recommend = $results->getRecommendations($configLocation)[0];
$configIndex = $request['configIndex'] ?? 0;
$recommend = $recommend[(int)$configIndex] ?? [];
$context = [ $context = [
'recommend' => $recommend, 'recommend' => $recommend,
'params' => $results->getParams(), 'params' => $results->getParams(),
'searchClassId' => DEFAULT_SEARCH_BACKEND 'searchClassId' => $request['searchClassId'] ?? DEFAULT_SEARCH_BACKEND
]; ];
if (isset($request['enabledFacets'])) { if (isset($request['enabledFacets'])) {
// Render requested facets separately // Render requested facets separately
...@@ -158,24 +158,25 @@ class GetSideFacets extends \VuFind\AjaxHandler\AbstractBase ...@@ -158,24 +158,25 @@ class GetSideFacets extends \VuFind\AjaxHandler\AbstractBase
/** /**
* Perform search and return the results * Perform search and return the results
* *
* @param array $request Request params * @param array $request Request params
* @param string $index Index of SideFacetsDeferred in configuration
* @param string $loc Location where SideFacetsDeferred is configured
* *
* @return Results * @return Results
*/ */
protected function getFacetResults(array $request) protected function getFacetResults(array $request, $index, $loc)
{ {
$rManager = $this->recommendPluginManager; $setupCallback = function ($runner, $params, $searchId) use ($index, $loc) {
$setupCallback = function ($runner, $params, $searchId) use ($rManager) { $listener = new RecommendListener(
$listener = new RecommendListener($rManager, $searchId); $this->recommendPluginManager, $searchId
);
$config = []; $config = [];
$rawConfig = $params->getOptions() $rawConfig = $params->getOptions()
->getRecommendationSettings($params->getSearchHandler()); ->getRecommendationSettings($params->getSearchHandler());
foreach ($rawConfig['side'] as $value) { $settings = explode(':', $rawConfig[$loc][$index] ?? '');
$settings = explode(':', $value); if ($settings[0] === 'SideFacetsDeferred') {
if ($settings[0] === 'SideFacetsDeferred') { $settings[0] = 'SideFacets';
$settings[0] = 'SideFacets'; $config[$loc][] = implode(':', $settings);
$config['side'][] = implode(':', $settings);
}
} }
$listener->setConfig($config); $listener->setConfig($config);
$listener->attach($runner->getEventManager()->getSharedManager()); $listener->attach($runner->getEventManager()->getSharedManager());
......
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment