|
From: Paul S. O. <ps...@us...> - 2001-11-23 01:04:34
|
Update of /cvsroot/phpbb/phpBB2
In directory usw-pr-cvs1:/tmp/cvs-serv14033
Modified Files:
posting.php search.php
Log Message:
Latest variants ... not finished yet ...
Index: posting.php
===================================================================
RCS file: /cvsroot/phpbb/phpBB2/posting.php,v
retrieving revision 1.104
retrieving revision 1.105
diff -C2 -r1.104 -r1.105
*** posting.php 2001/11/21 03:10:09 1.104
--- posting.php 2001/11/23 01:04:31 1.105
***************
*** 113,158 ****
$row = $db->sql_fetchrow($result);
! $common_threshold = floor($row['total_posts'] * $percent);
!
! $sql = "SELECT word_id
! FROM " . SEARCH_MATCH_TABLE . "
! $word_id_sql
! GROUP BY word_id
! HAVING COUNT(word_id) > $common_threshold";
! $result = $db->sql_query($sql);
! if( !$result )
{
! message_die(GENERAL_ERROR, "Couldn't obtain common word list", "", __LINE__, __FILE__, $sql);
! }
! if( $post_count = $db->sql_numrows($result) )
! {
! $common_word_id_list = array();
! while( $row = $db->sql_fetchrow($result) )
{
! $common_word_id_list[] = $row['word_id'];
}
! $db->sql_freeresult($result);
!
! if(count($common_word_ids) != 0)
{
! $common_word_id_list = implode(", ", $common_word_id_list);
!
! $sql = "UPDATE " . SEARCH_WORD_TABLE . "
! SET word_common = 1
! WHERE word_id IN ($common_word_id_list)";
! $result = $db->sql_query($sql);
! if( !$result )
{
! message_die(GENERAL_ERROR, "Couldn't delete word list entry", "", __LINE__, __FILE__, $sql);
}
! $sql = "DELETE FROM " . SEARCH_WORD_MATCH . "
! WHERE word_id IN ($common_word_id_list)";
! $result = $db->sql_query($sql);
! if( !$result )
{
! message_die(GENERAL_ERROR, "Couldn't delete word match entry", "", __LINE__, __FILE__, $sql);
}
}
--- 113,165 ----
$row = $db->sql_fetchrow($result);
! if( $row['total_posts'] > 100 )
{
! $common_threshold = floor($row['total_posts'] * $percent);
! $sql = "SELECT word_id
! FROM " . SEARCH_MATCH_TABLE . "
! $word_id_sql
! GROUP BY word_id
! HAVING COUNT(word_id) > $common_threshold";
! $result = $db->sql_query($sql);
! if( !$result )
{
! message_die(GENERAL_ERROR, "Couldn't obtain common word list", "", __LINE__, __FILE__, $sql);
}
! if( $word_count = $db->sql_numrows($result) )
{
! $common_word_id_list = array();
! while( $row = $db->sql_fetchrow($result) )
{
! $common_word_id_list[] = $row['word_id'];
}
! $db->sql_freeresult($result);
!
! if( count($common_word_ids) != 0 )
{
! $common_word_id_list = implode(", ", $common_word_id_list);
!
! $sql = "UPDATE " . SEARCH_WORD_TABLE . "
! SET word_common = " . TRUE . "
! WHERE word_id IN ($common_word_id_list)";
! $result = $db->sql_query($sql);
! if( !$result )
! {
! message_die(GENERAL_ERROR, "Couldn't delete word list entry", "", __LINE__, __FILE__, $sql);
! }
!
! $sql = "DELETE FROM " . SEARCH_WORD_MATCH . "
! WHERE word_id IN ($common_word_id_list)";
! $result = $db->sql_query($sql);
! if( !$result )
! {
! message_die(GENERAL_ERROR, "Couldn't delete word match entry", "", __LINE__, __FILE__, $sql);
! }
! }
! else
! {
! return 0;
}
}
***************
*** 162,279 ****
}
}
! return $words_removed;
}
! function remove_old_words($post_id)
{
! global $db, $phpbb_root_path, $board_config, $lang;
! $stopword_array = @file($phpbb_root_path . "language/lang_" . $board_config['default_lang'] . "/search_stopwords.txt");
! $synonym_array = @file($phpbb_root_path . "language/lang_" . $board_config['default_lang'] . "/search_synonyms.txt");
!
! $sql = "SELECT post_text
! FROM " . POSTS_TEXT_TABLE . "
! WHERE post_id = $post_id";
! if( $result = $db->sql_query($sql) )
{
! $row = $db->sql_fetchrow($result);
!
! $search_text = clean_words($row['post_text'], $stopword_array, $synonym_array);
! $search_matches = split_words($search_text);
!
! if( count($search_matches) )
! {
! $word = array();
! $word_count = array();
! $phrase_string = $text;
!
! $sql_in = "";
! for ($j = 0; $j < count($search_matches); $j++)
! {
! $this_word = strtolower(trim($search_matches[$j]));
!
! if( empty($word_count[$this_word]) )
! {
! $word_count[$this_word] = 1;
! }
! $new_word = true;
! for($k = 0; $k < count($word); $k++)
! {
! if( $this_word == $word[$k] )
! {
! $new_word = false;
! $word_count[$this_word]++;
! }
! }
! if( $new_word )
! {
! $word[] = $this_word;
! }
! }
! for($j = 0; $j < count($word); $j++)
{
! if( $word[$j] )
! {
! if( $sql_in != "" )
! {
! $sql_in .= ", ";
! }
! $sql_in .= "'" . $word[$j] . "'";
! }
}
! $sql = "SELECT word_id, word_text
! FROM " . SEARCH_WORD_TABLE . "
! WHERE word_text IN ($sql_in)";
$result = $db->sql_query($sql);
if( !$result )
{
! message_die(GENERAL_ERROR, "Couldn't select words", "", __LINE__, __FILE__, $sql);
}
! if( $word_check_count = $db->sql_numrows($result) )
! {
! $check_words = $db->sql_fetchrowset($result);
! $word_id_sql = "";
! for($i = 0; $i < count($check_words); $i++ )
! {
! if( $word_id_sql != "" )
! {
! $word_id_sql .= ", ";
! }
! $word_id_sql .= $check_words[$i]['word_id'];
! }
! $sql = "SELECT word_id, COUNT(post_id) AS post_occur_count
! FROM " . SEARCH_MATCH_TABLE . "
! WHERE word_id IN ($word_id_sql)
! GROUP BY word_id";
! if( !$result = $db->sql_query($sql) )
! {
! message_die(GENERAL_ERROR, "Couldn't obtain search word sums", "", __LINE__, __FILE__, $sql);
! }
!
! if( $post_count = $db->sql_numrows($result) )
{
! $rowset = $db->sql_fetchrowset($result);
!
! $word_id_sql = "";
! for($i = 0; $i < $post_count; $i++)
{
! if( $rowset[$i]['post_occur_count'] == 1 )
! {
! if( $word_id_sql != "" )
! {
! $word_id_sql .= ", ";
! }
! $word_id_sql .= $rowset[$i]['word_id'];
! }
}
if( $word_id_sql )
{
--- 169,255 ----
}
}
+ else
+ {
+ return 0;
+ }
! return $word_count;
}
! function remove_unmatched_words()
{
! global $db;
! switch(SQL_LAYER)
{
! case 'postgresql':
! $sql = "DELETE FROM " . SEARCH_WORD_TABLE . "
! WHERE word_id NOT IN (
! SELECT word_id
! FROM " . SEARCH_MATCH_TABLE . ")
! GROUP BY word_id";
! $result = $db->sql_query($sql);
! if( !$result )
! {
! message_die(GENERAL_ERROR, "Couldn't delete old words from word table", __LINE__, __FILE__, $sql);
! }
! $unmatched_count = $db->sql_affectedrows();
! break;
! case 'oracle':
! $sql = "DELETE FROM " . SEARCH_WORD_TABLE . "
! WHERE word_id IN (
! SELECT w.word_id
! FROM " . SEARCH_WORD_TABLE . " w, " . SEARCH_MATCH_TABLE . " m
! WHERE w.word_id = m.word_id(+)
! AND m.word_id IS NULL)";
! $result = $db->sql_query($sql);
! if( !$result )
{
! message_die(GENERAL_ERROR, "Couldn't delete old words from word table", __LINE__, __FILE__, $sql);
}
! $unmatched_count = $db->sql_affectedrows();
!
! break;
!
! case 'mssql':
! case 'msaccess':
! $sql = "DELETE FROM " . SEARCH_WORD_TABLE . "
! WHERE word_id IN (
! SELECT w.word_id
! FROM " . SEARCH_WORD_TABLE . " w
! LEFT JOIN " . SEARCH_MATCH_TABLE . " m ON m.word_id = w.word_id
! WHERE m.word_id IS NULL)";
$result = $db->sql_query($sql);
if( !$result )
{
! message_die(GENERAL_ERROR, "Couldn't delete old words from word table", __LINE__, __FILE__, $sql);
}
! $unmatched_count = $db->sql_affectedrows();
! break;
! case 'mysql':
! case 'mysql4':
! $sql = "SELECT w.word_id
! FROM " . SEARCH_WORD_TABLE . " w
! LEFT JOIN " . SEARCH_MATCH_TABLE . " m ON m.word_id = w.word_id
! WHERE m.word_id IS NULL";
! if( $result = $db->sql_query($sql) )
! {
! if( $unmatched_count = $db->sql_numrows($result) )
{
! $rowset = array();
! while( $row = $db->sql_fetchrow($result) )
{
! $rowset[] = $row['word_id'];
}
+ $word_id_sql = implode(", ", $rowset);
+
if( $word_id_sql )
{
***************
*** 286,307 ****
}
}
}
!
! $sql = "DELETE FROM " . SEARCH_MATCH_TABLE . "
! WHERE post_id = $post_id";
! $result = $db->sql_query($sql);
! if( !$result )
{
! message_die(GENERAL_ERROR, "Couldn't delete word match entry for this post", "", __LINE__, __FILE__, $sql);
}
}
! }
! }
! else
! {
! message_die(GENERAL_ERROR, "Couldn't obtain post text", "", __LINE__, __FILE__, $sql);
}
! return;
}
--- 262,280 ----
}
}
+ else
+ {
+ return 0;
+ }
}
! else
{
! return 0;
}
}
!
! break;
}
! return $unmatched_count;
}
***************
*** 1659,1669 ****
if( $delete || $mode == "delete" )
{
! remove_old_words($post_id);
! $sql = "DELETE FROM " . POSTS_TEXT_TABLE . "
WHERE post_id = $post_id";
! if($db->sql_query($sql, BEGIN_TRANSACTION))
{
! $sql = "DELETE FROM " . POSTS_TABLE . "
WHERE post_id = $post_id";
if($db->sql_query($sql))
--- 1632,1650 ----
if( $delete || $mode == "delete" )
{
! $sql = "DELETE FROM " . SEARCH_MATCH_TABLE . "
! WHERE post_id = $post_id";
! $result = $db->sql_query($sql, BEGIN_TRANSACTION);
! if( !$result )
! {
! message_die(GENERAL_ERROR, "Couldn't delete word match entry for this post", "", __LINE__, __FILE__, $sql);
! }
!
! remove_unmatched_words();
! $sql = "DELETE FROM " . POSTS_TEXT_TABLE . "
WHERE post_id = $post_id";
! if( $db->sql_query($sql) )
{
! $sql = "DELETE FROM " . POSTS_TABLE . "
WHERE post_id = $post_id";
if($db->sql_query($sql))
***************
*** 1677,1681 ****
if( $db->sql_query($sql) )
{
! $sql = "DELETE FROM " . TOPICS_TABLE . "
WHERE topic_id = $topic_id";
if( $db->sql_query($sql) )
--- 1658,1662 ----
if( $db->sql_query($sql) )
{
! $sql = "DELETE FROM " . TOPICS_TABLE . "
WHERE topic_id = $topic_id";
if( $db->sql_query($sql) )
***************
*** 1883,1892 ****
}
! remove_old_words($post_id);
$sql = "UPDATE " . POSTS_TABLE . "
SET bbcode_uid = '$bbcode_uid', enable_bbcode = $bbcode_on, enable_html = $html_on, enable_smilies = $smilies_on, enable_sig = $attach_sig" . $edited_sql . "
WHERE post_id = $post_id";
! if($db->sql_query($sql, BEGIN_TRANSACTION))
{
$sql = "UPDATE " . POSTS_TEXT_TABLE . "
--- 1864,1879 ----
}
! $sql = "DELETE FROM " . SEARCH_MATCH_TABLE . "
! WHERE post_id = $post_id";
! $result = $db->sql_query($sql, BEGIN_TRANSACTION);
! if( !$result )
! {
! message_die(GENERAL_ERROR, "Couldn't delete word match entry for this post", "", __LINE__, __FILE__, $sql);
! }
$sql = "UPDATE " . POSTS_TABLE . "
SET bbcode_uid = '$bbcode_uid', enable_bbcode = $bbcode_on, enable_html = $html_on, enable_smilies = $smilies_on, enable_sig = $attach_sig" . $edited_sql . "
WHERE post_id = $post_id";
! if($db->sql_query($sql))
{
$sql = "UPDATE " . POSTS_TEXT_TABLE . "
***************
*** 1898,1902 ****
if( $db->sql_query($sql) )
{
! add_search_words($post_id, stripslashes($post_message));
//
--- 1885,1890 ----
if( $db->sql_query($sql) )
{
! add_search_words($post_id, stripslashes($post_message));
! remove_unmatched_words();
//
***************
*** 2021,2026 ****
else
{
- remove_old_words($post_id);
add_search_words($post_id, stripslashes($post_message));
if( $db->sql_query($sql, END_TRANSACTION) )
--- 2009,2014 ----
else
{
add_search_words($post_id, stripslashes($post_message));
+ remove_unmatched_words();
if( $db->sql_query($sql, END_TRANSACTION) )
Index: search.php
===================================================================
RCS file: /cvsroot/phpbb/phpBB2/search.php,v
retrieving revision 1.37
retrieving revision 1.38
diff -C2 -r1.37 -r1.38
*** search.php 2001/11/22 02:02:11 1.37
--- search.php 2001/11/23 01:04:31 1.38
***************
*** 89,160 ****
return $split_entries[1];
}
-
- function arrayintersect($array1, $array2)
- {
- //
- // make sure arguments are actually arrays
- //
- if( !is_array($array1) || !is_array($array2) )
- {
- return false;
- }
-
- if( sizeof($array2) > sizeof($array1) )
- {
- $temp = $array1;
- $array1 = $array2;
- $array2 = $temp;
-
- unset($temp);
- }
-
- sort($array1);
- rsort($array2);
-
- // the greatest element in array2
- $eg2 = $array2[0];
-
- for($i = 0; $i < sizeof($array1); $i++)
- {
- $e1 = $array1[$i];
-
- for($j = 0; $j < sizeof($array2); $j++)
- {
- $e2 = $array2[$j];
-
- if( $e1 > $e2 )
- {
- //
- // we have passed the match
- //
- if( $e2 == $eg2 )
- {
- break(2);
- }
- else
- {
- break;
- }
- }
- else if( $e1 == $e2 )
- {
- //
- // we found a match
- //
- $retArray[] = $e1;
-
- break;
- }
- }
- }
- return $retArray;
- }
-
- function inarray($needle, $haystack)
- {
- for($i = 0; $i < count($haystack) && $haystack[$i] != $needle; $i++);
-
- return ( $i != count($haystack) );
- }
//
// End of functions defns
--- 89,92 ----
***************
*** 353,357 ****
--- 285,291 ----
$split_search = split_words($cleaned_search);
+ $word_count = 0;
$word_match = array();
+ $result_list = array();
$current_match_type = "and";
***************
*** 377,395 ****
}
! $word_match[$current_match_type][] = $split_search[$i];
! }
! }
- @reset($word_match);
-
- $word_count = 0;
- $result_list = array();
-
- while( list($match_type, $match_word_list) = each($word_match) )
- {
- for($i = 0; $i < count($match_word_list); $i++ )
- {
- $match_word = str_replace("*", "%", $match_word_list[$i]);
-
$sql = "SELECT m.post_id
FROM " . SEARCH_WORD_TABLE . " w, " . SEARCH_MATCH_TABLE . " m
--- 311,316 ----
}
! $match_word = str_replace("*", "%", $split_search[$i]);
$sql = "SELECT m.post_id
FROM " . SEARCH_WORD_TABLE . " w, " . SEARCH_MATCH_TABLE . " m
***************
*** 400,446 ****
if( !$result )
{
! message_die(GENERAL_ERROR, "Couldn't matched posts", "", __LINE__, __FILE__, $sql);
}
$row = array();
-
while( $temp_row = $db->sql_fetchrow($result) )
{
$row['' . $temp_row['post_id'] . ''] = 1;
- }
- @reset($row);
-
- while( list($post_id, $match_count) = each($row) )
- {
if( !$word_count )
{
! $result_list['' . $post_id . ''] = $match_count;
}
! else if( $match_type == "and" )
{
! $result_list['' . $post_id . ''] = ( $result_list['' . $post_id . ''] ) ? $result_list['' . $post_id . ''] + intval($match_count) : 0;
! }
! else if( $match_type == "or" )
! {
! if( $result_list['' . $post_id . ''] )
! {
! $result_list['' . $post_id . ''] += intval($match_count);
! }
! else
! {
! $result_list['' . $post_id . ''] = 0;
! $result_list['' . $post_id . ''] += intval($match_count);
! }
}
! else if( $match_type == "not" )
{
! $result_list['' . $post_id . ''] = 0;
}
}
! if( $match_type == "and" && $word_count )
{
- @reset($row);
@reset($result_list);
--- 321,348 ----
if( !$result )
{
! message_die(GENERAL_ERROR, "Couldn't obtain matched posts list", "", __LINE__, __FILE__, $sql);
}
$row = array();
while( $temp_row = $db->sql_fetchrow($result) )
{
$row['' . $temp_row['post_id'] . ''] = 1;
if( !$word_count )
{
! $result_list['' . $temp_row['post_id'] . ''] = 1;
}
! else if( $current_match_type == "or" )
{
! $result_list['' . $temp_row['post_id'] . ''] = 1;
}
! else if( $current_match_type == "not" )
{
! $result_list['' . $temp_row['post_id'] . ''] = 0;
}
}
! if( $current_match_type == "and" && $word_count )
{
@reset($result_list);
***************
*** 495,520 ****
else
{
! $sql = "SELECT topic_id
! FROM " . POSTS_TABLE . "
! WHERE post_id IN ($sql_post_id_in)
! GROUP BY topic_id";
! $result = $db->sql_query($sql);
! if( !$result )
{
! message_die(GENERAL_ERROR, "Couldn't matched posts", "", __LINE__, __FILE__, $sql);
! }
! $sql_post_id_in = "";
! while( $row = $db->sql_fetchrow($result) )
! {
! if( $sql_post_id_in != "" )
! {
! $sql_post_id_in .= ", ";
! }
! $sql_post_id_in .= $row['topic_id'];
! }
! $search_sql .= "t.topic_id IN ($sql_post_id_in) ";
!
}
}
--- 397,436 ----
else
{
! switch(SQL_LAYER)
{
! case 'mysql':
! case 'mysql4':
! $sql = "SELECT topic_id
! FROM " . POSTS_TABLE . "
! WHERE post_id IN ($sql_post_id_in)
! GROUP BY topic_id";
! $result = $db->sql_query($sql);
! if( !$result )
! {
! message_die(GENERAL_ERROR, "Couldn't matched posts", "", __LINE__, __FILE__, $sql);
! }
! $sql_post_id_in = "";
! while( $row = $db->sql_fetchrow($result) )
! {
! if( $sql_post_id_in != "" )
! {
! $sql_post_id_in .= ", ";
! }
! $sql_post_id_in .= $row['topic_id'];
! }
! $search_sql .= "t.topic_id IN ($sql_post_id_in) ";
!
! break;
!
! default:
! $search_sql .= "t.topic_id IN (
! SELECT topic_id
! FROM " . POSTS_TABLE . "
! WHERE post_id IN ($sql_post_id_in)
! GROUP BY topic_id )";
! break;
! }
}
}
***************
*** 612,620 ****
$total_match_count = $db->sql_numrows($result);
! /* if( $total_match_count > 500 )
! {
! message_die(GENERAL_MESSAGE, $lang['Too_many_results']);//"Your search returned too many matches, refine your search criteria and try again";
! }
! */
$searchset = $db->sql_fetchrowset($result);
--- 528,532 ----
$total_match_count = $db->sql_numrows($result);
!
$searchset = $db->sql_fetchrowset($result);
***************
*** 869,877 ****
if($return_chars != 0 )
{
! if($return_chars != -1)
! {
! $message = (strlen($message) > $return_chars) ? substr($message, 0, $return_chars) . " ..." : $message;
! }
!
//
// If the board has HTML off but the post has HTML
--- 781,786 ----
if($return_chars != 0 )
{
! $bbcode_uid = $searchset[$i]['bbcode_uid'];
!
//
// If the board has HTML off but the post has HTML
***************
*** 880,891 ****
if( $return_chars != -1 )
{
! $message = preg_replace("#<([\/]?.*?)>#is", "<\\1>", $message);
! $message = preg_replace("/[img\:[0-9a-z\:]+\].*?\[\/img\:[0-9a-z\:]+\]/si", "", $message);
! $message = preg_replace("/[\/[a-z\*]+\:[0-9a-z\:]+\]/si", "", $message);
}
else
{
- $bbcode_uid = $searchset[$i]['bbcode_uid'];
-
$user_sig = $searchset[$i]['user_sig'];
$user_sig_bbcode_uid = $searchset[$i]['user_sig_bbcode_uid'];
--- 789,799 ----
if( $return_chars != -1 )
{
! $message = (strlen($message) > $return_chars) ? substr($message, 0, $return_chars) . " ..." : $message;
! $message = strip_tags($message);
! $message = preg_replace("/\[.*?:$bbcode_uid:?.*?\]/si", "", $message);
! $message = preg_replace("/\[url\]|\[\/url\]/si", "", $message);
}
else
{
$user_sig = $searchset[$i]['user_sig'];
$user_sig_bbcode_uid = $searchset[$i]['user_sig_bbcode_uid'];
***************
*** 965,969 ****
{
$message = "";
-
if( count($orig_word) )
--- 873,876 ----
|