Extending the search for "Find all content by ...", but I'm a little stuck

Marcel

Active member
I put up a thread about this before but I'm not sure I was completely clear. I hope someone knows the answer this time!

I'm trying to build upon the function "Find all content by ... ", which is very similar to what I want to do.

I want to find all posts by the current user, but only display the results as threads....

So...if I was to run it on XenForo, for example, it would show this thread in the search results,
but it would also show this thread in the results too. https://xenforo.com/community/threads/weekly-digest.86791/
Although I didnt start the thread, it would be included in the list because I posted in it.

Does that make sense? I'm trying to build a 'Threads you've participated in" search for our users.
I've extended ControllerPublic_Search, inparticular modifying my actionParticipated() off the actionMember() function, but I'm now stuck.

The code in actionMember() goes down a rabbit hole of search handlers and stuff I'm really unsure of.

Would it be easier to completely build my own model to pull the data from the Database?
 
Personally I'd make my own query. Something like this...
Code:
return $this->_getDb()->fetchAll('
           SELECT DISTINCT thread.thread_id, thread.title
           FROM xf_post as post
           INNER JOIN xf_thread as thread ON
           (thread.thread_id = post.thread_id)
           WHERE post.user_id = ' . $user_id
       );
 
Sort of, but no. The 'Your content' shows a list of exactly that, your actual content. It's too 'busy'.
I want to perform a similar search but show the results as a thread list, regardless of who started the particular thread.

It's a list of threads you've posted in, complete with "New post" indicators etc, so you can quickly catch up on discussions you've recently been involved in.

Is that a bit clearer? I'm struggling to find the right words :D
 
Actually, I think I've found a way of doing it without building my own model.

Using $searcher->searchType and setting 'groupByDiscussion' to True?
 
I *think* I've figured it out now, using Model_Search=>searchType
It seems to work on my test forum.....so far.

Here's the relevant code for actionParticipated
Code:
        $userId = XenForo_Visitor::getUserId();
        $user = $this->_getUserModel()->getUserById($userId);
       
        $searchModel = $this->_getSearchModel();
        $searcher = new XenForo_Search_Searcher($searchModel);
           
        $typeHandler = $this->_getSearchModel()->getSearchDataHandler('post');
        $constraints = array('titles_only' => true, 'user'=> true, 'user_id' => $userId);
       
        $results = $searcher->searchType($typeHandler, null, $constraints, null, true, null);
       
        if (!$results)
        {
            return $this->getNoSearchResultsResponse($searcher);
        }
       
        $warnings = $searcher->getErrors() + $searcher->getWarnings();
       
        $search = $searchModel->insertSearch($results, 'participated', null, $constraints, 'date', true, array(), $warnings, $userId);
       
        return    $this->responseRedirect(
                XenForo_ControllerResponse_Redirect::SUCCESS,
                XenForo_Link::buildPublicLink('search', $search),
                ''
                );
        }
        }


Is there anything glaringly stupid that I've done wrong or missed?
 
Your "user" constraint should be the user ID I believe, but otherwise I think it looks correct and if it works... :)
 
Top Bottom