A search interface for data from the Politics of Patents case study (part of Copim WP6): this parses data from the archive of RTF files and provides additional data from the European Patent Office API. https://patents.copim.ac.uk
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

random.php 2.1KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152
  1. <?php
  2. function random_record (){
  3. // Generate a random number for sorting by random
  4. $random = rand();
  5. // 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
  6. // This query retrieves only the bib identifier field for records which satisfy the search query
  7. #$solrurl = 'http://host.docker.internal:8983/solr/epo_data/select?q.op=OR&q=*%3A*&wt=json&sort=random_' . $random . '%20asc';
  8. $solrurl = 'http://' . $_ENV["SOLR_HOSTNAME"] . ':' . $_ENV["SOLR_PORT"] . '/solr/' . $_ENV["SOLR_CORE"] . '/select?q.op=OR&q=*%3A*&wt=json&sort=random_' . $random . '%20asc';
  9. // Perform Curl request on the Solr API
  10. $ch = curl_init();
  11. curl_setopt($ch, CURLOPT_URL, $solrurl);
  12. curl_setopt($ch, CURLOPT_RETURNTRANSFER, TRUE);
  13. curl_setopt($ch, CURLOPT_HEADER, FALSE);
  14. curl_setopt($ch, CURLOPT_CUSTOMREQUEST, 'GET');
  15. $response = curl_exec($ch);
  16. curl_close($ch);
  17. // Turn the API response into useful Json
  18. $json = json_decode($response);
  19. // Pick a random key out of the docs array
  20. $random = array_rand($json->response->docs);
  21. // Search for the application ID in the content element and display it
  22. $content = $json->response->docs[$random]->content;
  23. preg_match('/Application.*\n(.*)\n/', $content, $application_id);
  24. $output['application_id'] = $application_id[1];
  25. // Search for the publication URL in the content element and display it
  26. $content = $json->response->docs[$random]->content;
  27. preg_match('/Publication.*\n(.*)\n/', $content, $publication);
  28. $output['publication_url'] = $publication[1];
  29. // Search for the title in the content element and display it
  30. $content = $json->response->docs[$random]->content;
  31. preg_match('/Title.*\n(.*)\n/', $content, $title);
  32. $output['title'] = $title[1];
  33. // Search for the abstract in the content element and display it
  34. $content = $json->response->docs[$random]->content;
  35. preg_match('/Abstract.*\n(.*)\n/', $content, $abstract);
  36. $output['abstract'] = $abstract[1];
  37. return $output;
  38. }
  39. ?>