示例#1
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;
 }
示例#2
0
 /**
  * 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);
 }