{"query":"Berufsbildung","authType":"Subject","count":42} */ header('Content-Type: application/json; charset=utf-8'); header('Access-Control-Allow-Origin: *'); // IP-Prüfung require_once __DIR__ . '/checkAccess.php'; // Parameter $authType = isset($_GET['authType']) ? trim($_GET['authType']) : ''; $query = isset($_GET['query']) ? trim($_GET['query']) : ''; // Validierung $allowedTypes = array('Subject', 'Person'); if (!in_array($authType, $allowedTypes)) { http_response_code(400); echo json_encode(array('error' => 'Invalid authType. Allowed: Subject, Person')); exit; } if (strlen($query) === 0) { http_response_code(400); echo json_encode(array('error' => 'Missing parameter: query')); exit; } // Solr-Feld je nach authType switch ($authType) { case 'Subject': $queryField = 'dc.subject.other'; break; case 'Person': $queryField = 'dc.contributor.author'; break; } // Query bereinigen $query = urldecode($query); $query = str_replace("'", "", $query); // Solr-Abfrage $solr_baseurl = "http://localhost:8080/solr/search/query?"; $solr_query = $queryField . ':' . $query; $rows = "&rows=10000"; $fl = "&fl=" . $queryField; $solr_URL = $solr_baseurl . "wt=phps" . $fl . $rows . "&q=" . urlencode($solr_query . " AND withdrawn:false"); $context = stream_context_create(array( 'http' => array('timeout' => 10) )); $response = @file_get_contents($solr_URL, false, $context); if ($response === false) { http_response_code(500); echo json_encode(array('error' => 'Solr query failed')); exit; } $result = unserialize($response); if (!isset($result['response']['docs'])) { echo json_encode(array( 'query' => $query, 'authType' => $authType, 'count' => 0 )); exit; } // Exakte Treffer zählen (analog zu DSpaceCountModel) $count = 0; foreach ($result['response']['docs'] as $entry) { foreach ($entry as $hit) { if (!is_array($hit)) { $hit = array($hit); } foreach ($hit as $h) { if ($authType === "Subject") { if (strcmp($query, trim($h)) === 0) { $count++; } } else { // Person: Authority-ID in eckigen Klammern abschneiden $name = trim(substr($h, 0, strpos($h, "["))); if (strlen($name) === 0) { $name = trim($h); } if (strcmp($query, $name) === 0) { $count++; } } } } } echo json_encode(array( 'query' => $query, 'authType' => $authType, 'count' => $count )); ?>