diff options
| author | Christian Weiske <cweiske@cweiske.de> | 2016-11-17 18:21:14 +0100 |
|---|---|---|
| committer | Christian Weiske <cweiske@cweiske.de> | 2016-11-17 18:21:14 +0100 |
| commit | f98e891b454e5677bdf61f476e366b01af713b50 (patch) | |
| tree | 6f44d739b0fbd4369945ec21bf5b0064dff590a8 | |
| parent | 202def908c2782312d82eeefd67afb0469dee440 (diff) | |
| download | phinde-f98e891b454e5677bdf61f476e366b01af713b50.tar.gz phinde-f98e891b454e5677bdf61f476e366b01af713b50.zip | |
Configuration for default sort order
| -rw-r--r-- | data/config.php.dist | 2 | ||||
| -rw-r--r-- | data/templates/search/sidebar.htm | 4 | ||||
| -rw-r--r-- | src/phinde/Elasticsearch.php | 3 | ||||
| -rw-r--r-- | www/index.php | 29 |
4 files changed, 27 insertions, 11 deletions
diff --git a/data/config.php.dist b/data/config.php.dist index 9c432f9..19a3221 100644 --- a/data/config.php.dist +++ b/data/config.php.dist @@ -34,5 +34,7 @@ $GLOBALS['phinde'] = array( 'showFullContent' => false, //search result "hit" template file 'hitTemplate' => 'hit.htm', + //default sort order: "score" or "date" + 'defaultSort' => 'score', ); ?>
\ No newline at end of file diff --git a/data/templates/search/sidebar.htm b/data/templates/search/sidebar.htm index a48b6e8..0c663ee 100644 --- a/data/templates/search/sidebar.htm +++ b/data/templates/search/sidebar.htm @@ -1,8 +1,8 @@ {% 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> + <a class="btn{%if sort=="score"%} disabled btn-primary{%endif%}" href="{{urlSorts.score}}">Relevance</a> + <a class="btn{%if sort=="date"%} disabled btn-primary{%endif%}" href="{{urlSorts.date}}">Date</a> </div> <br/> <br/> diff --git a/src/phinde/Elasticsearch.php b/src/phinde/Elasticsearch.php index 6c90480..c24f6cd 100644 --- a/src/phinde/Elasticsearch.php +++ b/src/phinde/Elasticsearch.php @@ -135,6 +135,9 @@ class Elasticsearch ) ); + if ($sort == '' && $GLOBALS['phinde']['defaultSort'] == 'date') { + $sort = 'date'; + } if ($sort == 'date') { $sortCfg = array('status.modate' => array('order' => 'desc')); } else { diff --git a/www/index.php b/www/index.php index 8bf8147..8bd900c 100644 --- a/www/index.php +++ b/www/index.php @@ -35,11 +35,16 @@ if (preg_match('#site:([^ ]*)#', $query, $matches)) { $cleanQuery = $query; } -if (isset($_GET['sort']) && $_GET['sort'] == 'date') { - $sort = 'date'; - $baseLink .= '&sort=date'; +if (isset($_GET['sort']) + && ($_GET['sort'] === 'date' || $_GET['sort'] === 'score') +) { + $sortMode = $_GET['sort']; } else { - $sort = ''; + $sortMode = $GLOBALS['phinde']['defaultSort']; +} +$sort = $sortMode; +if ($sortMode !== $GLOBALS['phinde']['defaultSort']) { + $baseLink .= '&sort=' . $sortMode; } $filters = array(); @@ -132,10 +137,17 @@ if ($site !== null) { $urlNoSite = null; } -$urlSortRelevance = buildLink( - str_replace('&sort=date', '', $baseLink), $filters, null, null +$urlSortBase = buildLink( + preg_replace('#&sort=[^&]+#', '', $baseLink), $filters, null, null ); -$urlSortDate = $urlSortRelevance . '&sort=date'; +$urlSorts = []; +foreach (['date', 'score'] as $sortMode) { + if ($sortMode === $GLOBALS['phinde']['defaultSort']) { + $urlSorts[$sortMode] = $urlSortBase; + } else { + $urlSorts[$sortMode] = $urlSortBase . '&sort=' . $sortMode; + } +} if (isset($_GET['format']) && $_GET['format'] == 'opensearch') { $template = 'opensearch'; @@ -161,8 +173,7 @@ render( 'activeFilters' => $activeFilters, 'pager' => $pager, 'sort' => $sort, - 'urlSortRelevance' => $urlSortRelevance, - 'urlSortDate' => $urlSortDate, + 'urlSorts' => $urlSorts, 'hitTemplate' => 'search/' . $GLOBALS['phinde']['hitTemplate'], ) ); |
