XF 1.1 Sort threads by last post when searching for threads by member

Calamity James

Active member
A user of one of my forums has pointed something out, I may be blind so if I'm missing a setting somewhere let me know.

If you search for threads started by one member, you only get two sort options, "Most Recent" and "Most Replies".

Most Recent seems to work a different way to vB, as in it orders by thread creation date as opposed to last post date.

For example,
Thread 1 created on May 1st 2012 with only 2 replies on the same day appears above
Thread 2 created on March 1st 2012 with hundreds of replies and the newest one half an hour ago.

Is there anyway to order it by last post time instead?

Cheers,
James.
 
the order is coming from XenForo_Search_SourceHandler_Abstract::getGeneralOrderClause


you could PROBABLY (i've made only some quick tests and it worked for me:) ) extend the default search handler (event search_source_create ) and overwrite
PHP:
public function getGeneralOrderClause($order)
{
        if ($order == 'date'){
                return array(
            array('thread', 'last_post_date','asc'));
        }
return parent::getGeneralOrderClause($order);
}
so the query is

SELECT search_index.content_type, search_index.content_id FROM xf_search_index AS search_index INNER JOIN xf_thread AS thread ON (thread.thread_id = search_index.discussion_id) WHERE MATCH(search_index.title, search_index.message, search_index.metadata) AGAINST (? IN BOOLEAN MODE) ORDER BY thread.last_post_date asc LIMIT 200


instead of


SELECT search_index.content_type, search_index.content_id FROM xf_search_index AS search_index WHERE MATCH(search_index.title, search_index.message, search_index.metadata) AGAINST (? IN BOOLEAN MODE) ORDER BY search_index.item_date desc LIMIT 200
 
Thanks for that ragtek, I'm pretty PHP savvy but I haven't got round to learning the ins and outs of extending XenForo yet, is there a tutorial that will help me out here, or something you can tell me? :)

Cheers,
James.
 
Top Bottom