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; }
/** * 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(['fq' => $this->filters, 'hl' => 'false'])); if ($results->getTotal() < 1) { return ''; } $json = []; $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 = ['id' => $current->getUniqueID(), 'type' => $current->isCollection() ? 'collection' : 'record', 'title' => $title]; 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[] = [$sequence, $childNode]; } else { $json[] = $childNode; } } return $sorting ? $this->sortNodes($json) : $json; }
/** * 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; }
/** * 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(); }
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; }