/[drupal]/contributions/modules/z3950/z3950.module
ViewVC logotype

Diff of /contributions/modules/z3950/z3950.module

Parent Directory Parent Directory | Revision Log Revision Log | View Revision Graph Revision Graph | View Patch Patch

revision 1.2.2.5, Sat Sep 1 19:56:54 2007 UTC revision 1.2.2.6, Sun Sep 2 11:27:16 2007 UTC
# Line 1  Line 1 
1  <?php  <?php
2  /* $Id: z3950.module,v 1.2.2.4 2007/09/01 19:52:29 douggreen Exp $ */  /* $Id: z3950.module,v 1.2.2.5 2007/09/01 19:56:54 douggreen Exp $ */
3    
4  /**  /**
5   * @file   * @file
# Line 165  function _z3950_search($keys) { Line 165  function _z3950_search($keys) {
165        'au'  => '1=1', // author        'au'  => '1=1', // author
166      );      );
167    
168        // replace the Drupal keys types with the equivalent CCL command
169        $keys = preg_replace('/(au|author):/', 'au=', $keys);
170        $keys = preg_replace('/(ti|title):/', 'ti=', $keys);
171    
172      // setup the YAZ search on each server      // setup the YAZ search on each server
173      $ids = array();      $ids = array();
174      foreach ($servers as $server_index => $server) {      foreach ($servers as $server_index => $server) {
# Line 208  function _z3950_search($keys) { Line 212  function _z3950_search($keys) {
212            // check for error and get number of 'hits' (results) from this server            // check for error and get number of 'hits' (results) from this server
213            $error = yaz_error($id);            $error = yaz_error($id);
214            if (empty($error)) {            if (empty($error)) {
215              $server_hits[$server_index] = yaz_hits($id);              $hits = yaz_hits($id);
216    
217              // if this server has any results              // if this server has any results
218              if (!empty($server_hits[$server_index])) {              if (!empty($hits)) {
219                // keep track of total number of hits, for use in the pager                // keep track of total number of hits, for use in the pager
220                $total_hits += $server_hits[$server_index];                $server_hits[$server_index] = $hits;
221                  $total_hits += $hits;
222    
223                // set the starting position                // set the starting position
224                $server_pos[$server_index] = 1;                $server_pos[$server_index] = 1;
# Line 241  function _z3950_search($keys) { Line 246  function _z3950_search($keys) {
246            $total_pos = pager_init(10, 0, $total_hits);            $total_pos = pager_init(10, 0, $total_hits);
247            $total_per_server = $total_pos / count($ids);            $total_per_server = $total_pos / count($ids);
248    
249              // display total matches when there are more than fit on one page
250              if ($total_hits > 10) {
251                drupal_set_message(t('%hits matches found', array('%hits' => $total_hits)));
252              }
253    
254            // initialize the current position in each server            // initialize the current position in each server
255            // @TODO: there's a faster way to do this, this is just the easy way!            // @TODO: there's a faster way to do this, this is just the easy way!
256            // @TODO: test this around the edge cases, is it losing any results?            // @TODO: test this around the edge cases, is it losing any results?
257            while ($total_pos > 1) {            while ($total_pos > 0) {
258              foreach ($ids as $server_index => $id) {              foreach ($ids as $server_index => $id) {
259                if ($server_pos[$server_index] < $server_hits[$server_index]) {                if ($server_pos[$server_index] < $server_hits[$server_index]) {
260                  $server_pos[$server_index] ++;                  $server_pos[$server_index] ++;
# Line 256  function _z3950_search($keys) { Line 266  function _z3950_search($keys) {
266            // process results from search server, evenly mixing results from each server            // process results from search server, evenly mixing results from each server
267            $limit = min($total_hits, 10);            $limit = min($total_hits, 10);
268            $find = array();            $find = array();
269            while (count($find) <= $limit) {            while (count($find) < $limit && count($server_hits) > 0) {
270              foreach ($ids as $server_index => $id) {              foreach ($ids as $server_index => $id) {
271                // loop through the results from this server                // loop through the results from this server
272                if ($server_pos[$server_index] < $server_hits[$server_index]) {                if (!empty($server_hits[$server_index])) {
273                  // store the position in a scalar variable to make code easier to read                  // store the position in a scalar variable to make code easier to read
274                  $pos = $server_pos[$server_index];                  $pos = $server_pos[$server_index] ++;
275    
276                    // when all records from this server are retrieved, remove it from the array
277                    if ($pos >= $server_hits[$server_index]) {
278                      unset($server_hits[$server_index]);
279                    }
280    
281                  // store the database name for use in the source string below                  // store the database name for use in the source string below
282                  $rec_database = yaz_record($id, $pos, 'database');                  $rec_database = yaz_record($id, $pos, 'database');
# Line 283  function _z3950_search($keys) { Line 298  function _z3950_search($keys) {
298    
299                    // save this summary, and don't process it again                    // save this summary, and don't process it again
300                    $find[] = $summary;                    $find[] = $summary;
                   $server_pos[$server_index] ++;  
301                  }                  }
302                }                }
303              }              }
304                if ($process == 0) {
305                }
306            }            }
307            return $find;            return $find;
308          }          }
# Line 295  function _z3950_search($keys) { Line 311  function _z3950_search($keys) {
311    }    }
312  }  }
313    
   
314  /**  /**
315   * Implementation of hook_form_alter().   * Implementation of hook_form_alter().
316   */   */
# Line 331  function z3950_form_alter($form_id, &$fo Line 346  function z3950_form_alter($form_id, &$fo
346      }      }
347    
348      // add help text to the basic form      // add help text to the basic form
349      $form['basic']['#description'] = t('enter the z39.50 search query (<A HREF="@url">see also</A>) and select the servers to search', array('@url' => 'http://www.indexdata.dk/yaz/doc/tools.tkl#CCL'));      $form['basic']['#description'] = t('enter the z39.50 search query.  You may use the CCL qualifiers au (or author) and ti (or title).  For example, <i>author:buber, martin</i> or <i>au:buber and ti:thou</i> are valid searches (<A HREF="@url">see also</A>).', array('@url' => 'http://www.indexdata.dk/yaz/doc/tools.tkl#CCL'));
350    
351      // add advanced form      // add advanced form
352      // @TODO      // @TODO

Legend:
Removed from v.1.2.2.5  
changed lines
  Added in v.1.2.2.6

  ViewVC Help
Powered by ViewVC 1.1.2