Parcourir la source

Added ID to prepare for API integration, more code efficiencies

main
Simon Bowie il y a 3 ans
Parent
révision
32675c6206
2 fichiers modifiés avec 38 ajouts et 10 suppressions
  1. +24
    -2
      site/public/index.php
  2. +14
    -8
      site/random.php

+ 24
- 2
site/public/index.php Voir le fichier

@@ -6,6 +6,16 @@ $random_record = random_record();

?>

ID:

<?php

echo $random_record['id']

?>

<br><br>

Application ID:

<?php
@@ -18,10 +28,22 @@ echo $random_record['application_id'];

EPO publication:

<a href=<?php echo $random_record['publication_url']; ?>>
<a href=<?php echo $random_record['epo_publication_url']; ?>>
<?php

echo $random_record['epo_publication_url'];

?>
</a>

<br><br>

IPC publication:

<a href=<?php echo $random_record['ipc_publication_url']; ?>>
<?php

echo $random_record['publication_url'];
echo $random_record['ipc_publication_url'];

?>
</a>

+ 14
- 8
site/random.php Voir le fichier

@@ -7,7 +7,6 @@ function random_record (){

// 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
@@ -25,23 +24,30 @@ function random_record (){
// 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
//Set content variable
$content = $json->response->docs[$random]->content;

//Set document reference number (used for OPS API)

$output['id'] = $json->response->docs[$random]->id;;

// Search for the application ID in the content element and display it
preg_match('/Application.*\n(.*)\n/', $content, $application_id);
$output['application_id'] = $application_id[1];

// Search for the publication URL in the content element and display it
$content = $json->response->docs[$random]->content;
preg_match('/Publication.*\n(.*)\n/', $content, $publication);
$output['publication_url'] = $publication[1];
// Search for the EPO publication URL in the content element and display it
preg_match('/Publication.*\n(.*)\n/', $content, $epo_publication);
$output['epo_publication_url'] = $epo_publication[1];

// Search for the IPC publication URL in the content element and display it
preg_match('/IPC.*\n(.*)\n/', $content, $ipc_publication);
$output['ipc_publication_url'] = $ipc_publication[1];

// Search for the title in the content element and display it
$content = $json->response->docs[$random]->content;
preg_match('/Title.*\n(.*)\n/', $content, $title);
$output['title'] = $title[1];

// Search for the abstract in the content element and display it
$content = $json->response->docs[$random]->content;
preg_match('/Abstract.*\n(.*)\n/', $content, $abstract);
$output['abstract'] = $abstract[1];


Chargement…
Annuler
Enregistrer