function tripal_pub_remote_search_PMID
2.x tripal_pub.PMID.inc | tripal_pub_remote_search_PMID($search_array, $num_to_retrieve, $page) |
3.x tripal_chado.pub_importer_PMID.inc | tripal_pub_remote_search_PMID($search_array, $num_to_retrieve, |
1.x PMID.inc | tripal_pub_remote_search_PMID($search_array, $num_to_retrieve, $pager_id) |
File
- tripal_pub/
includes/ importers/ PMID.inc, line 41 - Tripal Pub PubMed Interface
Code
function tripal_pub_remote_search_PMID($search_array, $num_to_retrieve, $pager_id) {
// convert the terms list provicded by the caller into a string with words
// separated by a '+' symbol.
$num_criteria = $search_array['num_criteria'];
$days = $search_array['days'];
$search_str = '';
for ($i = 1; $i <= $num_criteria; $i++) {
$search_terms = trim($search_array['criteria'][$i]['search_terms']);
$scope = $search_array['criteria'][$i]['scope'];
$is_phrase = $search_array['criteria'][$i]['is_phrase'];
$op = $search_array['criteria'][$i]['operation'];
if ($op) {
$search_str .= "$op ";
}
// if this is phrase make sure the search terms are surrounded by quotes
if ($is_phrase) {
$search_str .= "(\"$search_terms\" |SCOPE|) ";
}
// if this is not a phase then we want to separate each 'OR or 'AND' into a unique criteria
else {
$search_str .= "(";
if (preg_match('/and/i', $search_terms)) {
$elements = preg_split('/\s+and+\s/i', $search_terms);
foreach ($elements as $element) {
$search_str .= "($element |SCOPE|) AND ";
}
$search_str = substr($search_str, 0, -5); // remove trailing 'AND '
}
elseif (preg_match('/or/i', $search_terms)) {
$elements = preg_split('/\s+or+\s/i', $search_terms);
foreach ($elements as $element) {
$search_str .= "($element |SCOPE|) OR ";
}
$search_str = substr($search_str, 0, -4); // remove trailing 'OR '
}
else {
$search_str .= "($search_terms |SCOPE|) ";
}
$search_str .= ') ';
}
if ($scope == 'title') {
$search_str = preg_replace('/\|SCOPE\|/', '[Title]', $search_str);
}
elseif ($scope == 'author') {
$search_str = preg_replace('/\|SCOPE\|/', '[Author]', $search_str);
}
elseif ($scope == 'abstract') {
$search_str = preg_replace('/\|SCOPE\|/', '[Title/Abstract]', $search_str);
}
elseif ($scope == 'journal') {
$search_str = preg_replace('/\|SCOPE\|/', '[Journal]', $search_str);
}
elseif ($scope == 'id') {
$search_str = preg_replace('/PMID:([^\s]*)/', '$1', $search_str);
$search_str = preg_replace('/\|SCOPE\|/', '[Uid]', $search_str);
}
else {
$search_str = preg_replace('/\|SCOPE\|/', '', $search_str);
}
}
if ($days) {
// get the date of the day suggested
$past_timestamp = time() - ($days * 86400);
$past_date = getdate($past_timestamp);
$search_str .= " AND (\"" . sprintf("%04d/%02d/%02d", $past_date['year'], $past_date['mon'], $past_date['mday']) . "\"[Date - Create] : \"3000\"[Date - Create]))";
}
$search_array['limit'] = $num_to_retrieve;
$search_array['search_string'] = $search_str;
//dpm($search_str);
unset($_SESSION['tripal_pub_PMID_query']);
// we want to get the list of pubs using the search terms but using a Drupal style pager
$pubs = tripal_pager_callback('tripal_pub_PMID_range', $num_to_retrieve, $pager_id,
'tripal_pub_PMID_count', $search_array);
return $pubs;
}