public function doExecute() { $configToken = $this->registry->getConfig("BX_TOKEN", false); if ($configToken != null) { $configBX = $this->registry->getConfig("BX_SERVICE_URL", false, "http://recommender.service.exlibrisgroup.com/service"); $configLinkResolver = $this->registry->getConfig("LINK_RESOLVER_ADDRESS", true); $configSID = $this->registry->getConfig("APPLICATION_SID", false, "calstate.edu:xerxes"); $configMaxRecords = $this->registry->getConfig("BX_MAX_RECORDS", false, "10"); $configMinRelevance = $this->registry->getConfig("BX_MIN_RELEVANCE", false, "0"); $open_url = $this->request->getData("//openurl_kev_co"); $url = $configBX . "/recommender/openurl?token={$configToken}&{$open_url}&res_dat=source=global&threshold={$configMinRelevance}&maxRecords={$configMaxRecords}"; try { $xml = Xerxes_Framework_Parser::request($url, 4); if ($xml == "") { throw new Exception("No response from bx service"); } } catch (Exception $e) { trigger_error("Could not get result from bX service: " . $e->getTraceAsString(), E_USER_WARNING); return 1; } // header("Content-type: text/xml"); echo $xml; exit; $doc = new Xerxes_BxRecord_Document(); $doc->loadXML($xml); $objXml = new DOMDocument(); $objXml->loadXML("<recommendations />"); $results = $doc->records(); $x = 0; if (count($results) > 1) { foreach ($doc->records() as $record) { // first one is the same document if ($x == 0) { $x++; continue; } $objRecord = $objXml->createElement("record"); $objXml->documentElement->appendChild($objRecord); $objImport = $objXml->importNode($record->toXML()->documentElement, true); $objRecord->appendChild($objImport); $strOpenURL = $record->getOpenURL($configLinkResolver, $configSID); $objOpenURL = $objXml->createElement("url_open", Xerxes_Framework_Parser::escapeXML($strOpenURL)); $objRecord->appendChild($objOpenURL); } } $this->request->addDocument($objXml); } return 1; }
/** * Take search results and convert them to xml, with all the enhancements, including facets */ public function resultsXML() { $this->url = $this->search_object->getURL(); // get total and set in session if ($this->total == null) { $this->total = $this->search_object->getTotal(); } $id = $this->getHashID() . "-" . $this->getHash(); $this->request->setSession($id, number_format($this->total)); $results_xml = new DOMDocument(); $results_xml->loadXML("<results />"); // other cached search hits? foreach ($this->request->getAllSession() as $session_id => $session_value) { if (strstr($session_id, $this->query_hash)) { $id = str_replace("-" . $this->query_hash, "", $session_id); $other = $results_xml->createElement("other", $session_value); $other->setAttribute("module", $id); $results_xml->documentElement->appendChild($other); } } // spelling $spelling_url = $this->linkSpelling(); $spelling = $results_xml->createElement("spelling", Xerxes_Framework_Parser::escapeXml($this->request->getProperty("spelling_query"))); $spelling->setAttribute("url", $spelling_url); $results_xml->documentElement->appendChild($spelling); // add in the original url for debugging $search_url = $results_xml->createElement("search_url", Xerxes_Framework_Parser::escapeXml($this->url)); $results_xml->documentElement->appendChild($search_url); // add total $total = $results_xml->createElement("total", number_format($this->total)); $results_xml->documentElement->appendChild($total); // add facets that have been selected $facets_chosen = $this->request->getProperties("facet.*", true); if (count($facets_chosen) > 0) { $facet_applied = $results_xml->createElement("facets_applied"); $results_xml->documentElement->appendChild($facet_applied); foreach ($facets_chosen as $key => $facet) { $facet_level = $results_xml->createElement("facet_level", Xerxes_Framework_Parser::escapeXml($facet)); $facet_applied->appendChild($facet_level); $url = new Xerxes_Framework_Request_URL($this->currentParams()); $url->removeProperty($key, $facet); $remove_url = $this->request->url_for($url); $facet_level->setAttribute("url", $remove_url); } } if (count($this->results) > 0) { ## records $records_xml = $results_xml->createElement("records"); $results_xml->documentElement->appendChild($records_xml); foreach ($this->results as $result) { $record_container = $results_xml->createElement("record"); $records_xml->appendChild($record_container); // full-record link $record_link = Xerxes_Framework_Parser::escapeXml($this->linkFullRecord($result)); $link_full = $results_xml->createElement("url", $record_link); $record_container->appendChild($link_full); // this one for backwards compatibility $link_full = $results_xml->createElement("url_full", $record_link); $record_container->appendChild($link_full); // open-url link (which may be a redirect) $record_openurl = Xerxes_Framework_Parser::escapeXml($this->linkOpenURL($result)); $link_full = $results_xml->createElement("url_open", $record_openurl); $record_container->appendChild($link_full); // sms link $record_sms = Xerxes_Framework_Parser::escapeXml($this->linkSMS($result)); $link_sms = $results_xml->createElement("url_sms", $record_sms); $record_container->appendChild($link_sms); // save or delete link $record_save = Xerxes_Framework_Parser::escapeXml($this->linkSaveRecord($result)); $link_save = $results_xml->createElement("url_save", $record_save); $record_container->appendChild($link_save); // this one for backwards compatibility $link_save = $results_xml->createElement("url_save_delete", $record_save); $record_container->appendChild($link_save); // openurl kev context object please $kev = Xerxes_Framework_Parser::escapeXml($result->getOpenURL(null, $this->sid)); $open_url = $results_xml->createElement("openurl_kev_co", $kev); $record_container->appendChild($open_url); // other links (probably things like author, subject links) $this->linkOther($result, $results_xml, $record_container); // xerxes-record $xerxes_xml = $result->toXML(); $import = $results_xml->importNode($xerxes_xml->documentElement, true); $record_container->appendChild($import); // optionally import original xml if ($this->include_original == true) { $original_xml = $result->getOriginalXML(); $original_node = $original_xml; if ($original_xml instanceof DOMDocument) { $original_node = $original_xml->documentElement; } $import = $results_xml->importNode($original_node, true); $record_container->appendChild($import); } } ## recommendations if (count($this->recommendations) > 0) { $recommend_xml = $results_xml->createElement("recommendations"); $results_xml->documentElement->appendChild($recommend_xml); foreach ($this->recommendations as $record) { $record_xml = $results_xml->createElement("record"); $recommend_xml->appendChild($record_xml); $import = $results_xml->importNode($record->toXML()->documentElement, true); $record_xml->appendChild($import); $open_url = $record->getOpenURL($this->link_resolver, $this->sid); $open_url_xml = $results_xml->createElement("url_open", Xerxes_Framework_Parser::escapeXML($open_url)); $record_xml->appendChild($open_url_xml); } } $objPage = new Xerxes_Framework_Page(); ## summary $summary_xml = $objPage->summary($this->total, (int) $this->request->getProperty("startRecord"), $this->max); if ($summary_xml->documentElement != null) { $import = $results_xml->importNode($summary_xml->documentElement, true); $results_xml->documentElement->appendChild($import); } ## sorting $arrParams = $this->sortLinkParams(); $query_string = $this->request->url_for($arrParams); $sort_options = $this->sortOptions(); $current_sort = $this->sort; if ($current_sort == null) { $current_sort = $this->sort_default; } $sort_xml = $objPage->sortDisplay($query_string, $current_sort, $sort_options); $import = $results_xml->importNode($sort_xml->documentElement, true); $results_xml->documentElement->appendChild($import); ## pager $arrParams = $this->pagerLinkParams(); $pager_xml = $objPage->pager_dom($arrParams, "startRecord", (int) $this->request->getProperty("startRecord"), null, (int) $this->total, $this->max, $this->request); $import = $results_xml->importNode($pager_xml->documentElement, true); $results_xml->documentElement->appendChild($import); } ## facets $facets = $this->facets->toXML(); $import = $results_xml->importNode($facets->documentElement, true); $results_xml->documentElement->appendChild($import); return $results_xml; }
public function doExecute() { $arrResults = array(); // holds returned records $iTotalHits = 0; // total number of facets stored $arrFields = array(); // fields to return in response $arrDocs = array(); // stores list of document numbers $strFacetName = ""; // facet name // metalib search object $objSearch = $this->getSearchObject(); // parameters from request $id = $this->request->getProperty("group"); $strGroup = $this->getGroupNumber(); $strResultSet = $this->request->getProperty("resultSet"); // to correct a bug in 4.1.0 $iStartRecord = (int) $this->request->getProperty("startRecord"); $iFacet = $this->request->getProperty("facet"); $iNode = $this->request->getProperty("node"); // marc fields to return from metalib; we specify these here in order to keep // the response size as small (and thus as fast) as possible // @todo factor this out to metasearch parent class $strMarcFields = $strMarcFields = self::MARC_FIELDS_BRIEF; // configuration options $configRecordPerPage = $this->registry->getConfig("RECORDS_PER_PAGE", false, self::DEFAULT_RECORDS_PER_PAGE); $configMarcFields = $this->registry->getConfig("MARC_FIELDS_BRIEF", false); $configIncludeMarcRecord = $this->registry->getConfig("XERXES_BRIEF_INCLUDE_MARC", false, false); $configFacets = $this->registry->getConfig("FACETS", false, false); // add additional marc fields specified in the config file if ($configMarcFields != null) { $configMarcFields .= ", " . $strMarcFields; } else { $configMarcFields = $strMarcFields; } // empty querystring values will return as 0, so fix here in case if ($iStartRecord == 0) { $iStartRecord = 1; } $iMaximumRecords = (int) $configRecordPerPage; // get the list of document numbers for the facet from the cached // facet file (full version), then get only the range we've requested; // should we change this to make it more efficient? $objFacets = $this->getCache($id, "facets", "SimpleXML"); $strXpath = "//cluster_facet[position() = {$iFacet}]/node[position() = {$iNode}]"; foreach ($objFacets->xpath($strXpath) as $node) { // extract the name of the facet $strFacetName = $node["name"]; // get the list of document numbers foreach ($node->doc_num as $doc_num) { array_push($arrDocs, (string) $doc_num); } } $iTotalHits = count($arrDocs); if ($iTotalHits < 1) { throw new Exception("could not find facet!"); } // set marc fields to return in response $arrFields = explode(",", $configMarcFields); // get marc-xml results from metalib $objResultsXml = $objSearch->retrieve($strResultSet, $iStartRecord, $iMaximumRecords, null, "customize", $arrFields, $arrDocs); // extract marc records, this->addRecords will convert to xerxes_record foreach ($objResultsXml->getElementsByTagName("record") as $objRecord) { array_push($arrResults, $objRecord); } // build the response, including previous cached data $objXml = new DOMDocument(); $objXml = $this->documentElement(); // facet name $objXml->documentElement->appendChild($objXml->createElement("facet_name", Xerxes_Framework_Parser::escapeXML($strFacetName))); $objXml = $this->addSearchInfo($objXml, $id); $objXml = $this->addStatus($objXml, $id, $strResultSet, $iTotalHits); $objXml = $this->addProgress($objXml, $this->request->getSession("refresh-{$strGroup}")); $objXml = $this->addRecords($objXml, $arrResults, $configIncludeMarcRecord); $objXml = $this->addFacets($objXml, $id, $configFacets); // add to master xml $this->request->addDocument($objXml); return 1; }
protected function linkOther($result, $results_xml, $record_container) { // author links $arrAuthorsReverse = $result->getAuthors(false, true, true); $arrAuthorsForward = $result->getAuthors(false, true); for ($a = 0; $a < count($arrAuthorsReverse); $a++) { $strAuthorReverse = $arrAuthorsReverse[$a]; $strAuthorForward = $arrAuthorsForward[$a]; $arrLink = array("base" => $this->request->getProperty("base"), "action" => "search", "source" => $this->request->getProperty("source"), "query" => Xerxes_Framework_Parser::escapeXML($strAuthorReverse), "field" => "au", "spell" => "none"); $author_url = $this->request->url_for($arrLink); $objAuthorLink = $results_xml->createElement("author_link", Xerxes_Framework_Parser::escapeXML($strAuthorForward)); $objAuthorLink->setAttribute("link", $author_url); $record_container->appendChild($objAuthorLink); } // lateral subject links foreach ($result->getSubjects() as $subject) { $arrLink = array("base" => $this->request->getProperty("base"), "action" => "search", "source" => $this->request->getProperty("source"), "query" => Xerxes_Framework_Parser::escapeXML($subject->value), "field" => "su", "spell" => "none"); $subject_url = $this->request->url_for($arrLink); $objSubjectLink = $results_xml->createElement("subject_link", Xerxes_Framework_Parser::escapeXML($subject->display)); $objSubjectLink->setAttribute("link", $subject_url); $record_container->appendChild($objSubjectLink); } }
protected function addAlphaList() { // check for letters in session $alpha_list = $this->request->getSession("alpha_list"); if ($alpha_list == "") { $objDataMap = new Xerxes_DataMap(); // check database cache $arrCache = $objDataMap->getCache("dblist", "az"); if (count($arrCache) > 0) { $objCache = $arrCache[0]; $alpha_list = $objCache->data; } else { // so create it $alpha_list_array = $objDataMap->getDatabaseAlpha(); $alpha_list = implode(',', $alpha_list_array); // and cache it in the database $objCache = new Xerxes_Data_Cache(); $objCache->source = "dblist"; $objCache->id = "az"; $objCache->data = $alpha_list; $objCache->expiry = time() + 60 * 60; // for one hour $objDataMap->setCache($objCache); } // cache it in session too! $this->request->setSession("alpha_list", $alpha_list); } // add it to the interface $objAlpha = new DOMDocument(); $objAlpha->loadXML("<alpha />"); foreach (explode(',', $alpha_list) as $letter) { $objEntry = $objAlpha->createElement("entry"); $objAlpha->documentElement->appendChild($objEntry); $objLetter = $objAlpha->createElement("letter", $letter); $objEntry->appendChild($objLetter); $params = array("base" => "databases", "action" => "alphabetical", "alpha" => $letter); $link = $this->request->url_for($params); $objLink = $objAlpha->createElement("link", Xerxes_Framework_Parser::escapeXML($link)); $objEntry->appendChild($objLink); } $this->request->addDocument($objAlpha); }