Example #1
0
 /**
  * Set up filters based on VuFind settings.
  *
  * @param ParamBag $params     Parameter collection to update
  *
  * @return void
  */
 public function createBackendFilterParameters(ParamBag $params)
 {
     // flag our non-Standard checkbox filters:
     $foundIncludeNewspapers = false;
     # includeNewspapers
     $foundIncludeWithoutFulltext = false;
     # includeWithoutFulltext
     $filterList = $this->getFilterList();
     // Which filters should be applied to our query?
     if (!empty($filterList)) {
         // Loop through all filters and add appropriate values to request:
         foreach ($filterList as $filterArray) {
             foreach ($filterArray as $filt) {
                 $safeValue = SummonQuery::escapeParam($filt['value']);
                 if ($filt['field'] == 'holdingsOnly') {
                     // Special case -- "holdings only" is a separate parameter from
                     // other facets.
                     $params->set('holdings', strtolower(trim($safeValue)) == 'true');
                 } else {
                     if ($filt['field'] == 'excludeNewspapers') {
                         // support a checkbox for excluding newspapers:
                         // this is now the default behaviour.
                     } else {
                         if ($filt['field'] == 'includeNewspapers') {
                             // explicitly include newspaper articles
                             $foundIncludeNewspapers = true;
                         } else {
                             if ($range = SolrUtils::parseRange($filt['value'])) {
                                 // Special case -- range query (translate [x TO y] syntax):
                                 $from = SummonQuery::escapeParam($range['from']);
                                 $to = SummonQuery::escapeParam($range['to']);
                                 $params->add('rangeFilters', "PublicationDate,{$from}:{$to}");
                             } else {
                                 if ($filt['field'] == 'includeWithoutFulltext') {
                                     $foundIncludeWithoutFulltext = true;
                                 } else {
                                     // Standard case:
                                     $params->add('filters', "{$filt['field']},{$safeValue}");
                                 }
                             }
                         }
                     }
                 }
             }
         }
     }
     // special cases (apply also when filter list is empty)
     // newspaper articles
     if (!$foundIncludeNewspapers) {
         // this actually means: do *not* show newspaper articles
         $params->add('filters', "ContentType,Newspaper Article,true");
     }
     // combined facet "with holdings/with fulltext"
     if (!$foundIncludeWithoutFulltext) {
         $params->set('holdings', true);
         $params->add('filters', 'IsFullText,true');
     } else {
         $params->set('holdings', false);
     }
 }
Example #2
0
 /**
  * Set up filters based on VuFind settings.
  *
  * @param ParamBag $params Parameter collection to update
  *
  * @return void
  */
 public function createBackendFilterParameters(ParamBag $params)
 {
     // Which filters should be applied to our query?
     $filterList = $this->getFilterList();
     if (!empty($filterList)) {
         $orFacets = [];
         // Loop through all filters and add appropriate values to request:
         foreach ($filterList as $filterArray) {
             foreach ($filterArray as $filt) {
                 $safeValue = SummonQuery::escapeParam($filt['value']);
                 // Special case -- "holdings only" is a separate parameter from
                 // other facets.
                 if ($filt['field'] == 'holdingsOnly') {
                     $params->set('holdings', strtolower(trim($safeValue)) == 'true');
                 } else {
                     if ($filt['field'] == 'queryExpansion') {
                         // Special case -- "query expansion" is a separate parameter
                         // from other facets.
                         $params->set('expand', strtolower(trim($safeValue)) == 'true');
                     } else {
                         if ($filt['field'] == 'excludeNewspapers') {
                             // Special case -- support a checkbox for excluding
                             // newspapers:
                             $params->add('filters', "ContentType,Newspaper Article,true");
                         } else {
                             if ($range = SolrUtils::parseRange($filt['value'])) {
                                 // Special case -- range query (translate [x TO y] syntax):
                                 $from = SummonQuery::escapeParam($range['from']);
                                 $to = SummonQuery::escapeParam($range['to']);
                                 $params->add('rangeFilters', "{$filt['field']},{$from}:{$to}");
                             } else {
                                 if ($filt['operator'] == 'OR') {
                                     // Special case -- OR facets:
                                     $orFacets[$filt['field']] = isset($orFacets[$filt['field']]) ? $orFacets[$filt['field']] : [];
                                     $orFacets[$filt['field']][] = $safeValue;
                                 } else {
                                     // Standard case:
                                     $fq = "{$filt['field']},{$safeValue}";
                                     if ($filt['operator'] == 'NOT') {
                                         $fq .= ',true';
                                     }
                                     $params->add('filters', $fq);
                                 }
                             }
                         }
                     }
                 }
             }
             // Deal with OR facets:
             foreach ($orFacets as $field => $values) {
                 $params->add('groupFilters', $field . ',or,' . implode(',', $values));
             }
         }
     }
 }
Example #3
0
 /**
  * Constructor
  *
  * Sets up the Summon API Client
  *
  * @param string $query   Search query
  * @param array  $options Other options to set (associative array)
  */
 public function __construct($query = null, $options = array())
 {
     parent::__construct($query, $options);
     $this->config = ConfigReader::getConfig('Summon');
 }
Example #4
0
 /**
  * Execute a search.
  *
  * @param SerialsSolutions_Summon_Query $query     Query object
  * @param bool                          $returnErr On fatal error, should we fail
  * outright (false) or treat it as an empty result set with an error key set
  * (true)?
  *
  * @return array             An array of query results
  */
 public function query($query, $returnErr = false)
 {
     // Query String Parameters
     $options = $query->getOptionsArray();
     $options['s.role'] = $this->authedUser ? 'authenticated' : 'none';
     // Special case -- if user filtered down to newspapers AND excluded them,
     // we can't possibly have any results:
     if (isset($options['s.fvf']) && is_array($options['s.fvf']) && in_array('ContentType,Newspaper Article,true', $options['s.fvf']) && in_array('ContentType,Newspaper Article', $options['s.fvf'])) {
         return array('recordCount' => 0, 'documents' => array());
     }
     $this->debugPrint('Query: ' . print_r($options, true));
     try {
         $result = $this->call($options);
     } catch (SerialsSolutions_Summon_Exception $e) {
         if ($returnErr) {
             return array('recordCount' => 0, 'documents' => array(), 'errors' => $e->getMessage());
         } else {
             $this->handleFatalError($e);
         }
     }
     return $result;
 }