<?php | <?php | ||||
// Generate a random number for sorting by random | |||||
$random = rand(); | |||||
include '../random.php'; | |||||
// Assemble a query string to send to Solr. This uses the Solr hostname from config.env. Solr's query syntax can be found at many sites including https://lucene.apache.org/solr/guide/6_6/the-standard-query-parser.html | |||||
// This query retrieves only the bib identifier field for records which satisfy the search query | |||||
#$solrurl = 'http://host.docker.internal:8983/solr/epo_data/select?q.op=OR&q=*%3A*&wt=json&sort=random_' . $random . '%20asc'; | |||||
$solrurl = 'http://' . $_ENV["SOLR_HOSTNAME"] . ':' . $_ENV["SOLR_PORT"] . '/solr/' . $_ENV["SOLR_CORE"] . '/select?q.op=OR&q=*%3A*&wt=json&sort=random_' . $random . '%20asc'; | |||||
// Perform Curl request on the Solr API | |||||
$ch = curl_init(); | |||||
curl_setopt($ch, CURLOPT_URL, $solrurl); | |||||
curl_setopt($ch, CURLOPT_RETURNTRANSFER, TRUE); | |||||
curl_setopt($ch, CURLOPT_HEADER, FALSE); | |||||
curl_setopt($ch, CURLOPT_CUSTOMREQUEST, 'GET'); | |||||
$response = curl_exec($ch); | |||||
curl_close($ch); | |||||
// Turn the API response into useful Json | |||||
$json = json_decode($response); | |||||
// Pick a random key out of the docs array | |||||
$random = array_rand($json->response->docs); | |||||
$random_record = random_record(); | |||||
?> | ?> | ||||
<?php | <?php | ||||
// Search for the title in the content element and display it | |||||
$content = $json->response->docs[$random]->content; | |||||
preg_match('/Application.*\n(.*)\n/', $content, $application_id); | |||||
print_r($application_id[1]); | |||||
echo $random_record['application_id']; | |||||
?> | ?> | ||||
<?php | <?php | ||||
// Search for the title in the content element and display it | |||||
$content = $json->response->docs[$random]->content; | |||||
preg_match('/Publication.*\n(.*)\n/', $content, $publication); | |||||
print_r($publication[1]); | |||||
echo $random_record['publication_id']; | |||||
?> | ?> | ||||
<?php | <?php | ||||
// Search for the title in the content element and display it | |||||
$content = $json->response->docs[$random]->content; | |||||
preg_match('/Title.*\n(.*)\n/', $content, $title); | |||||
print_r($title[1]); | |||||
echo $random_record['title']; | |||||
?> | ?> | ||||
<?php | <?php | ||||
// Search for the title in the content element and display it | |||||
$content = $json->response->docs[$random]->content; | |||||
preg_match('/Abstract.*\n(.*)\n/', $content, $abstract); | |||||
print_r($abstract[1]); | |||||
echo $random_record['abstract']; | |||||
?> | ?> |
<?php | |||||
function random_record (){ | |||||
// Generate a random number for sorting by random | |||||
$random = rand(); | |||||
// Assemble a query string to send to Solr. This uses the Solr hostname from config.env. Solr's query syntax can be found at many sites including https://lucene.apache.org/solr/guide/6_6/the-standard-query-parser.html | |||||
// This query retrieves only the bib identifier field for records which satisfy the search query | |||||
#$solrurl = 'http://host.docker.internal:8983/solr/epo_data/select?q.op=OR&q=*%3A*&wt=json&sort=random_' . $random . '%20asc'; | |||||
$solrurl = 'http://' . $_ENV["SOLR_HOSTNAME"] . ':' . $_ENV["SOLR_PORT"] . '/solr/' . $_ENV["SOLR_CORE"] . '/select?q.op=OR&q=*%3A*&wt=json&sort=random_' . $random . '%20asc'; | |||||
// Perform Curl request on the Solr API | |||||
$ch = curl_init(); | |||||
curl_setopt($ch, CURLOPT_URL, $solrurl); | |||||
curl_setopt($ch, CURLOPT_RETURNTRANSFER, TRUE); | |||||
curl_setopt($ch, CURLOPT_HEADER, FALSE); | |||||
curl_setopt($ch, CURLOPT_CUSTOMREQUEST, 'GET'); | |||||
$response = curl_exec($ch); | |||||
curl_close($ch); | |||||
// Turn the API response into useful Json | |||||
$json = json_decode($response); | |||||
// Pick a random key out of the docs array | |||||
$random = array_rand($json->response->docs); | |||||
// Search for the application ID in the content element and display it | |||||
$content = $json->response->docs[$random]->content; | |||||
preg_match('/Application.*\n(.*)\n/', $content, $application_id); | |||||
$application_id = json_encode($application_id[1]); | |||||
$output['application_id'] = $application_id; | |||||
// Search for the publication ID in the content element and display it | |||||
$content = $json->response->docs[$random]->content; | |||||
preg_match('/Publication.*\n(.*)\n/', $content, $publication); | |||||
$publication_id = json_encode($publication[1]); | |||||
$output['publication_id'] = $publication_id; | |||||
// Search for the title in the content element and display it | |||||
$content = $json->response->docs[$random]->content; | |||||
preg_match('/Title.*\n(.*)\n/', $content, $title); | |||||
$title = json_encode($title[1]); | |||||
$output['title'] = $title; | |||||
// Search for the abstract in the content element and display it | |||||
$content = $json->response->docs[$random]->content; | |||||
preg_match('/Abstract.*\n(.*)\n/', $content, $abstract); | |||||
$abstract = json_encode($abstract[1]); | |||||
$output['abstract'] = $abstract; | |||||
return $output; | |||||
} | |||||
?> |