function tripal_pub_PMID_search_init
2.x tripal_pub.PMID.inc | tripal_pub_PMID_search_init($search_str, $retmax) |
3.x tripal_chado.pub_importer_PMID.inc | tripal_pub_PMID_search_init($search_str, $retmax) |
1.x PMID.inc | tripal_pub_PMID_search_init($search_str, $retmax) |
Initailizes a PubMed Search using a given search string
Parameters
$search_str: The PubMed Search string
$retmax: The maximum number of records to return
Return value
An array containing the Count, WebEnv and QueryKey as return by PubMed's esearch utility
1 call to tripal_pub_PMID_search_init()
- tripal_pub_remote_search_PMID in tripal_chado/
includes/ loaders/ tripal_chado.pub_importer_PMID.inc - A hook for performing the search on the PubMed database.
File
- tripal_chado/
includes/ loaders/ tripal_chado.pub_importer_PMID.inc, line 205 - This file provides support for importing and parsing of results from the NCBI PubMed database. The functions here are used by both the publication importer setup form and the publication importer.
Code
function tripal_pub_PMID_search_init($search_str, $retmax) {
// do a search for a single result so that we can establish a history, and get
// the number of records. Once we have the number of records we can retrieve
// those requested in the range.
$query_url = "http://www.ncbi.nlm.nih.gov/entrez/eutils/esearch.fcgi?" .
"db=Pubmed" .
"&retmax=$retmax" .
"&usehistory=y" .
"&term=" . urlencode($search_str);
$rfh = fopen($query_url, "r");
if (!$rfh) {
drupal_set_message('Could not perform Pubmed query. Cannot connect to Entrez.', 'error');
tripal_report_error('tripal_pubmed', TRIPAL_ERROR, "Could not perform Pubmed query. Cannot connect to Entrez.",
array());
return 0;
}
// retrieve the XML results
$query_xml = '';
while (!feof($rfh)) {
$query_xml .= fread($rfh, 255);
}
fclose($rfh);
$xml = new XMLReader();
$xml->xml($query_xml);
// iterate though the child nodes of the <eSearchResult> tag and get the count, history and query_id
$result = array();
while ($xml->read()) {
$element = $xml->name;
if ($xml->nodeType == XMLReader::END_ELEMENT and $element == 'WebEnv') {
// we've read as much as we need. If we go too much further our counts
// will get messed up by other 'Count' elements. so we're done.
break;
}
if ($xml->nodeType == XMLReader::ELEMENT) {
switch ($element) {
case 'Count':
$xml->read();
$result['Count'] = $xml->value;
break;
case 'WebEnv':
$xml->read();
$result['WebEnv'] = $xml->value;
break;
case 'QueryKey':
$xml->read();
$result['QueryKey'] = $xml->value;
break;
}
}
}
return $result;
}