diff options
| author | Christian Weiske <cweiske@cweiske.de> | 2016-02-03 06:21:30 +0100 |
|---|---|---|
| committer | Christian Weiske <cweiske@cweiske.de> | 2016-02-03 06:21:30 +0100 |
| commit | 226508cd8d3e8c147ad314a0de483e08be71c254 (patch) | |
| tree | 4142696d28830efa13835be79fd3ee888a4ab0a4 /www/index.php | |
| parent | 7b4425b096fa8c18d0db9fd9b1ae96d63ee8af55 (diff) | |
| download | phinde-226508cd8d3e8c147ad314a0de483e08be71c254.tar.gz phinde-226508cd8d3e8c147ad314a0de483e08be71c254.zip | |
first frontend
Diffstat (limited to 'www/index.php')
| -rw-r--r-- | www/index.php | 65 |
1 files changed, 35 insertions, 30 deletions
diff --git a/www/index.php b/www/index.php index 96d6f7a..8cdca41 100644 --- a/www/index.php +++ b/www/index.php @@ -1,14 +1,7 @@ <?php namespace phinde; // web interface to search -set_include_path(__DIR__ . '/../src/' . PATH_SEPARATOR . get_include_path()); -require_once __DIR__ . '/../data/config.php'; -require_once 'HTTP/Request2.php'; -require_once 'Pager.php'; -require_once 'Html/Pager.php'; -require_once 'Elasticsearch.php'; -require_once 'Elasticsearch/Request.php'; -require_once 'functions.php'; +require 'www-header.php'; if (!isset($_GET['q'])) { exit('no query'); @@ -25,41 +18,53 @@ if (isset($_GET['page'])) { } $perPage = 10;//$GLOBALS['phinde']['perPage']; +$filters = array(); +if (isset($_GET['filter'])) { + $allowedFilter = array('domain', 'language', 'tags', 'term'); + foreach ($_GET['filter'] as $type => $value) { + if (in_array($type, $allowedFilter)) { + $filters[$type] = filter_var($value, FILTER_SANITIZE_STRING); + } + } +} + $es = new Elasticsearch($GLOBALS['phinde']['elasticsearch']); -$res = $es->search($query, $page, $perPage); +$res = $es->search($query, $filters, $page, $perPage); $pager = new Html_Pager( $res->hits->total, $perPage, $page + 1, '?q=' . $query ); -foreach ($res->hits->hits as $hit) { +foreach ($res->hits->hits as &$hit) { $doc = $hit->_source; if ($doc->title == '') { $doc->title = '(no title)'; } - echo '<p>' - . '<a href="' . htmlspecialchars($doc->url) . '">' - . htmlspecialchars($doc->title) - . '</a>'; - if (isset($doc->author->name)) { - echo ' by <a href="' . htmlspecialchars($doc->author->url) . '">' - . htmlspecialchars($doc->author->name) - . '</a>'; - } - echo '<br/><tt>' - . htmlspecialchars(preg_replace('#^.*://#', '', $doc->url)) - . '</tt>'; + $doc->extra = new \stdClass(); + $doc->extra->cleanUrl = preg_replace('#^.*://#', '', $doc->url); if (isset($doc->modate)) { - echo '<br/>Changed: ' . substr($doc->modate, 0, 10); + $doc->extra->day = substr($doc->modate, 0, 10); } - echo '</p>'; } -$links = $pager->getLinks(); -echo $links['back'] - . ' ' . implode(' ', $links['pages']) - . ' ' . $links['next']; -//var_dump($links); -var_dump($res->aggregations->domain); +$baseLink = '?q=' . urlencode($query); +foreach ($res->aggregations as $key => &$aggregation) { + foreach ($aggregation->buckets as &$bucket) { + $bucket->url = $baseLink + . '&filter[' . urlencode($key) . ']=' . urlencode($bucket->key); + } +} +//var_dump($res->aggregations); + +render( + 'search', + array( + 'query' => $query, + 'hitcount' => $res->hits->total, + 'hits' => $res->hits->hits, + 'aggregations' => $res->aggregations, + 'pager' => $pager + ) +); ?> |
