function fetch_keywords_list($threadinfo, $pagetext = '') { global $vbphrase, $vbulletin; require_once DIR . '/includes/functions_search.php'; require_once DIR . '/includes/class_taggablecontent.php'; $keywords = vB_Taggable_Content_Item::filter_tag_list($threadinfo['taglist'], $errors, false); if (!empty($threadinfo['prefixid'])) { $prefix = $vbphrase["prefix_{$threadinfo['prefixid']}_title_plain"]; $keywords[] = trim($prefix); } if (!empty($pagetext)) { // title has already been htmlspecialchar'd, pagetext has not $words = fetch_postindex_text(unhtmlspecialchars($threadinfo['title']) . ' ' . $pagetext); $wordarray = split_string($words); $sorted_counts = array_count_values($wordarray); arsort($sorted_counts); require DIR . '/includes/searchwords.php'; // get the stop word list; allow multiple requires $badwords = array_merge($badwords, preg_split('/\\s+/s', $vbulletin->options['badwords'], -1, PREG_SPLIT_NO_EMPTY)); foreach ($sorted_counts as $word => $count) { $word = trim($word); if (in_array(vbstrtolower($word), $badwords)) { continue; } if (vbstrlen($word) <= $vbulletin->options['minsearchlength'] and !in_array(vbstrtolower($word), $goodwords)) { continue; } $word = htmlspecialchars_uni($word); if (!in_array($word, $keywords)) { $keywords[] = $word; } if (sizeof($keywords) >= 50) { break; } } } return implode(', ', $keywords); }
function fetch_similar_threads($threadtitle, $threadid = 0) { global $vbulletin; if ($vbulletin->options['fulltextsearch']) { $hook_query_joins = $hook_query_where = ''; ($hook = vBulletinHook::fetch_hook('search_similarthreads_fulltext')) ? eval($hook) : false; $safetitle = $vbulletin->db->escape_string($threadtitle); $threads = $vbulletin->db->query_read_slave("\n\t\t\tSELECT thread.threadid, MATCH(thread.title) AGAINST ('{$safetitle}') AS score\n\t\t\tFROM " . TABLE_PREFIX . "thread AS thread\n\t\t\t{$hook_query_joins}\n\t\t\tWHERE MATCH(thread.title) AGAINST ('{$safetitle}')\n\t\t\t\tAND thread.open <> 10\n\t\t\t\t" . iif($threadid, " AND thread.threadid <> {$threadid}") . "\n\t\t\t\t{$hook_query_where}\n\t\t\tLIMIT 5\n\t\t"); while ($thread = $vbulletin->db->fetch_array($threads)) { // this is an arbitrary number but items less then 4 - 5 seem to be rather unrelated if ($thread['score'] > 4) { $similarthreads .= ", {$thread['threadid']}"; } } $vbulletin->db->free_result($threads); return substr($similarthreads, 2); } // take out + and - because they have special meanings in a search $threadtitle = str_replace('+', ' ', $threadtitle); $threadtitle = str_replace('-', ' ', $threadtitle); $threadtitle = fetch_postindex_text(trim($threadtitle)); $retval = getsearchposts($threadtitle, 0); if (!$retval or sizeof($retval['scores']) == 0) { return ''; } if (sizeof($retval['scores']) < 20000) { // this version seems to die on the sort when a lot of posts are return arsort($retval['scores']); // biggest scores first foreach ($retval['scores'] as $postid => $score) { if ($score / $retval['searchables'] < $vbulletin->options['similarthreadthreshold'] or $numposts >= $vbulletin->options['maxresults']) { break; } else { $similarposts .= ', ' . intval($postid); $numposts++; } } } else { $scorelist = array(); $postlist = array(); $maxarrsize = min(40, sizeof($retval['scores'])); for ($i = 0; $i < $maxarrsize; $i++) { $scorelist[$i] = -1; $postlist[$i] = 0; } foreach ($retval['scores'] as $postid => $score) { if ($score / $retval['searchables'] < $vbulletin->options['similarthreadthreshold']) { continue; } $arraymin = min($scorelist); if ($score > $arraymin) { $i = 0; foreach ($scorelist as $thisscore) { if ($thisscore == $arraymin) { $scorelist["{$i}"] = $score; $postlist["{$i}"] = $postid; break; } $i++; } } } foreach ($postlist as $postid) { if ($postid) { $numposts++; $similarposts .= ', ' . intval($postid); } } } if ($numposts == 0) { return ''; } $sim = $vbulletin->db->query_read_slave("\n\t\tSELECT DISTINCT thread.threadid\n\t\tFROM " . TABLE_PREFIX . "post AS post\n\t\tINNER JOIN " . TABLE_PREFIX . "thread AS thread ON (thread.threadid = post.threadid)\n\t\tWHERE postid IN (0{$similarposts}) " . iif($threadid, " AND post.threadid <> {$threadid}") . "\n\t\tORDER BY ({$numposts} - FIELD(post.postid {$similarposts} )) DESC\n\t\tLIMIT 5\n\t"); $similarthreads = ''; while ($simthrd = $vbulletin->db->fetch_array($sim)) { $similarthreads .= ", {$simthrd['threadid']}"; } $vbulletin->db->free_result($sim); return substr($similarthreads, 2); }
/** * Prepare meta description to use first 20 keywords of the artile if it's not set. See bug #30456 */ protected function prepareFields() { parent::prepareFields(); if ((empty($this->set_fields['description']) OR $this->set_fields['description'] == (string) new vB_Phrase('vbcms', 'new_article')) AND !empty($this->type_set_fields['pagetext'])) { require_once(DIR . '/includes/functions_databuild.php'); $words = fetch_postindex_text($this->type_set_fields['pagetext']); $wordarray = split_string($words); $scores = array(); foreach ($wordarray AS $word) { if (!is_index_word($word)) { continue; } $scores[$word]++; } // Sort scores arsort($scores, SORT_NUMERIC); $scores = array_slice($scores, 0, 10, true); $this->set_fields['description'] = ''; foreach ($scores as $k => $v) { $this->set_fields['description'] .= $k . ' '; } $this->set_fields['description'] = trim($this->set_fields['description']); } }
function delete_post_index($postid, $title = '', $pagetext = '') { global $vbulletin; if ($vbulletin->options['fulltextsearch']) { return; } $postid = intval($postid); // get the data if (empty($pagetext)) { $post = $vbulletin->db->query_first_slave("\n\t\t\tSELECT postid, threadid, title, pagetext\n\t\t\tFROM " . TABLE_PREFIX . "post\n\t\t\tWHERE postid = {$postid}\n\t\t"); } else { $post['postid'] = $postid; $post['title'] = $title; $post['pagetext'] = $pagetext; } // get word ids from table $allwords = $post['title'] . ' ' . $post['pagetext']; $allwords = fetch_postindex_text($allwords); $getwordidsql = "title IN ('" . str_replace(" ", "','", $allwords) . "')"; $words = $vbulletin->db->query_read_slave("SELECT wordid, title FROM " . TABLE_PREFIX . "word WHERE {$getwordidsql}"); if ($vbulletin->db->num_rows($words)) { $wordids = ''; while ($word = $vbulletin->db->fetch_array($words)) { $wordids .= ',' . $word['wordid']; } $vbulletin->db->query_write("DELETE FROM " . TABLE_PREFIX . "postindex WHERE wordid IN (0{$wordids}) AND postid = " . $post['postid']); } }