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

Resolving VUFIND-882 (Combined search conflicts with search memory)

parent 1bcb1cbe
Branches
Tags
No related merge requests found
......@@ -164,6 +164,23 @@ class AbstractSearch extends AbstractBase
return false;
}
/**
* Store the URL of the provided search (if appropriate).
*
* @param \VuFind\Search\Base\Results $results Search results object
*
* @return void
*/
protected function rememberSearch($results)
{
if ($this->rememberSearch) {
$searchUrl = $this->url()->fromRoute(
$results->getOptions()->getSearchAction()
) . $results->getUrlQuery()->getParams(false);
Memory::rememberSearch($searchUrl);
}
}
/**
* Send search results to results view
*
......@@ -209,12 +226,7 @@ class AbstractSearch extends AbstractBase
// Send results to the view and remember the current URL as the last
// search.
$view->results = $results;
if ($this->rememberSearch) {
$searchUrl = $this->url()->fromRoute(
$results->getOptions()->getSearchAction()
) . $results->getUrlQuery()->getParams(false);
Memory::rememberSearch($searchUrl);
}
$this->rememberSearch($results);
// Add to search history:
if ($this->saveToHistory) {
......
......@@ -26,7 +26,7 @@
* @link http://vufind.org Main Site
*/
namespace VuFind\Controller;
use Zend\Stdlib\Parameters;
use VuFind\Search\Memory, Zend\Stdlib\Parameters;
/**
* Redirects the user to the appropriate default VuFind action.
......@@ -65,6 +65,11 @@ class CombinedController extends AbstractSearch
*/
public function resultAction()
{
$this->writeSession(); // avoid session write timing bug
// Turn off search memory -- not relevant in this context:
Memory::disable();
// Validate configuration:
$searchClassId = $this->params()->fromQuery('id');
$config = $this->getServiceLocator()->get('VuFind\Config')->get('combined')
......@@ -113,6 +118,11 @@ class CombinedController extends AbstractSearch
)
);
// Remember the current URL, then disable memory so multi-search results
// don't overwrite it:
$this->rememberSearch($results);
Memory::disable();
// Gather combined results:
$combinedResults = array();
$options = $this->getServiceLocator()
......
......@@ -39,6 +39,24 @@ use Zend\Session\Container as SessionContainer;
*/
class Memory
{
/**
* Is memory currently active? (i.e. will we save new URLs?)
*
* @var bool
*/
protected static $active = true;
/**
* Stop updating the URL in memory -- used in combined search to prevent
* multiple search URLs from overwriting one another.
*
* @return void
*/
public function disable()
{
self::$active = false;
}
/**
* Clear the last accessed search URL in the session.
*
......@@ -59,6 +77,11 @@ class Memory
*/
public static function rememberSearch($url)
{
// Do nothing if disabled.
if (!self::$active) {
return;
}
// Only remember URL if string is non-empty... otherwise clear the memory.
if (strlen(trim($url)) > 0) {
$session = new SessionContainer('Search');
......
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