public function indexAction() { $queryBuilder = new Util_QueryBuilder($this->log, true); // support backward compatibility: interpret missing parameter searchtype as latest search if (is_null($this->getRequest()->getParam('searchtype', null))) { $this->getRequest()->setParam('searchtype', Util_Searchtypes::LATEST_SEARCH); } $params = array(); try { $params = $queryBuilder->createQueryBuilderInputFromRequest($this->getRequest()); } catch (Util_QueryBuilderException $e) { $this->log->err(__METHOD__ . ' : ' . $e->getMessage()); throw new Application_Exception($e->getMessage()); } // overwrite parameters in rss context // rss feeds have a fixed maximum number of items $params['rows'] = self::NUM_OF_ITEMS_PER_FEED; $params['start'] = 0; // rss feeds have both a fixed sort field and sort order $params['sortField'] = self::RSS_SORT_FIELD; $params['sortOrder'] = self::RSS_SORT_ORDER; $resultList = array(); try { $searcher = new Opus_SolrSearch_Searcher(); $resultList = $searcher->search($queryBuilder->createSearchQuery($params)); } catch (Opus_SolrSearch_Exception $exception) { $this->handleSolrError($exception); } $this->loadStyleSheet($this->view->getScriptPath('') . 'stylesheets' . DIRECTORY_SEPARATOR . 'rss2_0.xslt'); $this->setLink(); $this->setDates($resultList); $this->setItems($resultList); $this->setFrontdoorBaseUrl(); }
/** * Returns all index documents that are associated to the given collection id. * * @param int $collectionId * @return array An array of Opus_SolrSearch_Result objects. * @throws Opus_SolrSearch_Exception */ private function getListItems($collectionId) { $query = new Opus_SolrSearch_Query(Opus_SolrSearch_Query::SIMPLE); $query->setCatchAll('*:*'); $query->addFilterQuery('collection_ids', $collectionId); $query->setRows(Opus_SolrSearch_Query::MAX_ROWS); $solrsearch = new Opus_SolrSearch_Searcher(); return $solrsearch->search($query)->getResults(); }
/** * Prepares xml export for solr search results. */ public function prepareXml($xml, $proc, $request) { try { $searcher = new Opus_SolrSearch_Searcher(); if ($request->getParam('searchtype') == 'id') { $resultList = $this->buildResultListForIdSearch($request); } else { $resultList = $searcher->search($this->buildQuery($request)); } $this->handleResults($resultList->getResults(), $resultList->getNumberOfHits(), $xml, $proc); } catch (Opus_SolrSearch_Exception $e) { $this->getLogger()->err(__METHOD__ . ' : ' . $e); throw new Application_SearchException($e, true); } }
public function doctypesAction() { $facetname = 'doctype'; $query = new Opus_SolrSearch_Query(Opus_SolrSearch_Query::FACET_ONLY); $query->setFacetField($facetname); $facets = array(); try { $searcher = new Opus_SolrSearch_Searcher(); $facets = $searcher->search($query)->getFacets(); } catch (Opus_SolrSearch_Exception $e) { $this->getLogger()->err(__METHOD__ . ' : ' . $e); throw new Application_SearchException($e); } $docTypesTranslated = array(); foreach ($facets[$facetname] as $facetitem) { $translation = $this->view->translate($facetitem->getText()); $docTypesTranslated[$translation] = $facetitem; } uksort($docTypesTranslated, "strnatcasecmp"); $this->view->facetitems = $docTypesTranslated; $this->view->title = $this->view->translate('solrsearch_browse_doctypes'); }
/** * Displays the metadata of a document. * @return void */ public function indexAction() { $request = $this->getRequest(); $docId = $request->getParam('docId', ''); if ($request->has('searchtype') && $request->has('rows') && $request->has('start')) { $listRows = $request->getParam('rows'); $start = $request->getParam('start'); $this->view->listRows = $listRows; $request->setParam('rows', '1'); // make sure only 1 entry is diplayed $query = Application_Search_Navigation::getQueryUrl($request, $this->getLogger()); $searcher = new Opus_SolrSearch_Searcher(); $resultList = $searcher->search($query); $queryResult = $resultList->getResults(); if (is_array($queryResult) && !empty($queryResult) && $queryResult[0] instanceof Opus_Search_Result_Match) { $resultDocId = $queryResult[0]->getId(); if (!empty($docId)) { if ($resultDocId != $docId) { $this->view->messages = array('notice' => $this->view->translate('frontdoor_pagination_list_changed')); } } else { $docId = $resultDocId; } $this->view->paginate = true; $numHits = $resultList->getNumberOfHits(); if ($request->getParam('searchtype') == 'latest') { $this->view->numOfHits = $numHits < $listRows ? $numHits : $listRows; } else { $this->view->numOfHits = $numHits; } $this->view->searchPosition = $start; $this->view->firstEntry = 0; $this->view->lastEntry = $this->view->numOfHits - 1; $this->view->previousEntry = $this->view->searchPosition - 1 < 0 ? 0 : $this->view->searchPosition - 1; $this->view->nextEntry = $this->view->searchPosition + 1 < $this->view->numOfHits - 1 ? $this->view->searchPosition + 1 : $this->view->numOfHits - 1; } } if ($docId == '') { $this->printDocumentError("frontdoor_doc_id_missing", 404); return; } // call export index-action, if parameter is set if (!is_null($this->getRequest()->getParam('export'))) { $params = $this->getRequest()->getParams(); // export module ignores pagination parameters unset($params['rows']); unset($params['start']); $params['searchtype'] = 'id'; return $this->_redirectToAndExit('index', null, 'index', 'export', $params); } $this->view->title = $this->view->translate('frontdoor_title'); $this->view->docId = $docId; $baseUrl = $request->getBaseUrl(); $document = null; try { $document = new Opus_Document($docId); } catch (Opus_Model_NotFoundException $e) { $this->printDocumentError("frontdoor_doc_id_not_found", 404); return; } $documentXml = null; try { $documentXml = new Application_Util_Document($document); } catch (Application_Exception $e) { switch ($document->getServerState()) { case self::SERVER_STATE_DELETED: $this->printDocumentError("frontdoor_doc_deleted", 410); return; case self::SERVER_STATE_UNPUBLISHED: $this->printDocumentError("frontdoor_doc_unpublished", 403); return; } $this->printDocumentError("frontdoor_doc_access_denied", 403); return; } $documentNode = $documentXml->getNode(); /* XSLT transformation. */ $docBuilder = new Frontdoor_Model_DocumentBuilder(); $xslt = $docBuilder->buildDomDocument($this->view->getScriptPath('index') . DIRECTORY_SEPARATOR . 'index'); $proc = new XSLTProcessor(); $proc->registerPHPFunctions(self::TRANSLATE_FUNCTION); $proc->registerPHPFunctions(self::TRANSLATE_DEFAULT_FUNCTION); $proc->registerPHPFunctions(self::FILE_ACCESS_FUNCTION); $proc->registerPHPFunctions(self::FORMAT_DATE_FUNCTION); $proc->registerPHPFunctions(self::EMBARGO_ACCESS_FUNCTION); $proc->registerPHPFunctions(self::SORT_ORDER_FUNCTION); $proc->registerPHPFunctions(self::CHECK_LANGUAGE_FILE_FUNCTION); $proc->registerPHPFunctions(self::GET_STYLESHEET_FUNCTION); $proc->registerPHPFunctions('urlencode'); $proc->importStyleSheet($xslt); $config = $this->getConfig(); $layoutPath = 'layouts/' . (isset($config, $config->theme) ? $config->theme : ''); $numOfShortAbstractChars = isset($config, $config->frontdoor->numOfShortAbstractChars) ? $config->frontdoor->numOfShortAbstractChars : '0'; $proc->setParameter('', 'baseUrlServer', $this->view->fullUrl()); $proc->setParameter('', 'baseUrl', $baseUrl); $proc->setParameter('', 'layoutPath', $baseUrl . '/' . $layoutPath); $proc->setParameter('', 'isMailPossible', $this->isMailPossible($document)); $proc->setParameter('', 'numOfShortAbstractChars', $numOfShortAbstractChars); $proc->setParameter('', 'urnResolverUrl', $config->urn->resolverUrl); /* print on demand config */ $printOnDemandEnabled = false; $podConfig = $config->get('printOnDemand', false); if ($podConfig !== false) { $printOnDemandEnabled = true; $proc->setParameter('', 'printOnDemandUrl', $podConfig->get('url', '')); $proc->setParameter('', 'printOnDemandButton', $podConfig->get('button', '')); } $proc->setParameter('', 'printOnDemandEnabled', $printOnDemandEnabled); $frontdoorContent = $proc->transformToXML($documentNode); /* Setup view. */ $this->view->frontdoor = $frontdoorContent; $this->view->baseUrl = $baseUrl; $this->view->doctype('<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML+RDFa 1.0//EN" "http://www.w3.org/MarkUp/DTD/xhtml-rdfa-1.dtd">'); $dateModified = $document->getServerDateModified(); if (!is_null($dateModified)) { $this->view->headMeta()->appendHttpEquiv('Last-Modified', $dateModified->getDateTime()->format(DateTime::RFC1123)); } $this->addMetaTagsForDocument($document); $this->view->title = $this->getFrontdoorTitle($document); $this->incrementStatisticsCounter($docId); $actionbox = new Admin_Form_ActionBox(); $actionbox->prepareRenderingAsView(); $actionbox->populateFromModel($document); $this->view->adminform = $actionbox; }
* @version $Id: find_missing_published_docs_in_searchindex.php 12011 2013-07-05 19:39:58Z sszott $ */ /** * * Dieses Skript gibt alle IDs der Dokumente zurück, die im Server State * published sind, aber aufgrund eines Fehlers nicht im Index repräsentiert sind. * * Siehe dazu auch die Story OPUSVIER-2368. * */ $numOfErrors = 0; $finder = new Opus_DocumentFinder(); $finder->setServerState('published'); foreach ($finder->ids() as $docId) { // check if document with id $docId is already persisted in search index $query = new Opus_SolrSearch_Query(Opus_SolrSearch_Query::DOC_ID); $query->setField('id', $docId); $query->setReturnIdsOnly(true); $query->setRows(Opus_SolrSearch_Query::MAX_ROWS); $searcher = new Opus_SolrSearch_Searcher(); if ($searcher->search($query)->getNumberOfHits() != 1) { echo "document # {$docId} is not stored in search index\n"; $numOfErrors++; } } if ($numOfErrors > 0) { echo "{$numOfErrors} missing documents were found\n"; } else { echo "no errors were found\n"; } exit;
private function getDocsInSearchIndex($checkConsistency = true) { $searcher = new Opus_SolrSearch_Searcher(); $query = new Opus_SolrSearch_Query(); $query->setCatchAll("*:*"); $query->setRows(Opus_SolrSearch_Query::MAX_ROWS); $resultList = $searcher->search($query, $checkConsistency); return $resultList; }
private function performSearch() { $this->_logger->debug('performing search'); try { $searcher = new Opus_SolrSearch_Searcher(); $this->openFacets = $this->facetMenu->buildFacetArray($this->_request->getParams()); $searcher->setFacetArray($this->openFacets); $this->resultList = $searcher->search($this->query); } catch (Opus_SolrSearch_Exception $e) { $this->_logger->err(__METHOD__ . ' : ' . $e); throw new Application_SearchException($e); } $this->numOfHits = $this->resultList->getNumberOfHits(); }
* Fehlermeldung pro Dokument ausgegeben. * * Siehe dazu auch das Ticket OPUSVIER-2853. * */ $numOfModified = 0; $numOfErrors = 0; $finder = new Opus_DocumentFinder(); $finder->setServerState('published'); foreach ($finder->ids() as $docId) { // check if document with id $docId is already persisted in search index $query = new Opus_SolrSearch_Query(Opus_SolrSearch_Query::DOC_ID); $query->setField('id', $docId); // $query->setReturnIdsOnly(true); $query->setRows(Opus_SolrSearch_Query::MAX_ROWS); $searcher = new Opus_SolrSearch_Searcher(); $search = $searcher->search($query); if ($search->getNumberOfHits() != 1) { echo "ERROR: document # {$docId} is not stored in search index\n"; $numOfErrors++; } else { $result = $search->getResults(); $solrModificationDate = $result[0]->getServerDateModified(); $document = new Opus_Document($docId); $docModificationDate = $document->getServerDateModified()->getUnixTimestamp(); if ($solrModificationDate != $docModificationDate) { $numOfModified++; echo "document # {$docId} is modified\n"; } } }