Go Back   vb.org Archive > vBulletin 3 Discussion > vB3 General Discussions
FAQ Community Calendar Today's Posts Search

 
 
Thread Tools Display Modes
Prev Previous Post   Next Post Next
  #1  
Old 05-12-2006, 11:33 AM
Oreamnos's Avatar
Oreamnos Oreamnos is offline
 
Join Date: Dec 2004
Posts: 130
Благодарил(а): 0 раз(а)
Поблагодарили: 0 раз(а) в 0 сообщениях
Default Using the build_post_index function

I want to call this function from functions_databuild.php to update the search index but im a little nervous about doing so. I've looked through this but i don't really understand a few of the queries.

So my question, am i safe to run this as long as the appropriate parameters are set in the function? Will all this do is update my search index?

thanks
eric

PHP Code:
// ###################### Start indexpost #######################
function build_post_index($postid$foruminfo$firstpost = -1$post false)
{
    global 
$vbulletin;

    if (
$vbulletin->options['fulltextsearch'])
    {
        return;
    }

    if (
$foruminfo['indexposts'])
    {
        global 
$vbulletin;
        static 
$firstpst;

        if (
is_array($post))
        {
            if (isset(
$post['threadtitle']))
            {
                
$threadinfo = array('title' => $post['threadtitle']);
            }
        }
        else
        {
            
$post $vbulletin->db->query_first("
                SELECT postid, post.title, pagetext, post.threadid, thread.title AS threadtitle
                FROM " 
TABLE_PREFIX "post AS post
                INNER JOIN " 
TABLE_PREFIX "thread AS thread USING(threadid)
                WHERE postid = 
$postid
            "
);
            
$threadinfo = array('title' => $post['threadtitle']);
        }

        if (isset(
$firstpst["$post[threadid]"]))
        {
            if (
$firstpst["$post[threadid]"] == $postid)
            {
                
$firstpost 1;
            }
            else
            {
                
$firstpost 0;
            }
        }

        if (
$firstpost == -1)
        {
            
$getfirstpost $vbulletin->db->query_first("
                SELECT MIN(postid) AS postid
                FROM " 
TABLE_PREFIX "post
                WHERE threadid = " 
intval($post['threadid'])
            );
            if (
$getfirstpost['postid'] == $postid)
            {
                
$firstpost 1;
            }
            else
            {
                
$firstpost 0;
            }
        }


        
$allwords '';

        if (
$firstpost)
        {
            if (!
is_array($threadinfo))
            {
                
$threadinfo $vbulletin->db->query_first("
                    SELECT title
                    FROM " 
TABLE_PREFIX "thread
                    WHERE threadid = 
$post[threadid]
                "
);
            }

            
$firstpst["$post[threadid]"] = $postid;

            
$words fetch_postindex_text($threadinfo['title']);
            
$allwords .= $words;
            
$wordarray explode(' '$words);
            foreach (
$wordarray AS $word)
            {
                
#$scores["$word"] += $vbulletin->options['threadtitlescore'];
                
$intitle["$word"] = 2;
                
$scores["$word"]++;
            }
        }

        
$words fetch_postindex_text($post['title']);
        
$allwords .= ' ' $words;
        
$wordarray explode(' '$words);

        foreach (
$wordarray AS $word)
        {
            
#$scores["$word"] += $vbulletin->options['posttitlescore'];
            
if (empty($intitle["$word"]))
            {
                
$intitle["$word"] = 1;
            }
            
$scores["$word"]++;
        }

        
$words fetch_postindex_text($post['pagetext']);
        
$allwords .= ' ' $words;
        
$wordarray explode(' '$words);
        foreach (
$wordarray AS $word)
        {
            
$scores["$word"]++;
        }

        
$getwordidsql "title IN ('" str_replace(" ""','"$allwords) . "')";
        
$words $vbulletin->db->query_read("SELECT wordid, title FROM " TABLE_PREFIX "word WHERE $getwordidsql");
        while (
$word $vbulletin->db->fetch_array($words))
        {
            
$word['title'] = vbstrtolower($word['title']);
            
$wordcache["$word[title]"] = $word['wordid'];
        }
        
$vbulletin->db->free_result($words);

        
$insertsql '';
        
$newwords '';
        
$newtitlewords '';

        foreach (
$scores AS $word => $score)
        {
            if (!
is_index_word($word))
            {
                unset(
$scores["$word"]);
                continue;
            }

            
// prevent score going over 255 for overflow control
            
if ($score 255)
            {
                
$scores["$word"] = 255;
            }
            
// make sure intitle score is set
            
$intitle["$word"] = intval($intitle["$word"]);

            if (
$word)
            {
                if (isset(
$wordcache["$word"]))
                { 
// Does this word already exist in the word table?
                    
$insertsql .= ", (" $vbulletin->db->escape_string($wordcache["$word"]) . ", $postid$score$intitle[$word])"// yes so just add a postindex entry for this post/word
                    
unset($scores["$word"], $intitle["$word"]);
                }
                else
                {
                    
$newwords .= $word ' '// No so add it to the word table
                
}
            }
        }

        if (!empty(
$insertsql))
        {
            
$insertsql substr($insertsql1);
            
/*insert query*/
            
$vbulletin->db->query_write("
                REPLACE INTO " 
TABLE_PREFIX "postindex
                (wordid, postid, score, intitle)
                VALUES
                
$insertsql
            "
);
        }

        
$newwords trim($newwords);
        if (
$newwords)
        {
            
$insertwords "('" str_replace(" ""'),('"$newwords) . "')";
            
/*insert query*/
            
$vbulletin->db->query_write("INSERT IGNORE INTO " TABLE_PREFIX "word (title) VALUES $insertwords");
            
$selectwords "title IN ('" str_replace(" ""','"$newwords) . "')";

            
$scoressql 'CASE title';
            foreach (
$scores AS $word => $score)
            {
                
$scoressql .= " WHEN '" $vbulletin->db->escape_string($word) . "' THEN $score";
            }
            
$scoressql .= ' ELSE 1 END';

            
$titlesql 'CASE title';
            foreach(
$intitle AS $word => $intitlescore)
            {
                
$titlesql .= " WHEN '" $vbulletin->db->escape_string($word) . "' THEN $intitlescore";
            }
            
$titlesql .= ' ELSE 0 END';

            
/*insert query*/
            
$vbulletin->db->query_write("
                INSERT IGNORE INTO " 
TABLE_PREFIX "postindex
                (wordid, postid, score, intitle)
                SELECT DISTINCT wordid, 
$postid$scoressql$titlesql
                FROM " 
TABLE_PREFIX "word
                WHERE 
$selectwords
            "
);
        }
    }

Reply With Quote
 


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 12:01 AM.


Powered by vBulletin® Version 3.8.12 by vBS
Copyright ©2000 - 2025, vBulletin Solutions Inc.
X vBulletin 3.8.12 by vBS Debug Information
  • Page Generation 0.03373 seconds
  • Memory Usage 2,478KB
  • Queries Executed 13 (?)
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
  • (1)bbcode_php
  • (1)footer
  • (1)forumjump
  • (1)forumrules
  • (1)gobutton
  • (1)header
  • (1)headinclude
  • (1)navbar
  • (3)navbar_link
  • (120)option
  • (1)post_thanks_box
  • (1)post_thanks_button
  • (1)post_thanks_javascript
  • (1)post_thanks_navbar_search
  • (1)post_thanks_postbit_info
  • (1)postbit
  • (1)postbit_onlinestatus
  • (1)postbit_wrapper
  • (1)showthread_list
  • (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_threadedmode.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_threaded
  • showthread_threaded_construct_link
  • 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