Browse Source

New function for ten random abstracts

main
Simon Bowie 3 years ago
parent
commit
6d7971c7b5
3 changed files with 69 additions and 10 deletions
  1. +43
    -0
      site/public/abstracts.php
  2. +4
    -0
      site/public/index.html
  3. +22
    -10
      site/solr.php

+ 43
- 0
site/public/abstracts.php View File

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

# @name: abstracts.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: Displays ten random abstracts

include '../solr.php';

$random_abstracts = ten_random_abstracts();

?>

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

<?php

foreach ($random_abstracts as $record_array):

?>

<?
foreach ($record_array as $id => $abstract):
echo $abstract;
endforeach;
?>

<br><br>

<hr>

<?php
endforeach;
?>

</body>
</html>

+ 4
- 0
site/public/index.html View File

@@ -35,6 +35,10 @@
<a href="./titles.php">ten random titles</a>
</div>

<div class="centre">
<a href="./abstracts.php">ten random abstracts</a>
</div>

<div class="centre">
<form action="search.php" method="POST">
<input type="hidden" name="search" value="leak">

+ 22
- 10
site/solr.php View File

@@ -95,9 +95,7 @@ function parse_result($input){
preg_match('/\(.\) \\n\\n(.*)\\n/', $input, $abstract);
$output['abstract'] = $abstract[1];
}

return $output;

}

function get_random_record(){
@@ -143,9 +141,7 @@ function one_random_record (){
foreach ($random as $id => $content){
$output = parse_result($content);
}

return $output;

}

function ten_random_titles (){
@@ -153,17 +149,33 @@ function ten_random_titles (){
for ($x=0; $x <= 9; $x++) {
$random = get_random_record();

foreach($random as $id => $content){
// Search for the title in the content element and display it
preg_match('/Title.*\n(.*)\n/', $content, $title);
foreach($random as $id => $content){
// Search for the title in the content element and display it
preg_match('/Title.*\n(.*)\n/', $content, $title);

$output[$x] = array($id=>$title[1]);
}
}
return $output;
}

function ten_random_abstracts (){

$output[$x] = array($id=>$title[1]);
for ($x=0; $x <= 9; $x++) {
$random = get_random_record();

foreach($random as $id => $content){
// Search for the abstract in the content element and display it
if (preg_match('/Abstract.*\n(.*)\n/', $content, $abstract)){
$output[$x] = array($id=>$abstract[1]);
}
else {
preg_match('/\(.\) \\n\\n(.*)\\n/', $content, $abstract);
$output[$x] = array($id=>$abstract[1]);
}
}
}

return $output;

}



Loading…
Cancel
Save