Exemplo n.º 1
0
 public function getRecordsInGroup()
 {
     $records = [];
     $record = $this->getRecordDriver();
     $query = new \VuFindSearch\Query\Query("local_ids_str_mv:" . '"' . addcslashes($record->getUniqueID(), '":') . '"');
     $docs = $this->searchService->search($record->getSourceIdentifier(), $query);
     foreach ($docs->getRecords() as $record) {
         $fields = $record->getRawData();
         foreach ($fields['local_ids_str_mv'] as $id) {
             $source = substr($id, 0, strpos($id, '.'));
             $records[] = ['source' => 'source_' . $source, 'id' => $id];
         }
     }
     return $records;
 }
Exemplo n.º 2
0
 /**
  * Get a random ID from the Solr index.
  *
  * @return string
  */
 protected function getRandomBibId()
 {
     $source = $this->getRecordSource();
     $query = isset($this->config['Records']['query']) ? $this->config['Records']['query'] : '*:*';
     $result = $this->searchService->random($source, new Query($query), 1);
     if (count($result) === 0) {
         throw new \Exception('Problem retrieving random record from $source.');
     }
     return current($result->getRecords())->getUniqueId();
 }
Exemplo n.º 3
0
 /**
  * Does this data source support the specified hierarchy ID?
  *
  * @param string $id Hierarchy ID.
  *
  * @return bool
  */
 public function supports($id)
 {
     $settings = $this->hierarchyDriver->getTreeSettings();
     if (!isset($settings['checkAvailability']) || $settings['checkAvailability'] == 1) {
         $results = $this->searchService->retrieve('Solr', $id, new ParamBag(['fq' => $this->filters]));
         if ($results->getTotal() < 1) {
             return false;
         }
     }
     // If we got this far the support-check was positive in any case.
     return true;
 }
Exemplo n.º 4
0
 /**
  * Get Solr Children for JSON
  *
  * @param string $parentID The starting point for the current recursion
  * (equivlent to Solr field hierarchy_parent_id)
  * @param string &$count   The total count of items in the tree
  * before this recursion
  *
  * @return string
  */
 protected function getChildrenJson($parentID, &$count)
 {
     $query = new Query('hierarchy_parent_id:"' . addcslashes($parentID, '"') . '"');
     $results = $this->searchService->search('Solr', $query, 0, 10000, new ParamBag(array('fq' => $this->filters, 'hl' => 'false', 'fl' => 'id, title_in_hierarchy, hierarchy_parent_id, hierarchy_sequence, hierarchy_top_title, title')));
     if ($results->getTotal() < 1) {
         return '';
     }
     $json = array();
     $sorting = $this->getHierarchyDriver()->treeSorting();
     foreach ($results->getRecords() as $current) {
         ++$count;
         $titles = $current->getTitlesInHierarchy();
         $title = isset($titles[$parentID]) ? $titles[$parentID] : $current->getTitle();
         $this->debug("{$parentID}: " . $current->getUniqueID());
         $childNode = array('id' => $current->getUniqueID(), 'type' => $current->isCollection() ? 'collection' : 'record', 'title' => htmlspecialchars($title));
         // here, the logic seems to have changed with respect to ::getChildren (creating xml caches). Beforehand, the
         // building of subchildren were not dependent on the type collection=true/false
         // commentend this out to get old behaviour
         //if ($current->isCollection()) {
         $children = $this->getChildrenJson($current->getUniqueID(), $count);
         if (!empty($children)) {
             $childNode['children'] = $children;
         }
         //}
         // If we're in sorting mode, we need to create key-value arrays;
         // otherwise, we can just collect flat values.
         if ($sorting) {
             $positions = $current->getHierarchyPositionsInParents();
             $sequence = isset($positions[$parentID]) ? $positions[$parentID] : 0;
             $json[] = array($sequence, $childNode);
         } else {
             $json[] = $childNode;
         }
     }
     return $sorting ? $this->sortNodes($json) : $json;
 }
Exemplo n.º 5
0
 /**
  * Given an array of IDs and a record source, load a batch of records for
  * that source.
  *
  * @param array  $ids    Record IDs
  * @param string $source Record source
  *
  * @throws \Exception
  * @return array
  */
 public function loadBatchForSource($ids, $source = DEFAULT_SEARCH_BACKEND)
 {
     $cachedRecords = [];
     if (null !== $this->recordCache && $this->recordCache->isPrimary($source)) {
         // Try to load records from cache if source is cachable
         $cachedRecords = $this->recordCache->lookupBatch($ids, $source);
         // Check which records could not be loaded from the record cache
         foreach ($cachedRecords as $cachedRecord) {
             $key = array_search($cachedRecord->getUniqueId(), $ids);
             if ($key !== false) {
                 unset($ids[$key]);
             }
         }
     }
     // Try to load the uncached records from the original $source
     $genuineRecords = [];
     if (!empty($ids)) {
         $genuineRecords = $this->searchService->retrieveBatch($source, $ids)->getRecords();
         foreach ($genuineRecords as $genuineRecord) {
             $key = array_search($genuineRecord->getUniqueId(), $ids);
             if ($key !== false) {
                 unset($ids[$key]);
             }
         }
     }
     if (!empty($ids) && null !== $this->recordCache && $this->recordCache->isFallback($source)) {
         // Try to load missing records from cache if source is cachable
         $cachedRecords = $this->recordCache->lookupBatch($ids, $source);
     }
     // Merge records found in cache and records loaded from original $source
     $retVal = $genuineRecords;
     foreach ($cachedRecords as $cachedRecord) {
         $retVal[] = $cachedRecord;
     }
     return $retVal;
 }
Exemplo n.º 6
0
 /**
  * Called at the end of the Search Params objects' initFromRequest() method.
  * This method is responsible for setting search parameters needed by the
  * recommendation module and for reading any existing search parameters that may
  * be needed.
  *
  * @param \VuFind\Search\Base\Params $params  Search parameter object
  * @param \Zend\StdLib\Parameters    $request Parameter object representing user
  * request.
  *
  * @return void
  */
 public function init($params, $request)
 {
     if ("retain" !== $this->mode) {
         $randomParams = $this->paramManager->get($params->getSearchClassId());
     } else {
         $randomParams = clone $params;
     }
     foreach ($this->filters as $filter) {
         $randomParams->addFilter($filter);
     }
     $query = $randomParams->getQuery();
     $paramBag = $randomParams->getBackendParameters();
     $this->results = $this->searchService->random($this->backend, $query, $this->limit, $paramBag)->getRecords();
 }
Exemplo n.º 7
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)
 {
     $this->results = $this->searchService->similar($driver->getSourceIdentifier(), $driver->getUniqueId());
 }
Exemplo n.º 8
0
 /**
  * Get an array of Record Driver objects representing items similar to the one
  * passed to the constructor.
  *
  * @return array
  */
 public function getResults()
 {
     $record = $this->getRecordDriver();
     $params = new \VuFindSearch\ParamBag(['rows' => 40]);
     return $this->searchService->similar($record->getSourceIdentifier(), $record->getUniqueId(), $params);
 }
Exemplo n.º 9
0
 /**
  * Get the number of child records belonging to this record
  *
  * @return int Number of records
  */
 public function getChildRecordCount()
 {
     // Shortcut: if this record is not the top record, let's not find out the
     // count. This assumes that contained records cannot contain more records.
     if (!$this->containerLinking || empty($this->fields['is_hierarchy_id']) || null === $this->searchService) {
         return 0;
     }
     $safeId = addcslashes($this->fields['is_hierarchy_id'], '"');
     $query = new \VuFindSearch\Query\Query('hierarchy_parent_id:"' . $safeId . '"');
     return $this->searchService->search('Solr', $query, 0, 0)->getTotal();
 }
Exemplo n.º 10
0
 protected function convertToIDUsingSolr(&$ids)
 {
     if (empty($ids)) {
         return array();
     }
     $results = array();
     $group = new \VuFindSearch\Query\QueryGroup('OR');
     foreach ($ids as $id) {
         $query = new \VuFindSearch\Query\Query($this->solrQueryField . ':' . $id);
         $group->addQuery($query);
     }
     if (isset($this->prefix)) {
         $idPrefixQuery = new \VuFindSearch\Query\Query('id:' . $this->prefix . '*');
         $group = new \VuFindSearch\Query\QueryGroup('AND', [$idPrefixQuery, $group]);
     }
     $params = new \VuFindSearch\ParamBag(['disableDedup' => TRUE]);
     $docs = $this->searchService->search('Solr', $group, 0, sizeof($ids), $params);
     foreach ($docs->getRecords() as $record) {
         $fields = $record->getRawData();
         if (isset($fields[$this->solrQueryField])) {
             if (is_array($fields[$this->solrQueryField])) {
                 foreach ($fields[$this->solrQueryField] as $value) {
                     if (in_array($value, $ids)) {
                         $results[$value] = $this->getId($record);
                     }
                 }
             } else {
                 $value = $fields[$this->solrQueryField];
                 if (in_array($value, $ids)) {
                     $results[$value] = $this->getId($record);
                 }
             }
         }
     }
     return $results;
 }
Exemplo n.º 11
0
 /**
  * Given an array of IDs and a record source, load a batch of records for
  * that source.
  *
  * @param array  $ids    Record IDs
  * @param string $source Record source
  *
  * @throws \Exception
  * @return array
  */
 public function loadBatchForSource($ids, $source = 'VuFind')
 {
     return $this->searchService->retrieveBatch($source, $ids)->getRecords();
 }
Exemplo n.º 12
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)
 {
     $this->results = $this->searchService->similar('Solr', $driver->getUniqueId());
 }