@@ -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
0 commit comments