public function getSuggestedLinksForRegistryObject(_registry_object $registry_object, $start, $rows)
 {
     // First, get published records with the same identifier as us
     // Note: whilst we can use SOLR to get the linked-to records,
     //       we shouldn't use SOLR to get our own information, as
     //       this would mean that DRAFT requests fail (drafts NOT
     // 		 in SOLR index).
     $suggestions = array();
     $sxml = $registry_object->getSimpleXML();
     if ($sxml->registryObject) {
         $sxml = $sxml->registryObject;
     }
     // Identifier matches (if another object has the same identifier)
     //var_dump($sxml);
     $my_identifiers = array();
     if ($sxml->{strtolower($registry_object->class)}->identifier) {
         foreach ($sxml->{strtolower($registry_object->class)}->identifier as $identifier) {
             if ((string) $identifier != '') {
                 $my_identifiers[] = (string) $identifier;
             }
         }
     }
     if (count($my_identifiers) == 0) {
         return $suggestions;
     }
     $identifier_search_query = '';
     if (sizeof($my_identifiers) > 0) {
         $identifier_search_query = join('","', $my_identifiers);
         $identifier_search_query = '+identifier_value:("' . $identifier_search_query . '")';
     }
     // But exclude already related objects
     $my_relationships = array_map(function ($elt) {
         return $elt;
     }, $registry_object->getRelatedKeys());
     $my_relationships[] = $registry_object->key;
     $relationship_search_query = '';
     if (sizeof($my_relationships) > 0) {
         $relationship_search_query = implode('") -key:("', $my_relationships);
         $relationship_search_query = '-key:("' . $relationship_search_query . '")';
     }
     $query = $relationship_search_query;
     if ($identifier_search_query != '') {
         $query .= ' AND ' . $identifier_search_query;
     }
     $suggestions = $this->getSuggestionsBySolrQuery($query, $start, $rows);
     if (sizeof($suggestions) > 0) {
         $suggestions['values'] = $my_identifiers;
     }
     return $suggestions;
 }
Exemplo n.º 2
0
 public function getSuggestedLinksForRegistryObject(_registry_object $registry_object, $start, $rows)
 {
     // First, get published records with the same identifier as us
     // Note: whilst we can use SOLR to get the linked-to records,
     //       we shouldn't use SOLR to get our own information, as
     //       this would mean that DRAFT requests fail (drafts NOT
     // 		 in SOLR index).
     $suggestions = array();
     $sxml = $registry_object->getSimpleXML();
     if ($sxml->registryObject) {
         $sxml = $sxml->registryObject;
     }
     // Subject matches
     $my_subjects = array();
     if ($sxml->{strtolower($registry_object->class)}->subject) {
         foreach ($sxml->{strtolower($registry_object->class)}->subject as $subject) {
             $my_subjects[] = (string) removeBadValue($subject);
         }
     }
     if (count($my_subjects) == 0) {
         return $suggestions;
     }
     if (sizeof($my_subjects) > 0) {
         $subject_search_query = join('" OR subject_value_resolved:"', $my_subjects);
         $subject_search_query = "(subject_value_resolved:\"" . $subject_search_query . "\")";
     }
     // But exclude already related objects
     $my_relationships = array_map(function ($elt) {
         return $elt;
     }, $registry_object->getRelatedKeys());
     $my_relationships[] = $registry_object->key;
     $relationship_search_query = '';
     if (sizeof($my_relationships) > 0) {
         $relationship_search_query = join('","', $my_relationships);
         $relationship_search_query = '-key:("' . $relationship_search_query . '")';
     }
     $query = $relationship_search_query;
     if ($subject_search_query != '') {
         $query .= ' AND ' . $subject_search_query;
     }
     $suggestions = $this->getSuggestionsBySolrQuery($query, $start, $rows);
     if (sizeof($suggestions) > 0) {
         $suggestions['values'] = $my_subjects;
     }
     return $suggestions;
 }
 public function getSuggestedLinksForRegistryObject(_registry_object $registry_object, $start, $rows)
 {
     // First, get published records with the same identifier as us
     // Note: whilst we can use SOLR to get the linked-to records,
     //       we shouldn't use SOLR to get our own information, as
     //       this would mean that DRAFT requests fail (drafts NOT
     // 		 in SOLR index).
     $sxml = $registry_object->getSimpleXML();
     if ($sxml->registryObject) {
         $sxml = $sxml->registryObject;
     }
     // Identifier matches (if another object has the same identifier)
     //var_dump($sxml);
     $my_identifiers = array('');
     if ($sxml->{strtolower($registry_object->class)}->identifier) {
         foreach ($sxml->{strtolower($registry_object->class)}->identifier as $identifier) {
             $my_identifiers[] = '"' . (string) $identifier . '"';
         }
     }
     $identifier_search_query = implode(" +identifier_value:", $my_identifiers);
     $identifier_search_query = " -slug:" . $registry_object->slug . $identifier_search_query;
     $suggestions = $this->getSuggestionsBySolrQuery($identifier_search_query);
     return $suggestions;
 }
 /**
  * XXX:
  * @return array(_data_source) or NULL
  */
 function create(_data_source $data_source, $registry_object_key, $class, $title, $status, $slug, $record_owner, $harvestID)
 {
     $ro = new _registry_object();
     $ro->_initAttribute("data_source_id", $data_source->getAttribute('data_source_id'), TRUE);
     $ro->_initAttribute("key", $registry_object_key, TRUE);
     $ro->_initAttribute("class", $class, TRUE);
     $ro->_initAttribute("title", $title, TRUE);
     $ro->_initAttribute("status", $status, TRUE);
     $ro->_initAttribute("slug", $slug, TRUE);
     $ro->_initAttribute("record_owner", $record_owner, TRUE);
     $ro->create();
     // Some extras
     $ro->setAttribute("created", time());
     $ro->setAttribute("harvest_id", $harvestID);
     $ro->save();
     return $ro;
 }
Exemplo n.º 5
0
 public function getSuggestedLinksForRegistryObject(_registry_object $registry_object, $start, $rows)
 {
     $CI =& get_instance();
     $q = preg_replace("/[^A-Za-z0-9\\- ]/", ' ', $registry_object->titleWithoutCommonWords());
     // preg_replace("/[^A-Za-z0-9 ]/", ' ',
     $significantsArray = $registry_object->splitTitleBySignificance(strtolower($q));
     $q = rawurlencode($q);
     $q = str_replace("%5C%22", "\"", $q);
     //silly encoding
     $q = '?q=+title:(' . $significantsArray[0] . ")+description:(" . $significantsArray[0] . ")";
     // Result variable
     $links = array();
     // Build the weighted URL based on datacite:resourceTypeGeneral
     //  - First Collections/Datasets
     //  - Then Film, Image, Sound, PhysicalObject, InteractiveResource
     //  - Then Model, Software, Service
     //  - Then Event, Text
     //  - Finally those without a resourceType
     $url = self::DATACITE_SOLR_URL;
     $urlTail = '&defType=disMax';
     $urlTail = '&fq=language_facet%3A"English"';
     // only English
     $urlTail .= '&qf=resourceTypeGeneral:("Collection","Dataset")^9999';
     $urlTail .= '%20+resourceTypeGeneral:("Film","Image","Sound","PhysicalObject","InteractiveResource")^5555';
     $urlTail .= '%20+resourceTypeGeneral:("Model","Software","Service")^1777';
     $urlTail .= '%20+resourceTypeGeneral:("Event","Text")^111';
     $urlTail .= '%20+resourceTypeGeneral:""^1';
     $urlTail .= '&fl=*,score';
     $urlTail .= '&start=' . $start;
     $urlTail .= '&rows=' . $rows;
     $urlTail .= '&version=2.2&wt=json';
     $content = json_decode(file_get_contents($url . $q . $urlTail), true);
     // Check for a valid SOLR response
     if (!isset($content['response']['numFound'])) {
         return $links;
     }
     $found = $content['response']['numFound'];
     /* If we got no results, then lets be more tolerant and add the non-significant words and do fuzzy match */
     $fuzzy_match_url = "";
     if ($found < 10) {
         if (isset($significantsArray[1]) && $significantsArray[1] != '') {
             $q .= '+title:(' . $significantsArray[1] . ")+description:(" . $significantsArray[1] . ")";
         }
         $fuzzy_match_url = $url . $q . $urlTail . '&defType=dismax&mm=3%3C75%25';
         $content = json_decode(file_get_contents($fuzzy_match_url), true);
         $found = $content['response']['numFound'];
     }
     /* Generate the links data */
     if (isset($content['response']['docs'])) {
         foreach ($content['response']['docs'] as $doc) {
             if ($doc['title'][0]) {
                 $links[] = array("url" => self::DATACITE_URL_PREFIX . $doc[self::DATACITE_URL_FIELD], "title" => ellipsis($doc['title'][0], self::DATACITE_TITLE_LENGTH), "class" => "external", "expanded_html" => $CI->load->view("registry_object/datacite_preview", $doc, true));
             }
         }
     }
     if (!$rows) {
         $rows = 10;
     }
     $pagination = array();
     if ($start == 0) {
         $currentPage = 1;
     } else {
         $currentPage = ceil($start / $rows) + 1;
     }
     $totalPage = ceil($content['response']['numFound'] / (int) $rows);
     if ($currentPage != 1) {
         $prev = $start - $rows;
         $next = $start + $rows;
     } else {
         if ($currentPage == 1 && $totalPage == 1) {
             $prev = false;
             $next = false;
         } else {
             if ($currentPage == $totalPage) {
                 $prev = $start - $rows;
                 $next = false;
             } else {
                 $prev = false;
                 $next = $start + $rows;
                 $debug = '1';
             }
         }
     }
     $pagination = array("currentPage" => $currentPage, "totalPage" => $totalPage);
     if ($prev) {
         $pagination['prev'] = $prev;
     }
     if ($next) {
         $pagination['next'] = $next;
     }
     if ($start == 10) {
         $pagination['prev'] = '0';
     }
     $response = array("count" => $found, "links" => $links, "pagination" => $pagination, "suggestor" => "datacite");
     return $response;
 }