XF 2.2 Question in search threads by titles

AndrewSimm

Well-known member
I am working on a add-on that is more a less a player database. I would like to display a list of recent threads posted about the particular player on the profile page, which is also a part of my add-on. My question is, how should I approach pulling threads that contain the players names? I know the code below works, but I am sure there is a much more efficient way to generate this list.

Any suggestions on how this should be done?

PHP:
$fullname_thread_search = "%" . $player->fullname . "%";
$repo = $this->repository('XF:Thread');
$finder = $repo->findLatestThreads();
$threads = $finder->where('title','like', $fullname_thread_search)
    ->with("Forum.Node.Permissions|{$visitor->permission_combination_id}")
    ->fetch(10);
 
There isn't really a more efficient way to do this unless you have a means of storing the player name in a structured way. A tag or custom field could theoretically work (though I'd have to check how these might actually be accessed through the finder system). This would likely require a reapproach to things.

Roughly speaking, I'd probably say that if it works and you don't have a ton of data, performance may not be worth caring about too much. You could also go about caching these results as well, if you find they're getting hit a lot.
 
Back
Top Bottom