Skip to content

Commit 20e0301

Browse files
committed
Restaure search_id feature
TODO: better pagination
1 parent 95739bd commit 20e0301

File tree

4 files changed

+26
-16
lines changed

4 files changed

+26
-16
lines changed

featherbb/Controller/Search.php

Lines changed: 12 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -33,13 +33,21 @@ public function display($req, $res, $args)
3333
}
3434

3535
// Figure out what to do :-)
36-
if (Input::query('action') || (Input::query('search_id'))) {
36+
if (Input::query('action') || $args['search_id']) {
3737

38-
$search = $this->model->get_search_results();
38+
$search = $this->model->get_search_results($args['search_id']);
3939

40-
// We have results to display
41-
if (!is_object($search) && isset($search['is_result'])) {
40+
if (is_object($search)) {
41+
// $search is most likely a Router::redirect() to search page (no hits or other error) or to a search_id
42+
return $search;
43+
} else {
44+
45+
// No results to display, redirect with message
46+
if (!isset($search['is_result'])) {
47+
return Router::redirect(Router::pathFor('search'), ['error', __('No hits')]);
48+
}
4249

50+
// We have results to display
4351
View::setPageInfo(array(
4452
'title' => array(Utils::escape(ForumSettings::get('o_board_title')), __('Search results')),
4553
'active_page' => 'search',
@@ -64,9 +72,6 @@ public function display($req, $res, $args)
6472
}
6573

6674
View::addTemplate('search/footer.php', 10)->display();
67-
68-
} else {
69-
return Router::redirect(Router::pathFor('search'), __('No hits'));
7075
}
7176
}
7277
// Display the form

featherbb/Model/Search.php

Lines changed: 12 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ public function __construct()
2222
$this->search = new \FeatherBB\Core\Search();
2323
}
2424

25-
public function get_search_results()
25+
public function get_search_results($search_id = null)
2626
{
2727
$search = array();
2828

@@ -42,8 +42,8 @@ public function get_search_results()
4242
}
4343

4444
// If a search_id was supplied
45-
if (Input::query('search_id')) {
46-
$search_id = intval(Input::query('search_id'));
45+
if ($search_id) {
46+
$search_id = intval($search_id);
4747
if ($search_id < 1) {
4848
throw new Error(__('Bad request'), 400);
4949
}
@@ -62,7 +62,7 @@ public function get_search_results()
6262
}
6363

6464
if (!$keywords && !$author) {
65-
throw new Error(__('No terms'), 400);
65+
return Router::redirect(Router::pathFor('search'), ['error', __('No terms')]);
6666
}
6767

6868
if ($author) {
@@ -118,7 +118,7 @@ public function get_search_results()
118118

119119
unset($temp);
120120
} else {
121-
throw new Error(__('No hits'), 404);
121+
return Router::redirect(Router::pathFor('search'), ['error', __('No hits')]);
122122
}
123123
} else {
124124
$keyword_results = $author_results = array();
@@ -178,7 +178,7 @@ public function get_search_results()
178178
$keywords_array = Container::get('hooks')->fire('model.search.get_search_results_keywords_array', $keywords_array);
179179

180180
if (empty($keywords_array)) {
181-
throw new Error(__('No hits'), 400);
181+
return Router::redirect(Router::pathFor('search'), ['error', __('No hits')]);
182182
}
183183

184184
// Should we search in message body or topic subject specifically?
@@ -315,7 +315,7 @@ public function get_search_results()
315315

316316
$num_hits = count($search_ids);
317317
if (!$num_hits) {
318-
throw new Error(__('No hits'), 400);
318+
return Router::redirect(Router::pathFor('search'), ['error', __('No hits')]);
319319
}
320320
} elseif ($action == 'show_new' || $action == 'show_recent' || $action == 'show_replies' || $action == 'show_user_posts' || $action == 'show_user_topics' || $action == 'show_subscriptions' || $action == 'show_unanswered') {
321321
$search_type = array('action', $action);
@@ -563,6 +563,11 @@ public function get_search_results()
563563
->set($cache['insert']);
564564
$cache = Container::get('hooks')->fireDB('model.search.get_search_results_update_cache', $cache);
565565
$cache = $cache->save();
566+
567+
if ($search_type[0] != 'action') {
568+
// Redirect the user to the cached result page
569+
return Router::redirect(Router::pathFor('search', ['search_id' => $search_id]));
570+
}
566571
}
567572

568573
// If we're on the new posts search, display a "mark all as read" link

featherbb/View/search/form.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@
2424
<legend><?php _e('Search criteria legend') ?></legend>
2525
<div class="infldset">
2626
<input type="hidden" name="action" value="search" />
27-
<label class="conl"><?php _e('Keyword search') ?><br /><input type="text" name="keywords" size="40" maxlength="100" autofocus /><br /></label>
27+
<label class="conl"><?php _e('Keyword search') ?><br /><input type="text" name="keywords" size="40" maxlength="100" pattern=".{<?= ForumEnv::get('FEATHER_SEARCH_MIN_WORD') ?>,}" autofocus required /><br /></label>
2828
<label class="conl"><?php _e('Author search') ?><br /><input id="author" type="text" name="author" size="25" maxlength="25" /><br /></label>
2929
<p class="clearb"><?php _e('Search info') ?></p>
3030
</div>

featherbb/routes.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -77,7 +77,7 @@
7777

7878
// Search routes
7979
Route::group('/search', function() {
80-
Route::get('', '\FeatherBB\Controller\Search:display')->setName('search');
80+
Route::get('[/{search_id:\d+}]', '\FeatherBB\Controller\Search:display')->setName('search');
8181
Route::get('/show/{show}', '\FeatherBB\Controller\Search:quicksearches')->setName('quickSearch');
8282
})->add(new CanReadBoard);
8383

0 commit comments

Comments
 (0)