| 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 |
| 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) { |
| 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; |
| 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] ++; |
| 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'); |
| 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 |
} |
} |
| 311 |
} |
} |
| 312 |
} |
} |
| 313 |
|
|
|
|
|
| 314 |
/** |
/** |
| 315 |
* Implementation of hook_form_alter(). |
* Implementation of hook_form_alter(). |
| 316 |
*/ |
*/ |
| 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 |