diff --git a/module/VuFind/src/VuFind/Recommend/ConsortialVuFind.php b/module/VuFind/src/VuFind/Recommend/ConsortialVuFind.php index 8b8ccbe3a1e..c0e5638b594 100644 --- a/module/VuFind/src/VuFind/Recommend/ConsortialVuFind.php +++ b/module/VuFind/src/VuFind/Recommend/ConsortialVuFind.php @@ -33,6 +33,7 @@ use VuFind\Connection\ExternalVuFind as Connection; use function intval; +use function is_callable; /** * ConsortialVuFind Recommendations Module @@ -111,9 +112,9 @@ class ConsortialVuFind implements RecommendInterface, \Laminas\Log\LoggerAwareIn /** * Query string from the original search results * - * @var string + * @var ?string */ - protected $queryString; + protected $queryString = null; /** * Constructor @@ -198,7 +199,10 @@ public function init($params, $request) */ public function process($results) { - $this->queryString = $results->getParams()->getQuery()->getString(); + $query = $results->getParams()->getQuery(); + if (is_callable([$query, 'getString'])) { + $this->queryString = $query->getString(); + } } /** @@ -208,7 +212,7 @@ public function process($results) */ public function getResults() { - if (!$this->hasMinimumConfig) { + if (!$this->hasMinimumConfig || !$this->queryString) { return []; } diff --git a/module/VuFind/src/VuFind/Recommend/Databases.php b/module/VuFind/src/VuFind/Recommend/Databases.php index 39de1e387f4..2bcfbb82a6e 100644 --- a/module/VuFind/src/VuFind/Recommend/Databases.php +++ b/module/VuFind/src/VuFind/Recommend/Databases.php @@ -33,6 +33,7 @@ use function count; use function intval; +use function is_callable; use function strlen; /** @@ -272,7 +273,10 @@ public function getResults() // Add databases from search query if ($this->useQuery) { - $query = strtolower($this->results->getParams()->getQuery()->getString()); + $queryObject = $this->results->getParams()->getQuery(); + $query = is_callable([$queryObject, 'getString']) + ? strtolower($queryObject->getString()) + : ''; if (strlen($query) >= $this->useQueryMinLength) { foreach ($nameToDatabase as $name => $databaseInfo) { if (str_contains(strtolower($name), $query)) {