diff --git a/controller/WebController.php b/controller/WebController.php index ce1974948..f2034280d 100644 --- a/controller/WebController.php +++ b/controller/WebController.php @@ -329,23 +329,36 @@ public function invokeGlobalSearch($request) $vocabObjects = array(); if ($vocids) { foreach($vocids as $vocid) { - $vocabObjects[] = $this->model->getVocabulary($vocid); + try { + $vocabObjects[] = $this->model->getVocabulary($vocid); + } catch (ValueError $e) { + // fail fast with an error page if the vocabulary cannot be found + if ($this->model->getConfig()->getLogCaughtExceptions()) { + error_log('Caught exception: ' . $e->getMessage()); + } + header("HTTP/1.0 400 Bad Request"); + $this->invokeGenericErrorPage($request, $e->getMessage()); + return; + } } } $parameters->setVocabularies($vocabObjects); + $counts = null; + $searchResults = null; + $errored = false; + try { $countAndResults = $this->model->searchConceptsAndInfo($parameters); + $counts = $countAndResults['count']; + $searchResults = $countAndResults['results']; } catch (Exception $e) { - header("HTTP/1.0 404 Not Found"); + $errored = true; + header("HTTP/1.0 500 Internal Server Error"); if ($this->model->getConfig()->getLogCaughtExceptions()) { error_log('Caught exception: ' . $e->getMessage()); } - $this->invokeGenericErrorPage($request, $e->getMessage()); - return; } - $counts = $countAndResults['count']; - $searchResults = $countAndResults['results']; $vocabList = $this->model->getVocabularyList(); $sortedVocabs = $this->model->getVocabularyList(false, true); $langList = $this->model->getLanguages($lang); @@ -357,6 +370,7 @@ public function invokeGlobalSearch($request) 'search_results' => $searchResults, 'rest' => $parameters->getOffset()>0, 'global_search' => true, + 'search_failed' => $errored, 'term' => $request->getQueryParamRaw('q'), 'lang_list' => $langList, 'vocabs' => str_replace(' ', '+', $vocabs), @@ -375,6 +389,7 @@ public function invokeVocabularySearch($request) $template = $this->twig->loadTemplate('vocab-search-listing.twig'); $this->setLanguageProperties($request->getLang()); $vocab = $request->getVocab(); + $searchResults = null; try { $vocabTypes = $this->model->getTypes($request->getVocabid(), $request->getLang()); } catch (Exception $e) { @@ -388,6 +403,7 @@ public function invokeVocabularySearch($request) 'languages' => $this->languages, 'vocab' => $vocab, 'request' => $request, + 'search_results' => $searchResults )); return; @@ -411,6 +427,7 @@ public function invokeVocabularySearch($request) 'languages' => $this->languages, 'vocab' => $vocab, 'term' => $request->getQueryParam('q'), + 'search_results' => $searchResults )); return; } diff --git a/model/DataObject.php b/model/DataObject.php index a1359758d..2865cbcc4 100644 --- a/model/DataObject.php +++ b/model/DataObject.php @@ -46,10 +46,15 @@ public function __construct($model, $resource) protected function getExternalLabel($exvoc, $exuri, $lang) { if ($exvoc) { - $exsparql = $exvoc->getSparql(); - $results = $exsparql->queryLabel($exuri, $lang); - - return isset($results[$lang]) ? $results[$lang] : null; + try { + $exsparql = $exvoc->getSparql(); + $results = $exsparql->queryLabel($exuri, $lang); + return isset($results[$lang]) ? $results[$lang] : null; + } catch (EasyRdf\Http\Exception | EasyRdf\Exception | Throwable $e) { + if ($this->model->getConfig()->getLogCaughtExceptions()) { + error_log('Caught exception: ' . $e->getMessage()); + } + } } return null; } @@ -63,9 +68,15 @@ protected function getExternalLabel($exvoc, $exuri, $lang) protected function getExternalNotation($exvoc, $exuri) { if ($exvoc) { - $exsparql = $exvoc->getSparql(); - $results = $exsparql->queryNotation($exuri); - return isset($results) ? $results : null; + try { + $exsparql = $exvoc->getSparql(); + $results = $exsparql->queryNotation($exuri); + return isset($results) ? $results : null; + } catch (EasyRdf\Http\Exception | EasyRdf\Exception | Throwable $e) { + if ($this->model->getConfig()->getLogCaughtExceptions()) { + error_log('Caught exception: ' . $e->getMessage()); + } + } } return null; } diff --git a/model/Model.php b/model/Model.php index 9b6b6d819..5cc570140 100644 --- a/model/Model.php +++ b/model/Model.php @@ -245,7 +245,7 @@ public function searchConcepts($params) try { $hitvoc = $this->getVocabularyByGraph($hit['graph']); $hit['vocab'] = $hitvoc->getId(); - } catch (Exception $e) { + } catch (ValueError $e) { trigger_error($e->getMessage(), E_USER_WARNING); $hitvoc = null; $hit['vocab'] = "???"; @@ -255,7 +255,7 @@ public function searchConcepts($params) $hit['voc'] = $hitvoc; - if (!$hitvoc->containsURI($hit['uri'])) { + if ($hitvoc === null || !$hitvoc->containsURI($hit['uri'])) { // if uri is a external vocab uri that is included in the current vocab $realvoc = $this->guessVocabularyFromURI($hit['uri'], $voc !== null ? $voc->getId() : null); if ($realvoc !== $hitvoc) { @@ -470,11 +470,18 @@ private function disambiguateVocabulary($vocabs, $uri, $preferredVocabId = null) if($preferredVocabId != null) { foreach ($vocabs as $vocab) { if($vocab->getId() == $preferredVocabId) { - // double check that a label exists in the preferred vocabulary - if ($vocab->getConceptLabel($uri, null) !== null) { - return $vocab; - } else { - // not found in preferred vocabulary, fall back to next method + try { + // double check that a label exists in the preferred vocabulary + if ($vocab->getConceptLabel($uri, null) !== null) { + return $vocab; + } else { + // not found in preferred vocabulary, fall back to next method + break; + } + } catch (EasyRdf\Http\Exception | EasyRdf\Exception | Throwable $e) { + if ($this->getConfig()->getLogCaughtExceptions()) { + error_log('Caught exception: ' . $e->getMessage()); + } break; } } @@ -483,8 +490,16 @@ private function disambiguateVocabulary($vocabs, $uri, $preferredVocabId = null) // no preferred vocabulary, or it was not found, search in which vocabulary the concept has a label foreach ($vocabs as $vocab) { - if ($vocab->getConceptLabel($uri, null) !== null) - return $vocab; + try { + if ($vocab->getConceptLabel($uri, null) !== null) { + return $vocab; + } + } catch (EasyRdf\Http\Exception | EasyRdf\Exception | Throwable $e) { + if ($this->getConfig()->getLogCaughtExceptions()) { + error_log('Caught exception: ' . $e->getMessage()); + } + break; + } } // if the URI couldn't be found, fall back to the first vocabulary diff --git a/resource/css/styles.css b/resource/css/styles.css index aeaf2fc89..8dc85da13 100644 --- a/resource/css/styles.css +++ b/resource/css/styles.css @@ -522,6 +522,10 @@ ul.dropdown-menu > li:last-child > input { margin: 10px 0px; } +.search-result-listing > .alert > .btn-default { + border-radius: 0; +} + .search-result-listing .search-count { text-align: left; margin-left: 15px; @@ -1068,6 +1072,21 @@ div#sidebar-grey > div > div > form.search-options { top: 10px; } +.search-result-listing .alert .btn-default { + position: unset; + vertical-align: unset; + margin-left: 15px; + font-size: 18px; +} + +.alert h4, .alert h3 { + display: inline; +} + +.search-result-listing .alert-warning h4 { + display: block; +} + .search-options .mCSB_container > li > a > .radio { margin: 0; padding-left: 25px; diff --git a/resource/js/docready.js b/resource/js/docready.js index 03e3d75b4..3362aaa49 100644 --- a/resource/js/docready.js +++ b/resource/js/docready.js @@ -844,7 +844,7 @@ $(function() { // DOCUMENT READY $('.search-result-listing').append($ready); } else { - $trigger.waypoint(function() { waypointCallback(); }, options); + $trigger.waypoint(function() { waypointCallback(this); }, options); } } @@ -894,9 +894,13 @@ $(function() { // DOCUMENT READY changeOffset += 200; } - function waypointCallback() { + function waypointCallback(waypoint) { + if ($('.search-result-listing > p .spinner,.search-result-listing .alert-danger').length > 0) { + return false; + } var number_of_hits = $(".search-result").length; - if (number_of_hits < parseInt($('.search-count p').text().substr(0, $('.search-count p').text().indexOf(' ')), 10)) { $('.search-result-listing').append($loading); + if (number_of_hits < parseInt($('.search-count p').text().substr(0, $('.search-count p').text().indexOf(' ')), 10)) { + $('.search-result-listing').append($loading); var typeLimit = $('#type-limit').val(); var schemeLimit = $('#scheme-limit').val(); var groupLimit = $('#group-limit').val(); @@ -917,7 +921,20 @@ $(function() { // DOCUMENT READY $('.search-result-listing').append($ready); return false; } - $('.search-result:nth-last-of-type(4)').waypoint(function() { waypointCallback(); }, options ); + waypoint.destroy(); + $('.search-result:nth-last-of-type(4)').waypoint(function() { waypointCallback(this); }, options ); + }, + error: function(jqXHR, textStatus, errorThrown) { + $loading.detach(); + var $failedSearch = $('
{% trans %}{{ search_count }} results for '{{ term }}'{% endtrans %}{% if limit_type %}, {% trans "limited to type" %} '{% for type in limit_type %}{{ type }}{% if loop.last == false %}, {% endif %}{% endfor %}'{% endif %}{% if limit_parent %}, {% trans "limited to parent" %} '{{ limit_parent }}'{% endif %}{% if limit_group %}, {% trans "limited to group" %} '{{ limit_group }}'{% endif %}{% if limit_scheme %}, {% trans "limited to scheme" %} '{% for scheme in limit_scheme %}{{ scheme }}{% if loop.last == false %}, {% endif %}{% endfor %}'{% endif %}
{% trans 'The search provided no results.' %}
{% endif %} +{% if search_results is not null and search_results|length == 0 %}{% trans 'The search provided no results.' %}
{% endif %} {% for concept in search_results %} {# loop through the hits #}