From 5b386ea06bec91e0b82fe39081dd1caf6ae53242 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Andr=C3=A9=20Lahmann?= <lahmann@ub.uni-leipzig.de> Date: Thu, 29 Jan 2015 12:57:32 -0500 Subject: [PATCH] More robust handling of hierarchy nodes missing from index * added check for availability of hierarchical parent to Solr-TreeDataSource * added configuration option for availability check to HierarchyTree inis * added try..catch to CLI hierarchy builder to work around missing IDs --- config/vufind/HierarchyDefault.ini | 11 ++++- config/vufind/HierarchyFlat.ini | 9 ++++ .../VuFind/Hierarchy/TreeDataSource/Solr.php | 12 ++++- .../Controller/UtilController.php | 46 ++++++++++--------- 4 files changed, 55 insertions(+), 23 deletions(-) diff --git a/config/vufind/HierarchyDefault.ini b/config/vufind/HierarchyDefault.ini index b342201180d..e2b00196c47 100644 --- a/config/vufind/HierarchyDefault.ini +++ b/config/vufind/HierarchyDefault.ini @@ -27,4 +27,13 @@ fullHierarchyRecordView = true ; Filter queries filter what kind of children are displayed in the tree ; Note: The hidden filters from searches.ini are applied as well ; Note: Only applies when treeSource = Solr -;filterQueries[] = "-relsext.hasModel:\"DataModel\" AND -relsext.hasModel:\"ListCollection\"" \ No newline at end of file +;filterQueries[] = "-relsext.hasModel:\"DataModel\" AND -relsext.hasModel:\"ListCollection\"" +; Check whether the hierarchy_parent_id and hierarchy_top_id records are +; available in the index. Without this setting, if a referenced parent_id +; or top_id does not exist the frontend will show HierarchyTree layout-elements +; but will hang on actually building the HierarchyTree. If you know this will +; never happen in your instance (i.e. all hierarchy elements are always retrievable +; from the Solr index under all conditions -- usually the case unless you have +; conditional filters), you can turn this off for a slight performance gain. +; (default = true) +checkAvailability = true \ No newline at end of file diff --git a/config/vufind/HierarchyFlat.ini b/config/vufind/HierarchyFlat.ini index eb7b4635528..c758be179d6 100644 --- a/config/vufind/HierarchyFlat.ini +++ b/config/vufind/HierarchyFlat.ini @@ -24,3 +24,12 @@ show = false ; (true = show full hierarchy, false = only show path to current selected node, ; default = true) ;fullHierarchyRecordView = true +; Check whether the hierarchy_parent_id and hierarchy_top_id records are +; available in the index. Without this setting, if a referenced parent_id +; or top_id does not exist the frontend will show HierarchyTree layout-elements +; but will hang on actually building the HierarchyTree. If you know this will +; never happen in your instance (i.e. all hierarchy elements are always retrievable +; from the Solr index under all conditions -- usually the case unless you have +; conditional filters), you can turn this off for a slight performance gain. +; (default = true) +checkAvailability = true \ No newline at end of file diff --git a/module/VuFind/src/VuFind/Hierarchy/TreeDataSource/Solr.php b/module/VuFind/src/VuFind/Hierarchy/TreeDataSource/Solr.php index 4ec56b1c703..6e6ec3cd94a 100644 --- a/module/VuFind/src/VuFind/Hierarchy/TreeDataSource/Solr.php +++ b/module/VuFind/src/VuFind/Hierarchy/TreeDataSource/Solr.php @@ -349,7 +349,17 @@ class Solr extends AbstractBase */ public function supports($id) { - // Assume all IDs are supported. + $settings = $this->hierarchyDriver->getTreeSettings(); + + if (!isset($settings['checkAvailability']) || $settings['checkAvailability']==1) { + $results = $this->searchService->retrieve( + 'Solr', $id, new ParamBag(array('fq' => $this->filters)) + ); + if ($results->getTotal() < 1) { + return false; + } + } + // If we got this far the support-check was positive in any case. return true; } } diff --git a/module/VuFindConsole/src/VuFindConsole/Controller/UtilController.php b/module/VuFindConsole/src/VuFindConsole/Controller/UtilController.php index c2ebd31474f..f2f5f0e7d83 100644 --- a/module/VuFindConsole/src/VuFindConsole/Controller/UtilController.php +++ b/module/VuFindConsole/src/VuFindConsole/Controller/UtilController.php @@ -462,27 +462,31 @@ class UtilController extends AbstractBase "\tBuilding tree for " . $recordid . '... ' . number_format($count) . ' records' ); - $driver = $recordLoader->load($recordid); - // Only do this if the record is actually a hierarchy type record - if ($driver->getHierarchyType()) { - // JSON - if (!$this->consoleOpts->getOption('skip-json')) { - Console::writeLine("\t\tJSON cache..."); - $driver->getHierarchyDriver()->getTreeSource()->getJSON( - $recordid, array('refresh' => true) - ); - } else { - Console::writeLine("\t\tJSON skipped."); - } - // XML - if (!$this->consoleOpts->getOption('skip-xml')) { - Console::writeLine("\t\tXML cache..."); - $driver->getHierarchyDriver()->getTreeSource()->getXML( - $recordid, array('refresh' => true) - ); - } else { - Console::writeLine("\t\tXML skipped."); + try { + $driver = $recordLoader->load($recordid); + // Only do this if the record is actually a hierarchy type record + if ($driver->getHierarchyType()) { + // JSON + if (!$this->consoleOpts->getOption('skip-json')) { + Console::writeLine("\t\tJSON cache..."); + $driver->getHierarchyDriver()->getTreeSource()->getJSON( + $recordid, array('refresh' => true) + ); + } else { + Console::writeLine("\t\tJSON skipped."); + } + // XML + if (!$this->consoleOpts->getOption('skip-xml')) { + Console::writeLine("\t\tXML cache..."); + $driver->getHierarchyDriver()->getTreeSource()->getXML( + $recordid, array('refresh' => true) + ); + } else { + Console::writeLine("\t\tXML skipped."); + } } + } catch (\VuFind\Exception\RecordMissing $e) { + Console::writeLine("WARNING! - Caught exception: " . $e->getMessage() . "\n"); } } Console::writeLine( @@ -554,4 +558,4 @@ class UtilController extends AbstractBase Console::writeLine(str_replace('%%count%%', $count, $successString)); return $this->getSuccessResponse(); } -} \ No newline at end of file +} -- GitLab