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

Incorporated Search Manager into deminification process.

parent c21bb2c0
No related merge requests found
...@@ -124,7 +124,7 @@ class AbstractSearch extends AbstractBase ...@@ -124,7 +124,7 @@ class AbstractSearch extends AbstractBase
if ($search->session_id == $sessId || $search->user_id == $userId) { if ($search->session_id == $sessId || $search->user_id == $userId) {
// They do, deminify it to a new object. // They do, deminify it to a new object.
$minSO = unserialize($search->search_object); $minSO = unserialize($search->search_object);
$savedSearch = $minSO->deminify(); $savedSearch = $minSO->deminify($this->getSearchManager());
// Now redirect to the URL associated with the saved search; this // Now redirect to the URL associated with the saved search; this
// simplifies problems caused by mixing different classes of search // simplifies problems caused by mixing different classes of search
...@@ -201,7 +201,8 @@ class AbstractSearch extends AbstractBase ...@@ -201,7 +201,8 @@ class AbstractSearch extends AbstractBase
$sessId = $this->getServiceLocator()->get('SessionManager')->getId(); $sessId = $this->getServiceLocator()->get('SessionManager')->getId();
$history = new SearchTable(); $history = new SearchTable();
$history->saveSearch( $history->saveSearch(
$results, $sessId, $history->getSearches( $this->getSearchManager(), $results, $sessId,
$history->getSearches(
$sessId, isset($user->id) ? $user->id : null $sessId, isset($user->id) ? $user->id : null
) )
); );
...@@ -304,7 +305,7 @@ class AbstractSearch extends AbstractBase ...@@ -304,7 +305,7 @@ class AbstractSearch extends AbstractBase
// Restore the full search object: // Restore the full search object:
$minSO = unserialize($search->search_object); $minSO = unserialize($search->search_object);
$savedSearch = $minSO->deminify(); $savedSearch = $minSO->deminify($this->getSearchManager());
// Fail if this is not the right type of search: // Fail if this is not the right type of search:
if ($savedSearch->getParams()->getSearchType() != 'advanced') { if ($savedSearch->getParams()->getSearchType() != 'advanced') {
......
...@@ -333,7 +333,9 @@ class ResultScroller extends AbstractPlugin ...@@ -333,7 +333,9 @@ class ResultScroller extends AbstractPlugin
$row = $searchTable->getRowById($this->data->searchId, false); $row = $searchTable->getRowById($this->data->searchId, false);
if (!empty($row)) { if (!empty($row)) {
$minSO = unserialize($row->search_object); $minSO = unserialize($row->search_object);
$search = $minSO->deminify(); $search = $minSO->deminify(
$this->getController()->getServiceLocator()->get('SearchManager')
);
// The saved search does not remember its original limit; // The saved search does not remember its original limit;
// we should reapply it from the session data: // we should reapply it from the session data:
$search->getParams()->setLimit($this->data->limit); $search->getParams()->setLimit($this->data->limit);
......
...@@ -251,7 +251,7 @@ class SearchController extends AbstractSearch ...@@ -251,7 +251,7 @@ class SearchController extends AbstractSearch
// Saved searches // Saved searches
if ($current->saved == 1) { if ($current->saved == 1) {
$saved[] = $minSO->deminify(); $saved[] = $minSO->deminify($this->getSearchManager());
} else { } else {
// All the others... // All the others...
...@@ -263,7 +263,7 @@ class SearchController extends AbstractSearch ...@@ -263,7 +263,7 @@ class SearchController extends AbstractSearch
Memory::forgetSearch(); Memory::forgetSearch();
} else { } else {
// Otherwise add to the list // Otherwise add to the list
$unsaved[] = $minSO->deminify(); $unsaved[] = $minSO->deminify($this->getSearchManager());
} }
} }
} }
......
...@@ -140,6 +140,7 @@ class Search extends Gateway ...@@ -140,6 +140,7 @@ class Search extends Gateway
/** /**
* Add a search into the search table (history) * Add a search into the search table (history)
* *
* @param \VuFind\Search\Manager $manager Search manager
* @param \VuFind\Search\Base\Results $newSearch Search to save * @param \VuFind\Search\Base\Results $newSearch Search to save
* @param string $sessionId Current session ID * @param string $sessionId Current session ID
* @param array $searchHistory Existing saved searches (for * @param array $searchHistory Existing saved searches (for
...@@ -147,8 +148,9 @@ class Search extends Gateway ...@@ -147,8 +148,9 @@ class Search extends Gateway
* *
* @return void * @return void
*/ */
public function saveSearch($newSearch, $sessionId, $searchHistory = array()) public function saveSearch($manager, $newSearch, $sessionId,
{ $searchHistory = array()
) {
// Duplicate elimination // Duplicate elimination
$dupSaved = false; $dupSaved = false;
foreach ($searchHistory as $oldSearch) { foreach ($searchHistory as $oldSearch) {
...@@ -160,7 +162,7 @@ class Search extends Gateway ...@@ -160,7 +162,7 @@ class Search extends Gateway
? stream_get_contents($oldSearch->search_object) ? stream_get_contents($oldSearch->search_object)
: $oldSearch->search_object : $oldSearch->search_object
); );
$dupSearch = $minSO->deminify(); $dupSearch = $minSO->deminify($manager);
// See if the classes and urls match // See if the classes and urls match
$oldUrl = $dupSearch->getUrlQuery()->getParams(); $oldUrl = $dupSearch->getUrlQuery()->getParams();
$newUrl = $newSearch->getUrlQuery()->getParams(); $newUrl = $newSearch->getUrlQuery()->getParams();
......
...@@ -28,27 +28,21 @@ ...@@ -28,27 +28,21 @@
namespace VuFind\Search; namespace VuFind\Search;
/** /**
* A minified search object used exclusively for trimming * A minified search object used exclusively for trimming a search object down to its
* a search object down to it's barest minimum size * barest minimum size before storage in a cookie or database.
* before storage in a cookie or database.
* *
* It's still contains enough data granularity to * It still contains enough data granularity to programmatically recreate search
* programmatically recreate search urls. * URLs.
* *
* This class isn't intended for general use, but simply * This class isn't intended for general use, but simply a way of storing/retrieving
* a way of storing/retrieving data from a search object: * data from a search object:
* *
* eg. Store * eg. Store
* $searchHistory[] = serialize($this->minify()); * $searchHistory[] = serialize($this->minify());
* *
* eg. Retrieve * eg. Retrieve
* $searchObject = SearchObjectFactory::initSearchObject(); * $searchObject = unserialize($search);
* $searchObject->deminify(unserialize($search)); * $searchObject->deminify($manager);
*
* Note: codingStandardsIgnore settings within this class are used to suppress
* warnings related to the name not meeting PEAR standards; since there
* are serialized versions of this class stored in databases in the wild,
* it is too late to easily rename it for standards compliance.
* *
* @category VuFind2 * @category VuFind2
* @package Search * @package Search
...@@ -128,17 +122,20 @@ class Minified ...@@ -128,17 +122,20 @@ class Minified
/** /**
* Turn the current object into search results. * Turn the current object into search results.
* *
* @param \VuFind\Search\Manager $manager Search manager
*
* @return \VuFind\Search\Base\Results * @return \VuFind\Search\Base\Results
*/ */
public function deminify() public function deminify(\VuFind\Search\Manager $manager)
{ {
// Figure out the parameter and result classes based on the search class ID: // Figure out the parameter and result classes based on the search class ID:
$this->populateClassNames(); $this->populateClassNames();
// Deminify everything: // Deminify everything:
$params = new $this->pc(); $manager->setSearchClassId($this->cl);
$params = $manager->getParams();
$params->deminify($this); $params->deminify($this);
$results = new $this->rc($params); $results = $manager->getResults($params);
$results->deminify($this); $results->deminify($this);
return $results; return $results;
...@@ -152,46 +149,34 @@ class Minified ...@@ -152,46 +149,34 @@ class Minified
*/ */
protected function populateClassNames() protected function populateClassNames()
{ {
// Simple case -- this is a recently-built object which has a search class ID // If this is a legacy entry from VuFind 1.x, we need to figure out the
// populated: // search class ID for the object we're about to construct:
if (isset($this->cl)) { if (!isset($this->cl)) {
$this->pc = 'VuFind\Search\\' . $this->cl . '\Params'; $fixType = true; // by default, assume we need to fix type
$this->rc = 'VuFind\Search\\' . $this->cl . '\Results'; switch($this->ty) {
return; case 'Summon':
} case 'SummonAdvanced':
$this->cl = 'Summon';
// If we got this far, it's a legacy entry from VuFind 1.x. We need to break;
// figure out the engine type for the object we're about to construct: case 'WorldCat':
switch($this->ty) { case 'WorldCatAdvanced':
case 'Summon': $this->cl = 'WorldCat';
case 'SummonAdvanced': break;
$this->pc = 'VuFind\Search\Summon\Params'; case 'Authority':
$this->rc = 'VuFind\Search\Summon\Results'; case 'AuthorityAdvanced':
$fixType = true; $this->cl = 'SolrAuth';
break; break;
case 'WorldCat': default:
case 'WorldCatAdvanced': $this->cl = 'Solr';
$this->pc = 'VuFind\Search\WorldCat\Params'; $fixType = false;
$this->rc = 'VuFind\Search\WorldCat\Results'; break;
$fixType = true; }
break;
case 'Authority':
case 'AuthorityAdvanced':
$this->pc = 'VuFind\Search\SolrAuth\Params';
$this->rc = 'VuFind\Search\SolrAuth\Results';
$fixType = true;
break;
default:
$this->pc = 'VuFind\Search\Solr\Params';
$this->rc = 'VuFind\Search\Solr\Results';
$fixType = false;
break;
}
// Now rewrite the type if necessary (only needed for legacy objects): // Now rewrite the type if necessary (only needed for legacy objects):
if ($fixType) { if ($fixType) {
$this->ty = (substr($this->ty, -8) == 'Advanced') $this->ty = (substr($this->ty, -8) == 'Advanced')
? 'advanced' : 'basic'; ? 'advanced' : 'basic';
}
} }
} }
} }
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