Display search results as threads by default (not as posts or mixed).

farang

Well-known member
Hi there.

Making a standard search, search results a mixed threads and posts. Most searchers maybe haven't even reflected over that. In an advanced search there is an option "Display results as threads" that is not ticked by default.

I have been using some time today to figure out how build a (free) add-on that alters so that a quick search result displays the results as threads.

I believe that the public function actionSearch() in \library\XenForo\ControllerPublic\Search.php is the place to do the modification. If I insert the following code at line 201 I believe it works as desired.
Code:
$input['group_discussion'] = 1;
$input['type'] = 'post';

But I can't see how I can do the modification without copying the whole function which wouldn't be a nice thing to do of course. I've been looking into altering the public function searchGeneral in \library\XenForo\Search\Searcher.php instead. It's not many lines of code there and by creating a "typeHandler" I believe I can call the public function searchType instead. I had some problem creating a "typeHandler" though... I'm also not sure if it's a good idea or not.

Please if you have the knowledge how to best implement this, give me a hint.
 
XF Enhanced Search does something along these lines to default the sort order to relevance. It uses an extended controller class and does this:
Code:
public function actionSearch()
{
   if (
      !$this->_request->getParam('order')
      && XenForo_Application::get('options')->enableElasticsearch
   )
   {
      $this->_request->setParam('order', XenForo_Application::getOptions()->esDefaultSearchOrder);
   }

   return parent::actionSearch();
}
Hopefully that demonstrates the concept of approach.
 
XF Enhanced Search does something along these lines to default the sort order to relevance. It uses an extended controller class and does this:
Hopefully that demonstrates the concept of approach.

Thanks @Mike It sure does! It will help me a lot.
 
Back
Top Bottom