/** * 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; }
/** * Obtain information from an alphabetic browse index. * * @param string $source Name of index to search * @param string $from Starting point for browse results * @param int $page Result page to return (starts at 0) * @param int $limit Number of results to return on each page * @param ParamBag $params Additional parameters * POST) * @param int $offsetDelta Delta to use when calculating page * offset (useful for showing a few results above the highlighted row) * * @return array */ public function alphabeticBrowse($source, $from, $page, $limit = 20, $params = null, $offsetDelta = 0) { $params = $params ?: new ParamBag(); $this->injectResponseWriter($params); $params->set('from', $from); $params->set('offset', $page * $limit + $offsetDelta); $params->set('rows', $limit); $params->set('source', $source); try { $response = $this->connector->query('browse', $params); } catch (RemoteErrorException $e) { $this->refineBrowseException($e); } return $this->deserialize($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); }
/** * Create the SOLR connector. * * @return Connector */ protected function createConnector() { $config = $this->config->get('config'); $handlers = ['select' => ['fallback' => true, 'defaults' => ['fl' => '*,score'], 'appends' => ['fq' => []]], 'term' => ['functions' => ['terms']]]; foreach ($this->getHiddenFilters() as $filter) { array_push($handlers['select']['appends']['fq'], $filter); } $connector = new Connector($this->getSolrUrl(), new HandlerMap($handlers), $this->uniqueKey); $connector->setTimeout(isset($config->Index->timeout) ? $config->Index->timeout : 30); if ($this->logger) { $connector->setLogger($this->logger); } if ($this->serviceLocator->has('VuFind\\Http')) { $connector->setProxy($this->serviceLocator->get('VuFind\\Http')); } return $connector; }
/** * Create connector with fixture file. * * @param string $fixture Fixture file * * @return Connector * * @throws InvalidArgumentException Fixture file does not exist */ protected function createConnector($fixture = null) { if ($fixture) { $file = realpath(sprintf('%s/solr/response/%s', PHPUNIT_SEARCH_FIXTURES, $fixture)); if (!is_string($file) || !file_exists($file) || !is_readable($file)) { throw new InvalidArgumentException(sprintf('Unable to load fixture file: %s', $file)); } $this->response = file_get_contents($file); } $map = new HandlerMap(['select' => ['fallback' => true]]); $conn = new Connector('http://example.tld/', $map); $conn->setProxy($this); return $conn; }
/** * Extract the Solr core from a connector's URL. * * @param Connector $connector Solr connector * * @return string */ protected function getCore(Connector $connector) { $url = rtrim($connector->getUrl(), '/'); $parts = explode('/', $url); return array_pop($parts); }