Parcourir la source

More functions added after discussion with project team

main
Simon Bowie il y a 3 ans
Parent
révision
a621b4c692
7 fichiers modifiés avec 271 ajouts et 61 suppressions
  1. +31
    -0
      site/public/compare.php
  2. +7
    -0
      site/public/css/style.css
  3. +27
    -0
      site/public/index.html
  4. +3
    -3
      site/public/random.php
  5. +77
    -0
      site/public/search.php
  6. +0
    -58
      site/random.php
  7. +126
    -0
      site/solr.php

+ 31
- 0
site/public/compare.php Voir le fichier

@@ -0,0 +1,31 @@
<?php

# @name: compare.php
# @version: 0.1
# @creation_date: 2021-09-30
# @license: The MIT License <https://opensource.org/licenses/MIT>
# @author: Simon Bowie <ad7588@coventry.ac.uk>
# @purpose: Displays two random records from the Solr index

?>

<!DOCTYPE html>
<html lang="en">
<head>
<link rel="stylesheet" type="text/css" href="css/style.css">
<script>
function resizeIframe(obj) {
obj.style.height = obj.contentWindow.document.documentElement.scrollHeight + 'px';
}
</script>
</head>
<body>
<div class="box">
<iframe src="./random.php" frameborder="0" scrolling="no" onload="resizeIframe(this)" align="left"> </iframe>
</div>

<div class="box">
<iframe src="./random.php" frameborder="0" scrolling="no" onload="resizeIframe(this)" align="right"></iframe>
</div>
</body>
</html>

+ 7
- 0
site/public/css/style.css Voir le fichier

@@ -0,0 +1,7 @@
.box{
float:left;
margin-right:20px;
}
.clear{
clear:both;
}

+ 27
- 0
site/public/index.html Voir le fichier

@@ -0,0 +1,27 @@
<!--

# @name: index.html
# @version: 0.1
# @creation_date: 2021-09-24
# @license: The MIT License <https://opensource.org/licenses/MIT>
# @author: Simon Bowie <ad7588@coventry.ac.uk>
# @purpose: Home page for the application

-->

<!DOCTYPE html>
<html lang="en">
<head>
</head>
<body>

<form action="search.php" method="POST">
<input type="text" name="search" placeholder="search for a patent record">
<input type="submit" value="search">
</form>

<a href="./random.php">show a random record</a>
<a href="./compare.php">compare two random records</a>

</body>
</html>

site/public/index.php → site/public/random.php Voir le fichier

@@ -1,13 +1,13 @@
<?php

# @name: index.php
# @name: random.php
# @version: 0.1
# @creation_date: 2021-09-24
# @license: The MIT License <https://opensource.org/licenses/MIT>
# @author: Simon Bowie <ad7588@coventry.ac.uk>
# @purpose: Home page for the application
# @purpose: Displays a random record from the Solr index

include '../random.php';
include '../solr.php';
include '../ops_api.php';

$random_record = random_record();

+ 77
- 0
site/public/search.php Voir le fichier

@@ -0,0 +1,77 @@
<?php

# @name: search.php
# @version: 0.1
# @creation_date: 2021-09-30
# @license: The MIT License <https://opensource.org/licenses/MIT>
# @author: Simon Bowie <ad7588@coventry.ac.uk>
# @purpose: Searches the Solr index

include '../solr.php';

?>

<?php

$search_results = solr_search($_POST["search"]);

//print_r($search_results);

foreach($search_results as $result):

?>
Application ID:

<?php
echo $result['application_id'];
?>

<br><br>

EPO publication:

<a href=<?php echo $result['epo_publication_url']; ?>>
<?php
echo $result['epo_publication_url'];
?>
</a>

<br><br>

IPC publication:

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

<br><br>

Title:

<?php
echo $result['title'];
?>

<br><br>

<?php
if ($result['abstract']):
?>

Abstract:

<?php
echo $result['abstract'];
?>

<br><br>

<?
endif;
?>

<?php
endforeach;
?>

+ 0
- 58
site/random.php Voir le fichier

@@ -1,58 +0,0 @@
<?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://' . $_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);

//Set content variable
$content = $json->response->docs[$random]->content;

//Set document reference number (used for OPS API)
preg_match('/=D\s(([^\s]*)\s([^\s]*)\s([^\s]*))/', $content, $doc_ref);
$output['doc_ref'] = str_replace(' ','',$doc_ref[1]);

// 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 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
preg_match('/Title.*\n(.*)\n/', $content, $title);
$output['title'] = $title[1];

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

return $output;

}

?>

+ 126
- 0
site/solr.php Voir le fichier

@@ -0,0 +1,126 @@
<?php

function solr_search($search){

// 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://' . $_ENV["SOLR_HOSTNAME"] . ':' . $_ENV["SOLR_PORT"] . '/solr/' . $_ENV["SOLR_CORE"] . '/select?q.op=OR&q=content%3A' . $search . '&wt=json';

// 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);

// If no results are found, display a message
if ($json->response->numFound == '0'){
$output = 'No results found';
}
else{
$output = parse_results($json);
}

return $output;

}

function parse_results($json_response){

foreach ($json_response->response->docs as $result){

$content = $result->content;

//Set document reference number (used for OPS API)
preg_match('/=D\s(([^\s]*)\s([^\s]*)\s([^\s]*))/', $content, $doc_ref);
$result_output['doc_ref'] = str_replace(' ','',$doc_ref[1]);

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

// Search for the EPO publication URL in the content element and display it
preg_match('/Publication.*\n(.*)\n/', $content, $epo_publication);
$result_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);
$result_output['ipc_publication_url'] = $ipc_publication[1];

// Search for the title in the content element and display it
preg_match('/Title.*\n(.*)\n/', $content, $title);
$result_output['title'] = $title[1];

// Search for the abstract in the content element and display it
preg_match('/Abstract.*\n(.*)\n/', $content, $abstract);
$result_output['abstract'] = $abstract[1];

$results[] = $result_output;

}

return $results;

}

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://' . $_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);

//Set content variable
$content = $json->response->docs[$random]->content;

//Set document reference number (used for OPS API)
preg_match('/=D\s(([^\s]*)\s([^\s]*)\s([^\s]*))/', $content, $doc_ref);
$output['doc_ref'] = str_replace(' ','',$doc_ref[1]);

// 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 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
preg_match('/Title.*\n(.*)\n/', $content, $title);
$output['title'] = $title[1];

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

return $output;

}

?>

Chargement…
Annuler
Enregistrer