+{% if hitcount > 1 %}
+ Sort by:
+<div class="btn-group">
+ <a class="btn{%if sort==""%} disabled btn-primary{%endif%}" href="{{urlSortRelevance}}">Relevance</a>
+ <a class="btn{%if sort=="date"%} disabled btn-primary{%endif%}" href="{{urlSortDate}}">Date</a>
+</div>
+<br/>
+<br/>
+{% endif %}
{% set filters %}
{% include 'search/sidebar-filter.htm' with {'type': 'tags', 'title': 'Tag'} %}
{% include 'search/sidebar-filter.htm' with {'type': 'domain', 'title': 'Domain'} %}
$r->send();
}
- public function search($query, $filters, $site, $page, $perPage)
+ public function search($query, $filters, $site, $page, $perPage, $sort)
{
+ if ($sort == 'date') {
+ $sortCfg = array('modate' => array('order' => 'desc'));
+ } else {
+ $sortCfg = array();
+ }
+
$r = new Elasticsearch_Request(
$this->baseUrl . 'document/_search',
\HTTP_Request2::METHOD_GET
),
'from' => $page * $perPage,
'size' => $perPage,
- 'sort' => array(
- //array('modate' => array('order' => 'desc'))
- )
+ 'sort' => $sortCfg,
);
foreach ($filters as $type => $value) {
$doc['query']['bool']['must'][] = array(
//PEAR Pager begins at 1
$page = (int)$_GET['page'] - 1;
}
+
$perPage = 10;//$GLOBALS['phinde']['perPage'];
$site = null;
$siteParam = false;
$cleanQuery = $query;
}
+if (isset($_GET['sort']) && $_GET['sort'] == 'date') {
+ $sort = 'date';
+ $baseLink .= '&sort=date';
+} else {
+ $sort = '';
+}
+
$filters = array();
if (isset($_GET['filter'])) {
$allowedFilter = array('domain', 'language', 'tags', 'term');
$timeBegin = microtime(true);
$es = new Elasticsearch($GLOBALS['phinde']['elasticsearch']);
-$res = $es->search($cleanQuery, $filters, $site, $page, $perPage);
+$res = $es->search($cleanQuery, $filters, $site, $page, $perPage, $sort);
$timeEnd = microtime(true);
$pager = new Html_Pager(
$urlNoSite = null;
}
+$urlSortRelevance = buildLink(
+ str_replace('&sort=date', '', $baseLink), $filters, null, null
+);
+$urlSortDate = $urlSortRelevance . '&sort=date';
+
render(
'search',
array(
'hits' => $res->hits->hits,
'aggregations' => $res->aggregations,
'activeFilters' => $activeFilters,
- 'pager' => $pager
+ 'pager' => $pager,
+ 'sort' => $sort,
+ 'urlSortRelevance' => $urlSortRelevance,
+ 'urlSortDate' => $urlSortDate,
)
);
?>