MyBB Community Forums

Full Version: Fix for Similar Threads Problem
You're currently viewing a stripped down version of our content. View the full version with proper formatting.
Pages: 1 2
I dunno if this is still a problem, I was reading some threads on here that some users were still having the problem with similar threads not returning any results no matter what setting they used like as low as a 1 relevancy rating.

I have a fix for this problem but I need to know if it is ok for me to post a snippet of the original code on this forum? I have altered the original only slight to get this function to work correctly and am more than happy to share the fix. I am new to this forum and am not aware of all the rules.

Is it ok for me to post the code here? IF not I can email the fix to the appropriate coders on this forum.

let me know,
The Doctor
You can post your proposed fix here; No guarantee we'll include it though.
cool. ok, it looks like the problem is that the db query is going after an exact match rather than a similar match. Simple fix, just go with a blind query expansion by including the statement WITH QUERY EXPANSION.

open showthread.php and look for
	// Show the similar threads table if wanted.
	if($mybb->settings['showsimilarthreads'] != "no")
	{
		$query = $db->query("
			SELECT t.*, t.username AS threadusername, u.username, MATCH (t.subject) AGAINST ('".$db->escape_string($thread['subject'])."') AS relevance
			FROM ".TABLE_PREFIX."threads t
			LEFT JOIN ".TABLE_PREFIX."users u ON (u.uid = t.uid)
			WHERE t.fid='{$thread['fid']}' AND t.tid!='{$thread['tid']}' AND t.visible='1' AND t.closed NOT LIKE 'moved|%' AND MATCH (t.subject) AGAINST ('".$db->escape_string($thread['subject'])."') >= '{$mybb->settings['similarityrating']}'
			ORDER BY t.lastpost DESC
			LIMIT 0, {$mybb->settings['similarlimit']}
		");

Replace with
// Show the similar threads table if wanted.
	if($mybb->settings['showsimilarthreads'] != "no")
	{
		$query = $db->query("
			SELECT t.*, t.username AS threadusername, u.username, MATCH (t.subject) AGAINST ('".$db->escape_string($thread['subject'])."' WITH QUERY EXPANSION) AS relevance
			FROM ".TABLE_PREFIX."threads t
			LEFT JOIN ".TABLE_PREFIX."users u ON (u.uid = t.uid)
			WHERE t.fid='{$thread['fid']}' AND t.tid!='{$thread['tid']}' AND t.visible='1' AND t.closed NOT LIKE 'moved|%' AND MATCH (t.subject) AGAINST ('".$db->escape_string($thread['subject'])."' WITH QUERY EXPANSION) >= '{$mybb->settings['similarityrating']}'
			ORDER BY t.lastpost DESC
			LIMIT 0, {$mybb->settings['similarlimit']}
		");

I included the entire subroutine in case someone else would like to expand on this. This is not a perfect fix but it works and that beats not working any day Wink
So basically "WITH QUERY EXPANSION" allows MySQL to use the query as a whole behaving as a single ambiguous "term"; i.e., conveying multiple meanings.

Am I correct?
sort of ...

here is the definition from the manual
Blind query expansion (also known as automatic relevance feedback) is enabled by adding WITH QUERY EXPANSION following the search phrase. It works by performing the search twice, where the search phrase for the second search is the original search phrase concatenated with the few most highly relevant documents from the first search. Thus, if one of these documents contains the word “databases” and the word “MySQL”, the second search finds the documents that contain the word “MySQL” even if they do not contain the word “database”.
What do you think of this fix Tiki?
Not sure. It looks like it'll work, but I'm not sure how it would affect server load and it also returns result that may not even by equivalent to the thread.
problem is the program is pulling the relevant data from the thread title rather than the "post message" so there isn't much to compare. It would work way better using the post message but that would require much more of a drain on the server load.

One of those things that makes you go hmmm, lol
This will be included in 1.4
that's great Tikitiki, feels nice to have participated in such a wonderful program even if it was an extremely small part, lol. I am really glad you decided to go with the suggestion. I have nothing but good things to say about the mybb bulletin board, it exceeds all the rest by lightyears.
Pages: 1 2