Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Back to browse results feature #3826

Open
wants to merge 35 commits into
base: dev
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from 23 commits
Commits
Show all changes
35 commits
Select commit Hold shift + click to select a range
3356657
Back to browse results feature
rominail Jul 15, 2024
e476f3e
Back to browse results feature
rominail Jul 15, 2024
a3568bd
Back to browse results feature
rominail Jul 15, 2024
3a35807
Back to browse results feature
rominail Jul 15, 2024
16bc5cd
Back to browse results feature - Discussion changes
rominail Jul 25, 2024
df77e7d
Back to browse results feature - Discussion changes
rominail Jul 25, 2024
1acf6cf
Back to browse results feature - Fix pipelines
rominail Jul 25, 2024
0683fda
Discussion changes
rominail Jul 26, 2024
3185f9e
Discussion changes
rominail Jul 26, 2024
235ca56
Discussion changes
rominail Jul 26, 2024
b963d83
Discussion changes
rominail Jul 26, 2024
542beae
Discussion changes
rominail Jul 26, 2024
21b14ac
Fix pipelines
rominail Jul 26, 2024
fece41b
Fix pipelines
rominail Jul 26, 2024
5e693df
Fix pipelines
rominail Jul 26, 2024
4d47821
Fix pipelines
rominail Jul 26, 2024
2c297d5
Discussion changes
rominail Jul 29, 2024
27f8938
Discussion changes
rominail Jul 29, 2024
0d9af3d
Discussion changes
rominail Jul 29, 2024
f1969ee
Discussion changes
rominail Jul 29, 2024
3fbf094
Fix pipelines
rominail Jul 29, 2024
e273e08
Remove getService
rominail Jul 31, 2024
2a1585c
Fix conflicts
rominail Jul 31, 2024
86473b6
Discussion changes
rominail Aug 12, 2024
f78eb87
Discussion changes
rominail Aug 12, 2024
11168cd
Discussion changes
rominail Aug 12, 2024
c57879b
Discussion changes
rominail Aug 12, 2024
730d379
Fix bug
rominail Aug 14, 2024
233c78b
Discussion changes
rominail Aug 14, 2024
f9a2a9b
Discussion changes
rominail Aug 16, 2024
8100053
Discussion changes
rominail Aug 16, 2024
2df9b95
Discussion changes
rominail Aug 16, 2024
df60635
Improve comment.
demiankatz Aug 19, 2024
f42ff33
Merge branch 'vufind-org:dev' into backToOrigin
rominail Aug 20, 2024
0f6d05b
Merge branch 'vufind-org:dev' into backToOrigin
rominail Aug 30, 2024
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions languages/en.ini
Original file line number Diff line number Diff line change
Expand Up @@ -111,6 +111,7 @@ Available Functionality = "Available Functionality"
Awards = "Awards"
Back to Record = "Back to Record"
Back to Search Results = "Back to Search Results"
back_to_browse_by = "Back to Browse %%field%%"
Backtrace = "Backtrace"
Bag = "Bag"
Balance = "Balance"
Expand Down
1 change: 1 addition & 0 deletions languages/fr.ini
Original file line number Diff line number Diff line change
Expand Up @@ -111,6 +111,7 @@ Available Functionality = "Fonctions disponibles"
Awards = "Récompenses"
Back to Record = "Retourner à la notice"
Back to Search Results = "Retourner aux résultats de recherche"
back_to_browse_by = "Retour à la recherche %%field%%"
Backtrace = "Historique"
Bag = "Panier"
Balance = "Solde du compte"
Expand Down
1 change: 1 addition & 0 deletions module/VuFind/config/module.config.php
Original file line number Diff line number Diff line change
Expand Up @@ -493,6 +493,7 @@
'VuFind\Search\Params\PluginManager' => 'VuFind\ServiceManager\AbstractPluginManagerFactory',
'VuFind\Search\Results\PluginManager' => 'VuFind\ServiceManager\AbstractPluginManagerFactory',
'VuFind\Search\SearchNormalizer' => 'VuFind\Search\SearchNormalizerFactory',
\VuFind\Search\SearchOrigin\SearchOriginFactory::class => \Laminas\ServiceManager\Factory\InvokableFactory::class,
'VuFind\Search\SearchRunner' => 'VuFind\Search\SearchRunnerFactory',
'VuFind\Search\SearchTabsHelper' => 'VuFind\Search\SearchTabsHelperFactory',
'VuFind\Search\Solr\HierarchicalFacetHelper' => 'VuFind\Search\Solr\HierarchicalFacetHelperFactory',
Expand Down
7 changes: 4 additions & 3 deletions module/VuFind/src/VuFind/Controller/AbstractRecord.php
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@
use VuFind\Ratings\RatingsService;
use VuFind\Record\ResourcePopulator;
use VuFind\RecordDriver\AbstractBase as AbstractRecordDriver;
use VuFind\Search\SearchOrigin\SearchOriginFactory;
use VuFind\Tags\TagsService;
use VuFindSearch\ParamBag;

Expand Down Expand Up @@ -952,9 +953,9 @@ protected function showTab($tab, $ajax = false)
$view->defaultTab = strtolower($this->getDefaultTab());
$view->backgroundTabs = $this->getBackgroundTabs();
$view->tabsExtraScripts = $this->getTabsExtraScripts($view->tabs);
$view->loadInitialTabWithAjax
= isset($config->Site->loadInitialTabWithAjax)
? (bool)$config->Site->loadInitialTabWithAjax : false;
$view->loadInitialTabWithAjax = (bool)($config->Site->loadInitialTabWithAjax ?? false);
$factory = $this->getService(SearchOriginFactory::class);
$this->layout()->setVariable('searchOrigin', $factory->createObject($this->params()->fromQuery()));

// Set up next/previous record links (if appropriate)
if ($this->resultScrollerActive()) {
Expand Down
31 changes: 20 additions & 11 deletions module/VuFind/src/VuFind/Controller/AbstractSearch.php
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,10 @@
use Laminas\View\Model\ViewModel;
use VuFind\Db\Entity\SearchEntityInterface;
use VuFind\Db\Service\SearchServiceInterface;
use VuFind\Search\Base\Results;
use VuFind\Search\RecommendListener;
use VuFind\Search\SearchOrigin\AbstractSearchOrigin;
use VuFind\Search\SearchOrigin\SearchOriginFactory;
use VuFind\Solr\Utils as SolrUtils;

use function count;
Expand Down Expand Up @@ -393,6 +396,8 @@ protected function getSearchResultsView($setupCallback = null)
$queryParams['page'] = $lastPage;
return $this->redirect()->toRoute('search-results', [], [ 'query' => $queryParams ]);
}
$factory = $this->getService(SearchOriginFactory::class);
$searchOrigin = $factory->createObject($this->params()->fromQuery());

// If we received an EmptySet back, that indicates that the real search
// failed due to some kind of syntax error, and we should display a
Expand All @@ -402,7 +407,7 @@ protected function getSearchResultsView($setupCallback = null)
$view->parseError = true;
} else {
// If a "jumpto" parameter is set, deal with that now:
if ($jump = $this->processJumpTo($results)) {
if ($jump = $this->processJumpTo($results, $searchOrigin)) {
return $jump;
}

Expand All @@ -415,7 +420,7 @@ protected function getSearchResultsView($setupCallback = null)
}

// Jump to only result, if configured:
if ($jump = $this->processJumpToOnlyResult($results)) {
if ($jump = $this->processJumpToOnlyResult($results, $searchOrigin)) {
return $jump;
}

Expand All @@ -428,6 +433,8 @@ protected function getSearchResultsView($setupCallback = null)
$this->flashMessenger()->addErrorMessage($error);
}
}
// For the header link
$this->layout()->setVariable('searchOrigin', $searchOrigin);

// Special case: If we're in RSS view, we need to render differently:
if (isset($view->params) && $view->params->getView() == 'rss') {
Expand All @@ -444,11 +451,12 @@ protected function getSearchResultsView($setupCallback = null)
* Process the jumpto parameter -- either redirect to a specific record and
* return view model, or ignore the parameter and return false.
*
* @param \VuFind\Search\Base\Results $results Search results object.
* @param Results $results Search results object.
* @param AbstractSearchOrigin|null $searchOrigin Search origin to propagate
*
* @return bool|HttpResponse
*/
protected function processJumpTo($results)
protected function processJumpTo($results, ?AbstractSearchOrigin $searchOrigin = null)
{
// Missing/invalid parameter? Ignore it:
$jumpto = $this->params()->fromQuery('jumpto');
Expand All @@ -457,18 +465,20 @@ protected function processJumpTo($results)
}

$recordList = $results->getResults();
$queryParams = $searchOrigin?->getSearchUrlParamsArray() ?? [];
return isset($recordList[$jumpto - 1])
? $this->getRedirectForRecord($recordList[$jumpto - 1]) : false;
? $this->getRedirectForRecord($recordList[$jumpto - 1], $queryParams) : false;
}

/**
* Process jump to record if there is only one result.
*
* @param \VuFind\Search\Base\Results $results Search results object.
* @param Results $results Search results object.
* @param AbstractSearchOrigin|null $searchOrigin Search origin to propagate
*
* @return bool|HttpResponse
*/
protected function processJumpToOnlyResult($results)
protected function processJumpToOnlyResult($results, ?AbstractSearchOrigin $searchOrigin = null)
{
// If jumpto is explicitly disabled (set to false, e.g. by combined search),
// we should NEVER jump to a result regardless of other factors.
Expand All @@ -479,10 +489,9 @@ protected function processJumpToOnlyResult($results)
&& $results->getResultTotal() == 1
&& $recordList = $results->getResults()
) {
return $this->getRedirectForRecord(
reset($recordList),
['sid' => $results->getSearchId()]
);
$queryParams = $searchOrigin?->getSearchUrlParamsArray() ?? [];
$queryParams['sid'] = $results->getSearchId();
return $this->getRedirectForRecord(reset($recordList), $queryParams);
}

return false;
Expand Down
8 changes: 8 additions & 0 deletions module/VuFind/src/VuFind/Controller/AlphabrowseController.php
Original file line number Diff line number Diff line change
Expand Up @@ -30,9 +30,11 @@

namespace VuFind\Controller;

use Exception;
use Laminas\Config\Config;
use Laminas\View\Model\ViewModel;
use VuFind\Exception\BadRequest;
use VuFind\Search\SearchOrigin\AlphaBrowseSearchOrigin;
use VuFindSearch\ParamBag;

use function in_array;
Expand Down Expand Up @@ -236,6 +238,11 @@ public function homeAction(): ViewModel
$source = $this->params()->fromQuery('source', false);
$from = $this->params()->fromQuery('from', false);
$page = intval($this->params()->fromQuery('page', 0));
try {
$origin = new AlphaBrowseSearchOrigin($this->defaultTypes[$source], $source, $from, $page ?: null);
rominail marked this conversation as resolved.
Show resolved Hide resolved
} catch (Exception) {
$origin = null;
}

// Load highlighting configuration while accounting for special case:
// highlighting is pointless if there's no user input:
Expand All @@ -252,6 +259,7 @@ public function homeAction(): ViewModel
'from' => $from,
'source' => $source,
'extras' => array_filter(explode(':', $extras[$source] ?? '')),
'origin' => $origin,
]
);

Expand Down
6 changes: 4 additions & 2 deletions module/VuFind/src/VuFind/Controller/WebController.php
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@
namespace VuFind\Controller;

use Laminas\ServiceManager\ServiceLocatorInterface;
use VuFind\Search\SearchOrigin\AbstractSearchOrigin;

/**
* Web Controller
Expand Down Expand Up @@ -57,11 +58,12 @@ public function __construct(ServiceLocatorInterface $sm)
* Process the jumpto parameter -- either redirect to a specific record and
* return view model, or ignore the parameter and return false.
*
* @param \VuFind\Search\Base\Results $results Search results object.
* @param \VuFind\Search\Base\Results $results Search results object.
* @param AbstractSearchOrigin|null $searchOrigin Search origin to propagate
*
* @return mixed
*/
protected function processJumpTo($results)
protected function processJumpTo($results, ?AbstractSearchOrigin $searchOrigin = null)
{
// Missing/invalid parameter? Ignore it:
$jumpto = $this->params()->fromQuery('jumpto');
Expand Down
8 changes: 8 additions & 0 deletions module/VuFind/src/VuFind/Search/Minified.php
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@
namespace VuFind\Search;

use VuFind\Search\Base\Results;
use VuFind\Search\SearchOrigin\AbstractSearchOrigin;

/**
* A minified search object used exclusively for trimming a search object down to its
Expand Down Expand Up @@ -142,6 +143,13 @@ class Minified
*/
public $scp = [];

/**
* Search origin
*
* @var AbstractSearchOrigin|null
*/
public $o;
rominail marked this conversation as resolved.
Show resolved Hide resolved

/**
* Constructor.
*
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,77 @@
<?php

/**
* Search Origin Object
*
* PHP version 8
*
* Copyright (C) Michigan State University 2024.
*
* 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 VuFind
* @package Search
* @author Robby ROUDON <[email protected]>
* @license http://opensource.org/licenses/gpl-2.0.php GNU General Public License
* @link https://vufind.org Main Page
*/

namespace VuFind\Search\SearchOrigin;

/**
* Abstract object for any search origin
*
* @category VuFind
* @package Search
* @author Robby ROUDON <[email protected]>
* @license http://opensource.org/licenses/gpl-2.0.php GNU General Public License
* @link https://vufind.org Main Page
*/
abstract class AbstractSearchOrigin
{
/**
* Name of the URL parameter containing the value of the search origin
*
* @var string
*/
public const PARAM_NAME = 'origin';

/**
* Get origin name
*
* @return string
*/
abstract public static function getName(): string;

/**
* Get array of parameters to put in the search URL
*
* @return array
*/
abstract public function getSearchUrlParamsArray(): array;

/**
* Get array of parameters to recreate the origin in the URL
*
* @return array
*/
abstract public function getOriginUrlParamsArray(): array;

/**
* Get route name to generate the url
*
* @return string
*/
abstract public function getRouteName(): string;
}
Loading
Loading