/** * Retrieve a batch of documents. * * @param array $ids Array of document identifiers * @param ParamBag $params Search backend parameters * * @return RecordCollectionInterface */ public function retrieveBatch($ids, ParamBag $params = null) { // Load 100 records at a time; this is a good number to avoid memory // problems while still covering a lot of ground. $pageSize = 100; // Callback function for formatting IDs: $formatIds = function ($i) { return '"' . addcslashes($i, '"') . '"'; }; // Retrieve records a page at a time: $results = false; while (count($ids) > 0) { $currentPage = array_splice($ids, 0, $pageSize, []); $currentPage = array_map($formatIds, $currentPage); $params = new ParamBag(['q' => 'id:(' . implode(' OR ', $currentPage) . ')', 'start' => 0, 'rows' => $pageSize]); $this->injectResponseWriter($params); $next = $this->createRecordCollection($this->connector->search($params)); if (!$results) { $results = $next; } else { foreach ($next->getRecords() as $record) { $results->add($record); } } } $this->injectSourceIdentifier($results); return $results; }
/** * Perform a search with clean params * * @param ParamBag $paramBag The params you'd normally send to solr * * @return json */ protected function search($paramBag) { // Remove global filters from the Solr connector $map = $this->solr->getMap(); $params = $map->getParameters('select', 'appends'); $map->setParameters('select', 'appends', []); // Turn off grouping $paramBag->set('group', 'false'); $paramBag->add('wt', 'json'); // Search $response = $this->solr->search($paramBag); // Reapply the global filters $map->setParameters('select', 'appends', $params->getArrayCopy()); return $response; }
/** * Search Solr. * * @param string $q Search query * @param int $rows Max rows to retrieve (default = int max) * * @return array */ protected function searchSolr($q, $rows = 2147483647) { $params = new ParamBag(['q' => [$q], 'fq' => $this->filters, 'hl' => ['false'], 'fl' => ['title,id,hierarchy_parent_id,hierarchy_top_id,' . 'is_hierarchy_id,hierarchy_sequence,title_in_hierarchy'], 'wt' => ['json'], 'json.nl' => ['arrarr'], 'rows' => [$rows], 'start' => [0]]); $response = $this->solrConnector->search($params); return json_decode($response); }