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.

78 lines
2.0KB

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