Пример #1
0
 /**
  * Establishes base settings for making recommendations.
  *
  * @param string                            $settings Settings from config.ini
  * @param \VuFind\RecordDriver\AbstractBase $driver   Record driver object
  *
  * @return void
  */
 public function init($settings, $driver)
 {
     // Create array of query parts:
     $parts = [];
     // Add Dewey class to query
     $deweyClass = $driver->tryMethod('getDeweyCallNumber');
     if (!empty($deweyClass)) {
         // Skip "English Fiction" Dewey class -- this won't give us useful
         // matches because there's too much of it and it's too broad.
         if (substr($deweyClass, 0, 3) != '823') {
             $parts[] = 'srw.dd any "' . $deweyClass . '"';
         }
     }
     // Add author to query
     $author = $driver->getPrimaryAuthor();
     if (!empty($author)) {
         $parts[] = 'srw.au all "' . $author . '"';
     }
     // Add subjects to query
     $subjects = $driver->getAllSubjectHeadings();
     foreach ($subjects as $current) {
         $parts[] = 'srw.su all "' . implode(' ', $current) . '"';
     }
     // Add title to query
     $title = $driver->getTitle();
     if (!empty($title)) {
         $parts[] = 'srw.ti any "' . str_replace('"', '', $title) . '"';
     }
     // Build basic query:
     $query = '(' . implode(' or ', $parts) . ')';
     // Not current record ID if this is already a WorldCat record:
     if ($driver->getSourceIdentifier() == 'WorldCat') {
         $id = $driver->getUniqueId();
         $query .= " not srw.no all \"{$id}\"";
     }
     // Perform the search and save results:
     $queryObj = new \VuFindSearch\Query\Query($query);
     $result = $this->searchService->search('WorldCat', $queryObj, 0, 5);
     $this->results = $result->getRecords();
 }