Skip to content

Commit

Permalink
Databases & ConsortialVuFind: Fix bug in advanced search (vufind-org#…
Browse files Browse the repository at this point in the history
  • Loading branch information
maccabeelevine authored Mar 25, 2024
1 parent 0d95174 commit ee9d024
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 5 deletions.
12 changes: 8 additions & 4 deletions module/VuFind/src/VuFind/Recommend/ConsortialVuFind.php
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@
use VuFind\Connection\ExternalVuFind as Connection;

use function intval;
use function is_callable;

/**
* ConsortialVuFind Recommendations Module
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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();
}
}

/**
Expand All @@ -208,7 +212,7 @@ public function process($results)
*/
public function getResults()
{
if (!$this->hasMinimumConfig) {
if (!$this->hasMinimumConfig || !$this->queryString) {
return [];
}

Expand Down
6 changes: 5 additions & 1 deletion module/VuFind/src/VuFind/Recommend/Databases.php
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@

use function count;
use function intval;
use function is_callable;
use function strlen;

/**
Expand Down Expand Up @@ -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)) {
Expand Down

0 comments on commit ee9d024

Please sign in to comment.