public function logSearch($module, Query $query, ResultSet $results) { $term = $query->getQueryTerm(0); $params = array(); $params[':ip_address'] = $query->getUser()->getIpAddress(); $params[':module'] = $module; $params[':field'] = $term->field; $params[':phrase'] = substr($term->phrase, 0, 999); $params[':hits'] = $results->getTotal(); $sql = 'INSERT INTO xerxes_search_stats ' . '( ip_address, stamp, module, field, phrase, hits ) ' . 'VALUES (:ip_address, NOW(), :module, :field, :phrase, :hits)'; $this->insert($sql, $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); }