vb.org Archive

vb.org Archive (https://vborg.vbsupport.ru/index.php)
-   vB3 General Discussions (https://vborg.vbsupport.ru/forumdisplay.php?f=111)
-   -   Using the build_post_index function (https://vborg.vbsupport.ru/showthread.php?t=115367)

Oreamnos 05-12-2006 10:33 AM

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
            "
);
        }
    }




All times are GMT. The time now is 08:45 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.01752 seconds
  • Memory Usage 1,801KB
  • Queries Executed 10 (?)
More Information
Template Usage:
  • (1)ad_footer_end
  • (1)ad_footer_start
  • (1)ad_header_end
  • (1)ad_header_logo
  • (1)ad_navbar_below
  • (1)bbcode_php_printable
  • (1)footer
  • (1)gobutton
  • (1)header
  • (1)headinclude
  • (6)option
  • (1)post_thanks_navbar_search
  • (1)printthread
  • (1)printthreadbit
  • (1)spacer_close
  • (1)spacer_open 

Phrase Groups Available:
  • global
  • postbit
  • showthread
Included Files:
  • ./printthread.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/class_bbcode_alt.php
  • ./includes/class_bbcode.php
  • ./includes/functions_bigthree.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
  • printthread_start
  • bbcode_fetch_tags
  • bbcode_create
  • bbcode_parse_start
  • bbcode_parse_complete_precache
  • bbcode_parse_complete
  • printthread_post
  • printthread_complete