/** * Extract facets from the Solr response * * @param simplexml $xml solr response * @return Facets, null if none */ protected function extractFacets($xml) { $facets = new Search\Facets(); $groups = $xml->xpath("//lst[@name='facet_fields']/lst"); if ($groups !== false && count($groups) > 0) { foreach ($groups as $facet_group) { // if only one entry, then all the results have this same facet, // so no sense even showing this as a limit $count = count($facet_group->int); if ($count <= 1) { continue; } $group_internal_name = (string) $facet_group["name"]; $group = new Search\FacetGroup(); $group->name = $group_internal_name; $group->public = $this->config->getFacetPublicName($group_internal_name); // put facets into an array $facet_array = array(); foreach ($facet_group->int as $int) { $facet_array[(string) $int["name"]] = (int) $int; } // date $decade_display = array(); $is_date = $this->config->isDateType($group_internal_name); if ($is_date == true) { $date_arrays = $group->luceneDateToDecade($facet_array); $decade_display = $date_arrays["display"]; $facet_array = $date_arrays["decades"]; } foreach ($facet_array as $key => $value) { $facet = new Search\Facet(); $facet->name = $key; $facet->count = $value; // dates are different if ($is_date == true) { $facet->name = $decade_display[$key]; $facet->is_date = true; $facet->key = $key; } $group->addFacet($facet); } $facets->addGroup($group); } } return $facets; }
/** * Perform normalization and analysis of PCI return value * (a single record) * * @param simplexml $item The xml record from PCI * * @return array The processed record array * @access protected */ protected function process($item) { global $configArray; $primoRecord = $item->children('http://www.exlibrisgroup.com/xsd/primo/primo_nm_bib'); $links = array(); $backlink = ''; foreach ((array) $primoRecord->PrimoNMBib->record->links->linktorsrc as $val) { $linkString = (string) $val; $ini = strripos($linkString, '$$U'); if ($ini === false) { continue; } $ini += 3; $linkArray = explode('$$', substr($linkString, $ini)); if ($linkArray[0]) { $links[] = $linkArray[0]; } } // Back links sometimes contain non-valid XML and thus cannot // be treated like source links $backlinkString = (string) $primoRecord->PrimoNMBib->record->links->backlink; $ini = strripos($backlinkString, '$$U'); if ($ini !== false) { $ini += 3; $backlinkArray = explode('$$', substr($backlinkString, $ini)); if ($backlinkArray[0]) { $backlink = $backlinkArray[0]; } } $openurl = ''; if (isset($configArray['OpenURL']['url']) && $configArray['OpenURL']['url']) { // Parse the OpenURL and extract parameters $link = $item->xpath('.//sear:LINKS/sear:openurl'); if (!$link) { $link = $item->xpath('.//sear:GETIT/@GetIt2'); if (!$link || $link[0] == "") { $link = $item->xpath('.//sear:GETIT/@GetIt1'); } } if ($link && strpos($link[0], 'url_ver=Z39.88-2004') !== false) { $params = explode('&', substr($link[0], strpos($link[0], '?') + 1)); $openurl = 'rfr_id=' . urlencode($configArray['OpenURL']['rfr_id']); foreach ($params as $param) { if (substr($param, 0, 7) != 'rfr_id=') { $openurl .= '&' . $param; } } } } $fulltext = (string) $primoRecord->PrimoNMBib->record->delivery->fulltext; $title = $this->hiLite((string) $primoRecord->PrimoNMBib->record->display->title); $authors = explode(' ; ', (string) $primoRecord->PrimoNMBib->record->display->creator); foreach ($authors as &$author) { $author = $this->hiLite($author); } return array('title' => $title, 'author' => $authors, 'AdditionalAuthors' => (array) $primoRecord->PrimoNMBib->record->search->creatorcontrib, 'source' => (string) $primoRecord->PrimoNMBib->record->display->source, 'publicationDate' => (string) $primoRecord->PrimoNMBib->record->search->creationdate, 'publicationTitle' => (string) $primoRecord->PrimoNMBib->record->display->ispartof, 'openUrl' => !empty($openurl) ? $openurl : null, 'url' => $links, 'backlink' => $backlink, 'fulltext' => $fulltext, 'fullrecord' => $item->asXML(), 'id' => 'pci.' . (string) $primoRecord->PrimoNMBib->record->search->recordid, 'format' => (string) $primoRecord->PrimoNMBib->record->display->type, 'ISSN' => (string) $primoRecord->PrimoNMBib->record->search->issn, 'language' => (string) $primoRecord->PrimoNMBib->record->facets->language, 'subjectTerms' => (array) $primoRecord->PrimoNMBib->record->search->subject, 'snippet' => (string) $primoRecord->PrimoNMBib->record->display->description, 'volume' => (string) $primoRecord->PrimoNMBib->record->addata->volume, 'issue' => (string) $primoRecord->PrimoNMBib->record->addata->issue, 'startPage' => '', 'endPage' => ''); }
/** * Extract facets from the Solr response * * @param simplexml $xml solr response * @return Facets null if none */ protected function extractFacets($xml) { $facets = new Search\Facets(); $groups = $xml->xpath("//lst[@name='facet_fields']/lst"); if ($groups !== false && count($groups) > 0) { foreach ($groups as $facet_group) { // if only one entry, then all the results have this same facet, // so no sense even showing this as a limit $count = count($facet_group->int); if ($count <= 1) { continue; } $group_internal_name = (string) $facet_group["name"]; $group = new Search\FacetGroup(); $group->name = $group_internal_name; // put facets into an array $facet_array = array(); foreach ($facet_group->int as $int) { $facet_array[(string) $int["name"]] = (int) $int; } $is_date = $this->config->isDateType($group_internal_name); foreach ($facet_array as $key => $value) { $facet = new Search\Facet(); $facet->name = $key; $facet->count = $value; if ($is_date == true) { $facet->is_date = true; $facet->timestamp = strtotime("1/1/{$key}") * 1000; } $group->addFacet($facet); } $facets->addGroup($group); } } return $facets; }