Example #1
0
 protected function newQuery($options)
 {
     $institution = $options->get('institution', config('app.primo.institution'));
     $scope = $options->get('scope', config('app.primo.default_scope'));
     $queryObj = new Query($institution);
     $queryObj->local($scope);
     $queryObj->onCampus(true);
     if ($options->has('institution')) {
         $queryTerm = new QueryTerm();
         $queryTerm->set('facet_local4', QueryTerm::EXACT, $options->get('institution'));
         $queryObj->addTerm($queryTerm);
     }
     if ($options->has('library')) {
         $library = explode(',', $options->get('library'));
         $queryTerm = new QueryTerm();
         $queryTerm->set('facet_library', QueryTerm::EXACT, $library);
         $queryObj->includeTerm($queryTerm);
     }
     if ($options->has('material')) {
         $queryTerm = new QueryTerm();
         /**
          * This is really weird, but using
          *
          *    $queryTerm->set('rtype',
          *       QueryTerm::EXACT,
          *       explode(',', $options->get('material'))
          *    );
          *
          * sometimes resulted in fewer results than expected. E.g. for the
          * search "field theories Eduardo" with "rtype,exact,print-books",
          * I got 3 results rather than the expected 4. Using "facet_rtype"
          * seems to work better.
          */
         $queryTerm->set('facet_rtype', QueryTerm::EXACT, explode(',', $options->get('material')));
         $queryObj->includeTerm($queryTerm);
     }
     $start = $options->get('start', 1);
     $limit = $options->get('limit', 10);
     $sort = $options->get('sort', 'relevance');
     if ($sort != 'relevance') {
         $queryObj->sortField($sort);
     }
     $queryObj->start($start)->bulkSize($limit);
     return $queryObj;
 }