/** * Add links to the query object limits * * @param Query $query */ public function addQueryLinks(Query $query) { // we have to pass in the query object here rather than take // the property above because adding the links doesn't seem // to reflect back in the main object, even though they should // be references, maybe because limit objects are in an array? // search option links $search = $this->registry->getConfig('search'); if ($search instanceof \SimpleXMLElement) { $controller_map = $this->request->getControllerMap(); foreach ($search->xpath("//option") as $option) { // format the number // is this the current tab? if ($controller_map->getControllerName() == (string) $option["id"] && ($this->request->getParam('source') == (string) $option["source"] || (string) $option["source"] == '')) { $option->addAttribute('current', "1"); } // url $params = $query->extractSearchParams(); $params['controller'] = $controller_map->getUrlAlias((string) $option["id"]); $params['action'] = "results"; $params['source'] = (string) $option["source"]; $url = $this->request->url_for($params); $option->addAttribute('url', $url); // cached search hit count? foreach ($this->request->getAllSessionData() as $session_id => $session_value) { // does this value in the cache have the save id as our tab? $id = str_replace("_" . $query->getHash(), "", $session_id); if ($id == (string) $option["id"]) { // yup, so add it $option->addAttribute('hits', Parser::number_format($session_value)); } } } $this->registry->setConfig('search', $search); } // links to remove facets foreach ($query->getLimits() as $limit) { $params = $this->currentParams(); $params = Parser::removeFromArray($params, $limit->field, $limit->value); $limit->remove_url = $this->request->url_for($params); } }
/** * Do the actual search * * @param Query $search search object * @param int $start [optional] starting record number * @param int $max [optional] max records * @param string $sort [optional] sort order * * @return Results */ protected function doSearch(Search\Query $search, $start = 1, $max = 10, $sort = "") { // limit to local users? if ($search->getUser()->isAuthorized()) { $this->summon_client->setToAuthenticated(); } // prepare the query $query = $search->toQuery(); // facets to include in the response foreach ($this->config->getFacets() as $facet_config) { if ($facet_config['type'] == 'date') { $this->summon_client->setDateRangesToInclude((string) $facet_config["ranges"]); } else { $this->summon_client->includeFacet((string) $facet_config["internal"] . ",or,1," . (string) $facet_config["max"]); } } // limit to local holdings unless told otherwise if ($this->config->getConfig('LIMIT_TO_HOLDINGS', false)) { $this->summon_client->limitToHoldings(); } // limits foreach ($search->getLimits(true) as $limit) { if ($limit->field == 'newspapers') { continue; // we'll handle you later } // holdings only if ($limit->field == 'holdings') { if ($limit->value == 'false') { // this is actually an expander to search everything $this->summon_client->limitToHoldings(false); } else { $this->summon_client->limitToHoldings(); } } elseif ($this->config->getFacetType($limit->field) == 'date') { // @todo: make this not 'display' if ($limit->value == 'start' && $limit->display != '') { $this->summon_client->setStartDate($limit->display); } elseif ($limit->value == 'end' && $limit->display != '') { $this->summon_client->setEndDate($limit->display); } } else { $value = ''; $boolean = 'false'; if ($limit->boolean == "NOT") { $boolean = 'true'; } // multi-select filter if (is_array($limit->value)) { // exclude if ($boolean == 'true') { foreach ($limit->value as $limited) { $value = str_replace(',', '\\,', $limited); $this->summon_client->addFilter($limit->field . ",{$value},{$boolean}"); } } else { foreach ($limit->value as $limited) { $value .= ',' . str_replace(',', '\\,', $limited); } $this->summon_client->addComplexFilter($limit->field . ',' . $boolean . $value); } } else { $value = str_replace(',', '\\,', $limit->value); $this->summon_client->addFilter($limit->field . ",{$value},{$boolean}"); } } } // format filters // newspapers are a special case, i.e., they can be optional if ($this->config->getConfig('NEWSPAPERS_OPTIONAL', false)) { $news_limit = $search->getLimit('facet.newspapers'); if ($news_limit->value != 'true') { $this->formats_exclude[] = 'Newspaper Article'; } } // always exclude these foreach ($this->formats_exclude as $format) { $this->summon_client->addFilter("ContentType,{$format},true"); } // summon deals in pages, not start record number if ($max > 0) { $page = ceil($start / $max); } else { $page = 1; } // get the results $summon_results = $this->summon_client->query($query, $page, $max, $sort); return $this->parseResponse($summon_results); }
/** * Add links to the query object limits * * @param Query $query */ public function addQueryLinks(Query $query) { // we have to pass in the query object here rather than take // the property above because adding the links doesn't seem // to reflect back in the main object, even though they should // be references, maybe because limit objects are in an array? // search option links $search = $this->registry->getConfig('search'); if ($search instanceof \SimpleXMLElement) { $controller_map = $this->request->getControllerMap(); foreach ($search->xpath("//option") as $option) { $id = (string) $option["id"]; if ((string) $option["source"] != '') { $id .= '_' . (string) $option["source"]; } $id .= '_' . $this->query->getHash(); // is this the current tab? if ($controller_map->getControllerName() == (string) $option["id"] && ($this->request->getParam('source') == (string) $option["source"] || (string) $option["source"] == '')) { // mark as current $option->addAttribute('current', "1"); // keep the current url, too, minus the start # $params = $this->request->getParams(); $params['start'] = null; $this->request->setSessionData("url-{$id}", $this->request->url_for($params)); } // url $url = $this->request->getSessionData("url-{$id}"); // already cached, so use it if ($url == null) { $params = $query->extractSearchParams(); $params['controller'] = $controller_map->getUrlAlias((string) $option["id"]); $params['action'] = "results"; $params['source'] = (string) $option["source"]; $params['sort'] = $this->request->getParam('sort'); $url = $this->request->url_for($params); } $option->addAttribute('url', $url); // cached search hit count? $session_hits = $this->request->getSessionData($id); if ($session_hits != null) { $option->addAttribute('hits', Parser::number_format($session_hits)); } } $this->registry->setConfig('search', $search); } // links to remove facets foreach ($query->getLimits() as $limit) { $params = $this->currentParams(); // urlencode here necessary to support the urlencode above on 'key' urls $params = Parser::removeFromArray($params, urlencode($limit->field), $limit->value); $limit->remove_url = $this->request->url_for($params); } }
/** * Do the actual search * * @param Query $search search object * @param int $start [optional] starting record number * @param int $max [optional] max records * @param string $sort [optional] sort order * * @return Results */ protected function doSearch(Search\Query $search, $start = 1, $max = 10, $sort = "") { // prepare the query $query = $search->toQuery(); // facets to include in the response $facets_to_include = array(); foreach ($this->config->getFacets() as $facet_config) { $facets_to_include[(string) $facet_config["internal"]] = (string) $facet_config["internal"] . ",or,1," . (string) $facet_config["max"]; } // limits $facets = array(); foreach ($search->getLimits(true) as $limit) { // remove chosen facet from response // @todo: make multi-value facets selectable $facets_to_include = Parser::removeFromArray($facets_to_include, $limit->field); array_push($facets, $limit->field . "," . str_replace(',', '\\,', $limit->value) . ",false"); } // set actual response facets $this->summon_client->setFacetsToInclude($facets_to_include); // filter out formats foreach ($this->formats_exclude as $format) { array_push($facets, "ContentType,{$format},true"); } // holdings only if ($search->isHoldingsOnly()) { $this->summon_client->limitToHoldings(); } // summon deals in pages, not start record number if ($max > 0) { $page = ceil($start / $max); } else { $page = 1; } // get the results $summon_results = $this->summon_client->query($query, $facets, $page, $max, $sort); return $this->parseResponse($summon_results); }
/** * Add links to the query object limits * * @param Query $query */ public function addQueryLinks(Query $query) { // we have to pass in the query object here rather than take // the property above because adding the links doesn't seem // to reflect back in the main object, even though they should // be references, maybe because limit objects are in an array? // add current query to query object itself $params = $query->extractSearchParams(); $params['controller'] = $this->request->getParam('controller'); $params['action'] = 'search'; $params['source'] = $this->request->getParam('source'); $params['sort'] = $this->request->getParam('sort'); // url $query->url = $this->request->url_for($params); // query only $query->url_query = Parser::removeLeft($query->url, '?'); // advanced search $params['action'] = 'advanced'; $query->url_advanced = $this->request->url_for($params); // search option links $search = $this->registry->getConfig('search'); if ($search instanceof \SimpleXMLElement) { $controller_map = $this->request->getControllerMap(); // combined results $combined = $controller_map->getUrlAlias('combined'); $combined_id = $combined . '_' . $query->getHash(); if ($this->request->getSessionData($combined_id) != null) { $params = $query->extractSearchParams(); $params['controller'] = $combined; $params['action'] = "results"; $search->combined_url = $this->request->url_for($params); } // individual search options foreach ($search->xpath("//option") as $option) { $id = (string) $option["id"]; if ((string) $option["source"] != '') { $id .= '_' . (string) $option["source"]; } $id .= '_' . $this->query->getHash(); // format the number // is this the current tab? if ($this->request->getControllerName() == (string) $option["id"] && ($this->request->getParam('source') == (string) $option["source"] || (string) $option["source"] == '')) { // mark as current $option->addAttribute('current', "1"); } // create url based on the search terms only! $params = $query->extractSearchParams(); $params['controller'] = $controller_map->getUrlAlias((string) $option["id"]); $params['action'] = "results"; $params['source'] = (string) $option["source"]; $params['sort'] = $this->request->getParam('sort'); // results url $url = $this->request->url_for($params); $option->addAttribute('url', $url); // hits url $params['action'] = 'hits'; $url = $this->request->url_for($params); $option->addAttribute('url_hits', $url); // cached search hit count? foreach ($this->request->getAllSessionData() as $session_id => $session_value) { // does this value in the cache have the save id as our tab? $id = str_replace("_" . $query->getHash(), "", $session_id); if ($id == (string) $option["id"]) { // yup, so add it $option->addAttribute('hits', Parser::number_format($session_value)); } } } // header('Content-type: text/xml'); echo $search->asXML(); exit; $this->registry->setConfig('search', $search); } // links to remove facets foreach ($query->getLimits() as $limit) { $params = $this->currentParams(); $value = $limit->value; if ($limit->display != "") { $value = $limit->display; } // urlencode here necessary to support the urlencode above on 'key' urls $params = Parser::removeFromArray($params, urlencode($limit->param), $value); $limit->remove_url = $this->request->url_for($params); } }