Esempio n. 1
0
 public function getHitCount($aim25sid, $query)
 {
     $hits = array();
     if (!is_null($aim25sid)) {
         // should have hits stored away - no need to rerun
         $hits['hits'] = $this->cache()->get('hits_' . $aim25sid);
         $hits['url'] = $this->cache()->get('url_' . $aim25sid);
         $hits['session'] = $this->cache()->get('sid_' . $aim25sid);
     } else {
         $params = $query->getAllSearchParams();
         // the aim25 web search doesn't do Z39.50, so we need
         // to approximate as best we can
         if ($params['field'] == 'keyword' || $params['field'] == 'title' || $params['field'] == 'author') {
             $querystring = 'zany2?term1=' . urlencode($params['query']);
         } else {
             if ($params['field'] == 'subject') {
                 $querystring = 'zub2?term1=' . urlencode($params['query']);
             } else {
                 // we don't handle isbn etc
                 $hits['hits'] = 0;
                 return $hits;
             }
         }
         $url = $this->conf()->getConfig('AIM25_HTTPURL', false);
         $url .= $querystring;
         $hits['url'] = $url;
         // initialize without calling initializePazpar2Client()
         // as we don't want this client to overwrite the cached one
         $client = new Pazpar2($this->conf()->getConfig('url', true), false, null, $this->client);
         $aim25sid = $client->getSessionId();
         $hits['session'] = $aim25sid;
         // blocking (synchronous) call to pz2 search
         $zurl = $this->conf()->getConfig('AIM25_ZURL', false);
         $res = $client->search($query->toQuery(), array($zurl), null, null, true);
         $hits['hits'] = $res[$zurl]['records'];
         // cache so we don't need to rerun next time
         $this->cache()->set('hits_' . $aim25sid, $hits['hits']);
         $this->cache()->set('url_' . $aim25sid, $hits['url']);
         $this->cache()->set('sid_' . $aim25sid, $hits['session']);
     }
     return $hits;
 }
Esempio n. 2
0
 /**
  * Initialize a pazpar2 client, save to cache, and return id for retrieval
  *
  */
 public function initializePazpar2Client()
 {
     $client = new Pazpar2($this->conf()->getConfig('url', true), false, null, $this->client);
     $this->cache()->set($client->getSessionId(), serialize($client));
     $this->client = $client;
     return $this->client->getSessionId();
 }