diff --git a/languages/en.ini b/languages/en.ini index 92d4692b660bcb5d24ebb7669d134342120f85bd..f04255c7364de04c8ca65d83ecf72e7462a32fcd 100644 --- a/languages/en.ini +++ b/languages/en.ini @@ -349,6 +349,7 @@ email_subject = "Subject" email_success = "Message Sent" Empty = "Empty" Empty Book Bag = "Empty Book Bag" +empty_search_disallowed = "An empty query is not allowed with the current search target" Enable Auto Config = "Enable Auto Config" End Page = "End Page" Era = "Era" diff --git a/languages/fi.ini b/languages/fi.ini index cb3fb51815acf5612d71cad288142ab516b2949f..769729c0d75abb4964a8fab374728f690cb7652b 100644 --- a/languages/fi.ini +++ b/languages/fi.ini @@ -347,6 +347,7 @@ email_subject = "Aihe" email_success = "Viesti lähetetty" Empty = "Tyhjä" Empty Book Bag = "Tyhjennä kirjakori" +empty_search_disallowed = "Käytetystä hakukohteesta ei voi hakea ilman hakuehtoja" Enable Auto Config = "Ota käyttöön automaattinen asennus" End Page = "Viimeinen sivu" Era = "Aikakausi" diff --git a/languages/sv.ini b/languages/sv.ini index 586c1d57b3d44c8d1bb9c9d36865dbdafa07da95..d32a7c0a82fb47b3d2983a9eeef4e82e58b701aa 100644 --- a/languages/sv.ini +++ b/languages/sv.ini @@ -341,6 +341,7 @@ email_subject = "Ämne" email_success = "Meddelandet har skickats" Empty = "Tom" Empty Book Bag = "Tömma" +empty_search_disallowed = "Det går inte att söka i nuvarande sökmål utan söktermer" Enable Auto Config = "Enable Auto Config" End Page = "Sista sidan" Era = "Tidsperiod" diff --git a/module/VuFind/src/VuFind/Controller/AbstractSearch.php b/module/VuFind/src/VuFind/Controller/AbstractSearch.php index 80792d8f4e156f8c46118cfb74f27732934f757c..f7714bc4f4247155e8a6dbec3949679f94289878 100644 --- a/module/VuFind/src/VuFind/Controller/AbstractSearch.php +++ b/module/VuFind/src/VuFind/Controller/AbstractSearch.php @@ -310,6 +310,10 @@ class AbstractSearch extends AbstractBase if ($this->resultScrollerActive()) { $this->resultScroller()->init($results); } + + foreach ($results->getErrors() as $error) { + $this->flashMessenger()->addErrorMessage($error); + } } // Special case: If we're in RSS view, we need to render differently: diff --git a/module/VuFind/src/VuFind/Search/Base/Results.php b/module/VuFind/src/VuFind/Search/Base/Results.php index 2dd1b20d980b0b8ab97af47f4f591d60dfd107b7..6b99ea6604805cbb67007981d7f009ca034dfebe 100644 --- a/module/VuFind/src/VuFind/Search/Base/Results.php +++ b/module/VuFind/src/VuFind/Search/Base/Results.php @@ -74,6 +74,13 @@ abstract class Results */ protected $results = null; + /** + * Any errors reported by the search backend + * + * @var array + */ + protected $errors = null; + /** * An ID number for saving/retrieving search * @@ -257,6 +264,7 @@ abstract class Results $this->resultTotal = 0; $this->results = []; $this->suggestions = []; + $this->errors = []; // Run the search: $this->startQueryTimer(); @@ -375,6 +383,19 @@ abstract class Results return $this->results; } + /** + * Basic 'getter' for errors. + * + * @return array + */ + public function getErrors() + { + if (null === $this->errors) { + $this->performAndProcessSearch(); + } + return $this->errors; + } + /** * Basic 'getter' for ID of saved search. * diff --git a/module/VuFind/src/VuFind/Search/Primo/Results.php b/module/VuFind/src/VuFind/Search/Primo/Results.php index 3ebb7b5724427b905a1030d56f5ef0acabb51fcd..f2fac9cc3863e16a774b182d3e594c723f332319 100644 --- a/module/VuFind/src/VuFind/Search/Primo/Results.php +++ b/module/VuFind/src/VuFind/Search/Primo/Results.php @@ -56,6 +56,7 @@ class Results extends \VuFind\Search\Base\Results $this->responseFacets = $collection->getFacets(); $this->resultTotal = $collection->getTotal(); + $this->errors = $collection->getErrors(); // Construct record drivers for all the items in the response: $this->results = $collection->getRecords(); diff --git a/module/VuFindSearch/src/VuFindSearch/Backend/Primo/Connector.php b/module/VuFindSearch/src/VuFindSearch/Backend/Primo/Connector.php index fe85b83835960c8a13fd2ed8e1dcaa65a6405a01..dacafdfa4a3e8ab0b1d436f7f20233c0e3c09146 100644 --- a/module/VuFindSearch/src/VuFindSearch/Backend/Primo/Connector.php +++ b/module/VuFindSearch/src/VuFindSearch/Backend/Primo/Connector.php @@ -83,7 +83,7 @@ class Connector implements \Zend\Log\LoggerAwareInterface 'recordCount' => 0, 'documents' => [], 'facets' => [], - 'error' => 'Primo does not accept an empty query' + 'error' => 'empty_search_disallowed' ]; /** diff --git a/module/VuFindSearch/src/VuFindSearch/Backend/Primo/Response/RecordCollection.php b/module/VuFindSearch/src/VuFindSearch/Backend/Primo/Response/RecordCollection.php index 58ca36264968ecd2fcefc71f508d49c86143fbc9..f5392e4627783619c0716d38026cc0927576767c 100644 --- a/module/VuFindSearch/src/VuFindSearch/Backend/Primo/Response/RecordCollection.php +++ b/module/VuFindSearch/src/VuFindSearch/Backend/Primo/Response/RecordCollection.php @@ -93,4 +93,14 @@ class RecordCollection extends AbstractRecordCollection $size = $this->response['query']['pageSize'] ?? 0; return $page * $size; } + + /** + * Return any errors. + * + * @return array + */ + public function getErrors() + { + return (array)($this->response['error'] ?? []); + } } diff --git a/module/VuFindSearch/src/VuFindSearch/Response/AbstractRecordCollection.php b/module/VuFindSearch/src/VuFindSearch/Response/AbstractRecordCollection.php index 45b973533820c51772758bcbb4dea66dbffacbd8..9320e7f226ca3b7ddfab284ebb31778d8e5bf434 100644 --- a/module/VuFindSearch/src/VuFindSearch/Response/AbstractRecordCollection.php +++ b/module/VuFindSearch/src/VuFindSearch/Response/AbstractRecordCollection.php @@ -77,6 +77,16 @@ abstract class AbstractRecordCollection implements RecordCollectionInterface return $this->records; } + /** + * Return any errors. + * + * @return array + */ + public function getErrors() + { + return []; + } + /** * Shuffles records. * diff --git a/module/VuFindSearch/tests/unit-tests/src/VuFindTest/Backend/Primo/ConnectorTest.php b/module/VuFindSearch/tests/unit-tests/src/VuFindTest/Backend/Primo/ConnectorTest.php index 01af661861a7416a86074ac570ffcfb083391b0f..c2cd04ca7a369e6712befac595e3447d528da45b 100644 --- a/module/VuFindSearch/tests/unit-tests/src/VuFindTest/Backend/Primo/ConnectorTest.php +++ b/module/VuFindSearch/tests/unit-tests/src/VuFindTest/Backend/Primo/ConnectorTest.php @@ -81,7 +81,7 @@ class ConnectorTest extends TestCase $terms = []; $result = $conn->query('dummyinst', $terms); $this->assertEquals(0, $result['recordCount']); - $this->assertEquals('Primo does not accept an empty query', $result['error']); + $this->assertEquals('empty_search_disallowed', $result['error']); } /**