Beispiel #1
0
<?php

/**
 * View a specific file
 */
$config = (require __DIR__ . '/../conf/webapp/configuration.php');
$id = isset($_REQUEST['id']) ? $_REQUEST['id'] : null;
if ($id) {
    require __DIR__ . '/../common/Tikr/Solr/Client.php';
    $solr = new \Tikr\Solr\Client($config['solrUrl']);
    $q = 'solrDocumentId:' . $id;
    $result = $solr->search($q);
    if (isset($result['response']['docs'][0])) {
        $file = $result['response']['docs'][0]['filename'];
        $contentType = is_array($result['response']['docs'][0]['contentType']) ? $result['response']['docs'][0]['contentType'][0] : $result['response']['docs']['contentType'];
        header('Content-Type: ' . $contentType);
        header('Content-Description: File Transfer');
        header('Content-Disposition: attachment; filename=' . basename($file));
        header('Expires: 0');
        header('Cache-Control: must-revalidate');
        header('Pragma: public');
        header('Content-Length: ' . filesize($file));
        echo readfile($file);
    }
}
Beispiel #2
0
$q = isset($_REQUEST['q']) ? $_REQUEST['q'] : null;
$start = isset($_REQUEST['start']) ? $_REQUEST['start'] : 0;
$rows = isset($_REQUEST['rows']) ? $_REQUEST['rows'] : 99;
// Default values
$sort = '';
$indent = 'on';
$hl = null;
$docs = array();
$params = array('q' => $q, 'start' => $start, 'rows' => $rows, 'f' => $f);
$pagination = null;
// Facets definition (refer to conf/webapp/configuration.php)
$facets = $config['facets'];
// Execute search if a query is passed
if ($q) {
    require __DIR__ . '/../common/Tikr/Solr/Client.php';
    $solr = new \Tikr\Solr\Client($config['solrUrl']);
    $query = $q;
    foreach ($f as $k => $v) {
        $query .= ' AND ' . $k . ':"' . $v . '"';
    }
    $result = $solr->search($query, $start, $rows, $sort, $indent, $hl, $facets);
    $docs = isset($result['response']['docs']) ? $result['response']['docs'] : array();
    $facetsResult = isset($result['facet_counts']['facet_fields']) ? $result['facet_counts']['facet_fields'] : array();
    $facetsDate = isset($result['facet_counts']['facet_dates']) ? $result['facet_counts']['facet_dates'] : array();
    $facetsRange = isset($result['facet_counts']['facet_ranges']) ? $result['facet_counts']['facet_ranges'] : array();
    if ($start >= 0 && $rows < $result['response']['numFound']) {
        $newParams = $params;
        $newParams['start']++;
        $pagination = '<a href="?' . http_build_query($newParams) . '#docs">Next</a>';
    }
}