I've spent most of today doing it - going off the basic idea in orbans thread. I think I've listed every change I made.
The first bit in sphinx.conf is replace pagetext in the two post queries with this:
Code:
concat(pagetext,' username_', post.username,' startername_',thread.postusername)
You basically get then instead of just "message", "message username_myname startername_hisname" in your sphinx index.
Then you edit your search.php, find this block of code:
Code:
if ($vbulletin->GPC['userid'] AND $userinfo = fetch_userinfo($vbulletin->GPC['userid']))
{
$vbulletin->GPC_exists['searchuser'] = true;
$vbulletin->GPC['searchuser'] = unhtmlspecialchars($userinfo['username']);
}
and add this after it:
Code:
// If username does not exist, skip sphinx and let the normal search routine spit it out
if ($testuser = $db->query_first_slave("SELECT userid, username, posts FROM " . TABLE_PREFIX . "user WHERE username = '" . $vbulletin->GPC['searchuser'] . "'")){
if ($vbulletin->GPC['searchuser'] != '') {
if ($vbulletin->GPC['starteronly']) {
$vbulletin->GPC['query'] = $vbulletin->GPC['query'] . ' startername_' . $vbulletin->GPC['searchuser'];
}
else {
$vbulletin->GPC['query'] = $vbulletin->GPC['query'] . ' username_' . $vbulletin->GPC['searchuser'];
}
$vbulletin->GPC['searchuser'] = '';
}
}
That will basically do it - your faking a keyword search from your user search. If the search is not exact, it goes on to the standard vbulletin search, if the username does not exist it goes on to the standard vbulletin search.
To tidy it up I added after
Code:
$displayWords = '<b><u>' . implode('</u></b>, <b><u>', $display['words']) . '</u></b>';
Code:
$displayWords = str_replace('username_','', $displayWords);
$displayWords = str_replace('startername_','', $displayWords);
To hide what it really just searched on.
I chose to not allow partial name matches (unticking exact match) as it's not that useful and can tip you over the edge if the server is heavily loaded already. To stop members using it but still allow moderators and so on I added this modification to the search template:
Code:
<if condition="is_member_of($bbuserinfo, 5, 6, 7)">
<label for="cb_exactname"><input type="checkbox" name="exactname" value="1" id="cb_exactname" $exactnamechecked[1] />$vbphrase[exact_name]</label>
<else />
<input type="hidden" name="exactname" value="1">
</if>
So if you aren't an admin or moderator the exact name is always on.
I also changed this in the postbit template:
Code:
<if condition="$show['search']">
<tr><td class="vbmenu_option"><a href="search.php?$session[sessionurl]do=finduser&u=$post[userid]" rel="nofollow"><phrase 1="$post[username]">$vbphrase[find_more_posts_by_x]</phrase></a></td></tr>
</if>
to
Code:
<if condition="$show['search']">
<tr><td class="vbmenu_option"><a href="search.php?$session[sessionurl]do=process&searchuser=$post[username]&u=$post[userid]" rel="nofollow"><phrase 1="$post[username]">$vbphrase[find_more_posts_by_x]</phrase></a></td></tr>
</if>
basically changing the do= to process and adding searchuser=username. This forces the search.php into the same sphinx search when somebody clicks 'find more posts by xxxx'.