public function doExecute() { $objPage = new Xerxes_Framework_Page(); $iTotalHits = (int) $this->request->getData("results/hits"); $strDatabaseTitle = (string) $this->request->getData("results/database"); $strSortKeys = (string) $this->request->getData("results/sort"); $iMax = $this->registry->getConfig("RECORDS_PER_PAGE", false, 10); // create page hit summary element $objSummaryXml = $objPage->summary($iTotalHits, (int) $this->request->getProperty("startRecord"), $iMax); $this->request->addDocument($objSummaryXml); // create sorting element only for merged results if ($strDatabaseTitle == "Top Results") { $arrParams = array("base" => "metasearch", "action" => "sort", "group" => $this->request->getProperty("group")); $strQueryString = $this->request->url_for($arrParams); $arrSortOptions = array("rank" => "relevance", "year" => "date", "title" => "title", "author" => "author"); if ($strSortKeys == null) { $strSortKeys = $this->registry->getConfig("SORT_ORDER_PRIMARY", false, "rank"); } $objSortXml = $objPage->sortDisplay($strQueryString, $strSortKeys, $arrSortOptions); $this->request->addDocument($objSortXml); } // create paging element $arrParams = array("base" => "metasearch", "action" => $this->request->getProperty("action"), "group" => $this->request->getProperty("group"), "resultSet" => $this->request->getProperty("resultSet")); // only used in facets if ($this->request->getProperty("node") != null) { $arrParams["node"] = $this->request->getProperty("node"); $arrParams["facet"] = $this->request->getProperty("facet"); } $objPagerXml = $objPage->pager_dom($arrParams, "startRecord", (int) $this->request->getProperty("startRecord"), null, (int) $iTotalHits, $iMax, $this->request); $this->request->addDocument($objPagerXml); return 1; }
public function doExecute() { $objPage = new Xerxes_Framework_Page(); // get parameters and configuration information $strUsername = $this->request->getSession("username"); $iStart = (int) $this->request->getProperty("startRecord"); $strLabel = $this->request->getProperty("label"); $strType = $this->request->getProperty("type"); $iMax = $this->registry->getConfig("SAVED_RECORDS_PER_PAGE", false, self::DEFAULT_RECORDS_PER_PAGE); // get total number of saved records $iTotal = $this->getTotal($strUsername, $strLabel, $strType); ### create page hit summary element $objSummaryXml = $objPage->summary($iTotal, $iStart, $iMax); $this->request->addDocument($objSummaryXml); ### create sorting element $strSort = $this->request->getProperty("sortKeys"); if ($strSort == "") { $strSort = "id"; } $arrParams = array("base" => "folder", "action" => "home", "username" => $strUsername, "startRecord" => 1, "label" => $strLabel, "type" => $strType); $strQueryString = $this->request->url_for($arrParams); $arrSortOptions = array("title" => "title", "author" => "author", "year" => "date", "id" => "most recently added"); $objSortXml = $objPage->sortDisplay($strQueryString, $strSort, $arrSortOptions); $this->request->addDocument($objSortXml); ### create paging element $params = array("base" => "folder", "action" => "home", "username" => $this->request->getSession("username"), "sortKeys" => $this->request->getProperty("sortKeys"), "label" => $strLabel, "type" => $strType); $objPagerXml = $objPage->pager_dom($params, "startRecord", (int) $this->request->getProperty("startRecord"), null, $iTotal, $iMax, $this->request); $this->request->addDocument($objPagerXml); 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; }