Go Back   vb.org Archive > vBulletin Modifications > Archive > vB.org Archives > General > Big Board Discussions
FAQ Community Calendar Today's Posts Search

Reply
 
Thread Tools
Hacking up Search by Username Details »»
Hacking up Search by Username
Version: , by Rayn21 Rayn21 is offline
Developer Last Online: Feb 2013 Show Printable Version Email this Page

Version: Unknown Rating:
Released: 02-06-2007 Last Update: Never Installs: 0
 
No support by the author.

I have replaced vBulleting's internal fulltext search with one powered by the Sphinx engine. It works fantastic.

It does not work for search for all threads started by user and search for posts by user.

We have a post table of over 8 million posts, and the table locking has caused significant delays for the website. We've had to disable search.

I'm ready for drastic measures. Anyone have advice?

Show Your Support

  • This modification may not be copied, reproduced or published elsewhere without author's permission.

Comments
  #2  
Old 02-09-2007, 12:26 PM
fastforward fastforward is offline
 
Join Date: Oct 2001
Location: NC, USA
Posts: 399
Благодарил(а): 0 раз(а)
Поблагодарили: 0 раз(а) в 0 сообщениях
Default

Quote:
Originally Posted by Rayn21 View Post
I have replaced vBulleting's internal fulltext search with one powered by the Sphinx engine. It works fantastic.

It does not work for search for all threads started by user and search for posts by user.

We have a post table of over 8 million posts, and the table locking has caused significant delays for the website. We've had to disable search.

I'm ready for drastic measures. Anyone have advice?
This post references that issue.
https://vborg.vbsupport.ru/showthrea...er#post1150437

Use the latest code provided by orban in that thread. The search by user works fine for me.
Reply With Quote
  #3  
Old 05-08-2007, 08:11 PM
Rayn21 Rayn21 is offline
 
Join Date: Sep 2005
Posts: 9
Благодарил(а): 0 раз(а)
Поблагодарили: 0 раз(а) в 0 сообщениях
Default

If you are using orban's code, it uses the regular vb searching for keywordless username searches and sphinx for everything else. If you have a smaller post table, you may not notice problems with it. Unfortunately, I had to remove anything that didn't use sphinx because my post table is a monster.

Regarding adding that keyword, that would require modification of orban's code as well as search.php; I don't have enough grasp on the code to make those modifications.
Reply With Quote
  #4  
Old 08-27-2007, 04:19 PM
telescopi telescopi is offline
 
Join Date: Sep 2002
Posts: 5
Благодарил(а): 0 раз(а)
Поблагодарили: 0 раз(а) в 0 сообщениях
Default

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&amp;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&amp;searchuser=$post[username]&amp;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'.
Reply With Quote
  #5  
Old 08-31-2007, 09:41 AM
Jah-Hools Jah-Hools is offline
 
Join Date: Jul 2007
Posts: 214
Благодарил(а): 0 раз(а)
Поблагодарили: 0 раз(а) в 0 сообщениях
Default

Can I ask why you wanted to replace fulltext?

Thanks,
Reply With Quote
  #6  
Old 09-03-2007, 08:12 AM
telescopi telescopi is offline
 
Join Date: Sep 2002
Posts: 5
Благодарил(а): 0 раз(а)
Поблагодарили: 0 раз(а) в 0 сообщениях
Default

As the OP says - locking.

Sphinx search avoids all locking issues because it is not a part of mysql, it also helps that it is lightning fast - sub 1 second results whewre fulltext would have taken 20 seconds or more.

You also reduce the size of your database substantially as you can drop the fulltext index on the post table, this means mysql can devote it's memory to more useful indexes.
Reply With Quote
  #7  
Old 10-24-2007, 04:10 PM
jawatkin jawatkin is offline
 
Join Date: Apr 2007
Posts: 61
Благодарил(а): 0 раз(а)
Поблагодарили: 0 раз(а) в 0 сообщениях
Default

Quote:
Originally Posted by telescopi View Post
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.
Thank you very much for this. This not being able to search by name via Sphinx has been the only thing holding me back from putting the time into implementing it. Rapidly coming up on 2M posts and the searches are locking up mySQL during peak times.

EDIT: This works REALLY great. Will avoid the locking that I've been experiencing and the users will be happier with faster searches!
Reply With Quote
  #8  
Old 10-26-2007, 01:28 AM
jawatkin jawatkin is offline
 
Join Date: Apr 2007
Posts: 61
Благодарил(а): 0 раз(а)
Поблагодарили: 0 раз(а) в 0 сообщениях
Default

Quote:
Originally Posted by telescopi View Post
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&amp;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&amp;searchuser=$post[username]&amp;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'.
This didn't quite give me the desired effect (at least not the default of find more posts for user). What it gave was a partial name search and returned it as threads. I changed it to the following and it gives the desired effect:

Code:
<if condition="$show['search']">
		<tr><td class="vbmenu_option"><a href="search.php?$session[sessionurl]do=process&amp;showposts=1&amp;exactname=1&amp;u=$post[userid]&amp;searchuser=$post[username]" rel="nofollow"><phrase 1="$post[username]">$vbphrase[find_more_posts_by_x]</phrase></a></td></tr>
	</if>
Reply With Quote
  #9  
Old 11-01-2007, 04:41 PM
mute mute is offline
 
Join Date: Dec 2002
Location: Phoenixville, PA
Posts: 152
Благодарил(а): 0 раз(а)
Поблагодарили: 0 раз(а) в 0 сообщениях
Default

Hmm. This looks promising. My search.php is so old (we're still running 3.6.2+patches), that I don't have that bit of code in mine. I'll have to see if I can get 3.6.8's running on our install.

--------------- Added [DATE]1193940945[/DATE] at [TIME]1193940945[/TIME] ---------------

I've found a minor bug.

I've gotten this up and running, but searches on my site for say.. "Kyle" also pull up posts for the user "Kyle=agglicious".

I'm also seeing really weird results when searching for all threads by users, but I have yet to track the source of the problem down.
Reply With Quote
  #10  
Old 11-02-2007, 04:57 PM
mute mute is offline
 
Join Date: Dec 2002
Location: Phoenixville, PA
Posts: 152
Благодарил(а): 0 раз(а)
Поблагодарили: 0 раз(а) в 0 сообщениях
Default

Ok, so I've done a bit more investigation.

When I have the search.php blurb in that concats the startername_Username or username_Username bits to the search query, the results returned are really wonky.

We limit search results to 500 results. If I have this code running, and search for threads created by myself, I only get 27 results back ranging back about 2 months, as opposed to the full range.

If i search via the command line client, I get many more results:

[root@db2 ~]# search -c sphinx.conf startername_Kyle|grep index
index 'vbpost': query 'startername_Kyle ': returned 1000 matches of 2854 total in 0.005 sec
index 'vbpostarchived': query 'startername_Kyle ': returned 1000 matches of 4882 total in 0.012 sec
index 'vbpostdelta': query 'startername_Kyle ': returned 1 matches of 1 total in 0.000 sec
index 'vbthread': query 'startername_Kyle ': returned 0 matches of 0 total in 0.000 sec
index 'vbthreaddelta': query 'startername_Kyle ': returned 0 matches of 0 total in 0.000 sec

If I comment out the code and let the normal search run, it works as it should. Furthermore, I'm not entirely sure why you are running an additional query rather than just using fetch_userinfo() in the if statement that wraps this code.

Has anyone else run into these issues? I'm going to troubleshoot some more, but so far I'm not able to get this code working as the OP said it should.
Reply With Quote
Reply


Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump


All times are GMT. The time now is 01:49 AM.


Powered by vBulletin® Version 3.8.12 by vBS
Copyright ©2000 - 2024, vBulletin Solutions Inc.
X vBulletin 3.8.12 by vBS Debug Information
  • Page Generation 0.05039 seconds
  • Memory Usage 2,307KB
  • Queries Executed 23 (?)
More Information
Template Usage:
  • (1)SHOWTHREAD
  • (1)ad_footer_end
  • (1)ad_footer_start
  • (1)ad_header_end
  • (1)ad_header_logo
  • (1)ad_navbar_below
  • (1)ad_showthread_beforeqr
  • (11)bbcode_code
  • (3)bbcode_quote
  • (1)footer
  • (1)forumjump
  • (1)forumrules
  • (1)gobutton
  • (1)header
  • (1)headinclude
  • (1)modsystem_post
  • (1)navbar
  • (6)navbar_link
  • (120)option
  • (10)post_thanks_box
  • (10)post_thanks_button
  • (1)post_thanks_javascript
  • (1)post_thanks_navbar_search
  • (10)post_thanks_postbit_info
  • (9)postbit
  • (10)postbit_onlinestatus
  • (10)postbit_wrapper
  • (1)spacer_close
  • (1)spacer_open
  • (1)tagbit_wrapper 

Phrase Groups Available:
  • global
  • inlinemod
  • postbit
  • posting
  • reputationlevel
  • showthread
Included Files:
  • ./showthread.php
  • ./global.php
  • ./includes/init.php
  • ./includes/class_core.php
  • ./includes/config.php
  • ./includes/functions.php
  • ./includes/class_hook.php
  • ./includes/modsystem_functions.php
  • ./includes/functions_bigthree.php
  • ./includes/class_postbit.php
  • ./includes/class_bbcode.php
  • ./includes/functions_reputation.php
  • ./includes/functions_post_thanks.php 

Hooks Called:
  • init_startup
  • init_startup_session_setup_start
  • init_startup_session_setup_complete
  • cache_permissions
  • fetch_threadinfo_query
  • fetch_threadinfo
  • fetch_foruminfo
  • style_fetch
  • cache_templates
  • global_start
  • parse_templates
  • global_setup_complete
  • showthread_start
  • showthread_getinfo
  • forumjump
  • showthread_post_start
  • showthread_query_postids
  • showthread_query
  • bbcode_fetch_tags
  • bbcode_create
  • showthread_postbit_create
  • postbit_factory
  • postbit_display_start
  • post_thanks_function_post_thanks_off_start
  • post_thanks_function_post_thanks_off_end
  • post_thanks_function_fetch_thanks_start
  • post_thanks_function_fetch_thanks_end
  • post_thanks_function_thanked_already_start
  • post_thanks_function_thanked_already_end
  • fetch_musername
  • postbit_imicons
  • bbcode_parse_start
  • bbcode_parse_complete_precache
  • bbcode_parse_complete
  • postbit_display_complete
  • post_thanks_function_can_thank_this_post_start
  • tag_fetchbit_complete
  • forumrules
  • navbits
  • navbits_complete
  • showthread_complete