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
Nelze vybrat více než 25 témat Téma musí začínat písmenem nebo číslem, může obsahovat pomlčky („-“) a může být dlouhé až 35 znaků.

59 lines
2.2KB

  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://' . $_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. //Set content variable
  21. $content = $json->response->docs[$random]->content;
  22. //Set document reference number (used for OPS API)
  23. preg_match('/=D\s(([^\s]*)\s([^\s]*)\s([^\s]*))/', $content, $doc_ref);
  24. $output['doc_ref'] = str_replace(' ','',$doc_ref[1]);
  25. // Search for the application ID in the content element and display it
  26. preg_match('/Application.*\n(.*)\n/', $content, $application_id);
  27. $output['application_id'] = $application_id[1];
  28. // Search for the EPO publication URL in the content element and display it
  29. preg_match('/Publication.*\n(.*)\n/', $content, $epo_publication);
  30. $output['epo_publication_url'] = $epo_publication[1];
  31. // Search for the IPC publication URL in the content element and display it
  32. preg_match('/IPC.*\n(.*)\n/', $content, $ipc_publication);
  33. $output['ipc_publication_url'] = $ipc_publication[1];
  34. // Search for the title in the content element and display it
  35. preg_match('/Title.*\n(.*)\n/', $content, $title);
  36. $output['title'] = $title[1];
  37. // Search for the abstract in the content element and display it
  38. preg_match('/Abstract.*\n(.*)\n/', $content, $abstract);
  39. $output['abstract'] = $abstract[1];
  40. return $output;
  41. }
  42. ?>