Example #1
0
 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);
 }
Example #2
0
 public function getUrl(Query $query)
 {
     $term = $query->getQueryTerm(0);
     $phrase = $term->phrase;
     switch ($term->field) {
         case "title":
             $phrase = "t:({$phrase})";
             break;
         case "subject":
             $phrase = "s:({$phrase})";
             break;
         case "author":
             $phrase = "a:({$phrase})";
             break;
     }
     $url = $this->server . "search/?searchtype=X&searcharg=" . urlencode($phrase);
     return $url;
 }
Example #3
0
 /**
  * Do the actual search and return results
  *
  * @param Query $search  search object
  * @param int $start     [optional] starting record number
  * @param int $max       [optional] max records
  * @param string $sort   [optional] sort order
  * @param bool $facets   [optional] whether to include facets
  *
  * @return Results
  */
 protected function doSearch(Search\Query $search, $start = 1, $max = 10, $sort = "", $facets = true)
 {
     $username = $search->getQueryTerm(0)->phrase;
     $label = $search->getLimit("label");
     $format = $search->getLimit("format");
     $results = new Search\ResultSet($this->config);
     $results->total = $this->datamap->totalRecords($username, $label->value, $format->value);
     // just the hit count please
     if ($max == 0) {
         return $results;
     }
     // no we want actual records too
     $records = array();
     if ($label->value != "") {
         $records = $this->datamap->getRecordsByLabel($username, $label->value, $sort, $start, $max);
     } elseif ($format->value != "") {
         $records = $this->datamap->getRecordsByFormat($username, $format->value, $sort, $start, $max);
     } else {
         $records = $this->datamap->getRecords($username, null, $sort, $start, $max);
     }
     // convert them into our model
     foreach ($records as $record) {
         $result = $this->createSearchResult($record);
         $results->addResult($result);
     }
     // facets
     $facets = new Search\Facets();
     // formats
     $formats = $this->datamap->getFormats($username);
     if (count($formats) > 0) {
         $group = new Search\FacetGroup();
         $group->name = "format";
         $group->public = "Formats";
         // @todo: i18n this?
         foreach ($formats as $format) {
             $facet = new Search\Facet();
             $facet->name = $format->format;
             $facet->count = $format->total;
             $group->addFacet($facet);
         }
         $facets->addGroup($group);
     }
     // labels
     $tags = $this->datamap->getTags($username);
     if (count($tags) > 0) {
         $group = new Search\FacetGroup();
         $group->name = "label";
         $group->public = "Labels";
         // @todo: i18n this?
         foreach ($tags as $tag) {
             $facet = new Search\Facet();
             $facet->name = $tag->label;
             $facet->count = $tag->total;
             $group->addFacet($facet);
         }
         $facets->addGroup($group);
     }
     $results->setFacets($facets);
     return $results;
 }