Verzeichnisstruktur phpBB-2.0.0


Veröffentlicht
03.04.2002

So funktioniert es


Auf das letzte Element klicken. Dies geht jeweils ein Schritt zurück

Auf das Icon klicken, dies öffnet das Verzeichnis. Nochmal klicken schließt das Verzeichnis.
Auf den Verzeichnisnamen klicken, dies zeigt nur das Verzeichnis mit Inhalt an

(Beispiel Datei-Icons)

Auf das Icon klicken um den Quellcode anzuzeigen

search_fill.php

Zuletzt modifiziert: 09.10.2024, 12:51 - Dateigröße: 5.06 KiB


001  <?php 
002   
003  //
004  // Security message:
005  //
006  // This script is potentially dangerous.
007  // Remove or comment the next line (die(".... ) to enable this script.
008  // Do NOT FORGET to either remove this script or disable it after you have used it.
009  //
010   
011  //
012  // Do not change anything below this line.
013  //
014  set_time_limit(0);
015   
016  $phpbb_root_path = "../";
017  include($phpbb_root_path . 'extension.inc');
018  include($phpbb_root_path . 'common.'.$phpEx);
019  include($phpbb_root_path . 'includes/search.'.$phpEx);
020   
021  $common_percent = 0.4; // Percentage of posts in which a word has to appear to be marked as common
022   
023  print "<html>\n<body>\n";
024   
025  //
026  // Try and load stopword and synonym files
027  //
028  // This needs fixing! Shouldn't be hardcoded to English files!
029  $stopword_array = file($phpbb_root_path . "language/lang_english/search_stopwords.txt"); 
030  $synonym_array = file($phpbb_root_path . "language/lang_english/search_synonyms.txt"); 
031   
032  //
033  // Fetch a batch of posts_text entries
034  //
035  $sql = "SELECT COUNT(*) as total, MAX(post_id) as max_post_id 
036      FROM ". POSTS_TEXT_TABLE;
037  if ( !($result = $db->sql_query($sql)) ) 
038  {
039      $error = $db->sql_error();
040      die("Couldn't get maximum post ID :: " . $sql . " :: " . $error['message']);
041  }
042   
043  $max_post_id = $db->sql_fetchrow($result);
044   
045  $totalposts = $max_post_id['total'];
046  $max_post_id = $max_post_id['max_post_id'];
047   
048  $postcounter = (!isset($HTTP_GET_VARS['batchstart'])) ? 0 : $HTTP_GET_VARS['batchstart'];
049   
050  $batchsize = 200; // Process this many posts per loop
051  $batchcount = 0;
052  for(;$postcounter <= $max_post_id; $postcounter += $batchsize)
053  {
054      $batchstart = $postcounter + 1;
055      $batchend = $postcounter + $batchsize;
056      $batchcount++;
057      
058      $sql = "SELECT * 
059          FROM " . POSTS_TEXT_TABLE . " 
060          WHERE post_id 
061              BETWEEN $batchstart 
062                  AND $batchend";
063      if( !($result = $db->sql_query($sql)) )
064      {
065          $error = $db->sql_error();
066          die("Couldn't get post_text :: " . $sql . " :: " . $error['message']);
067      }
068   
069      $rowset = $db->sql_fetchrowset($result);
070      $db->sql_freeresult($result);
071   
072      $post_rows = count($rowset);
073      
074      if( $post_rows )
075      {
076   
077      //    $sql = "LOCK TABLES ".POST_TEXT_TABLE." WRITE";
078      //    $result = $db->sql_query($sql); 
079          print "\n<p>\n<a href='$PHP_SELF?batchstart=$batchstart'>Restart from posting $batchstart</a><br>\n";
080   
081          // For every post in the batch:
082          for($post_nr = 0; $post_nr < $post_rows; $post_nr++ )
083          { 
084              print ".";
085              flush();
086   
087              $post_id = $rowset[$post_nr]['post_id']; 
088   
089              $matches = array();
090              $matches['text'] = split_words(clean_words("post", $rowset[$post_nr]['post_text'], $stopword_array, $synonym_array));
091              $matches['title'] = split_words(clean_words("post", $rowset[$post_nr]['post_subject'], $stopword_array, $synonym_array));
092   
093              while( list($match_type, $match_ary) = @each($matches) )
094              {
095                  $title_match = ( $match_type == 'title' ) ? 1 : 0;
096   
097                  $num_matches = count($match_ary);
098   
099                  if ( $num_matches < 1 )
100                  {
101                      // Skip this post if no words where found
102                      continue;
103                  }
104   
105                  // For all words in the posting
106                  $sql_in = "";
107   
108                  $sql_insert = '';
109                  $sql_select = '';
110   
111                  $word = array();
112                  $word_count = array();
113   
114                  for($j = 0; $j < $num_matches; $j++)
115                  {
116                      $this_word = strtolower(trim($match_ary[$j]));
117                      if ( $this_word != '' )
118                      {
119                          $word_count[$this_word] = ( isset($word_count[$this_word]) ) ? $word_count[$this_word] + 1 : 0;
120                          $comma = ($sql_insert != '')? ', ': '';
121                      
122                          $sql_insert .= "$comma('" . $this_word . "')";
123                          $sql_select .= "$comma'" . $this_word . "'";
124                      }
125                  }
126   
127                  if ( $sql_insert == '' )
128                  {
129                      die("no words found");
130                  }
131                      
132                  $sql = 'INSERT IGNORE INTO ' . SEARCH_WORD_TABLE . "
133                      (word_text)
134                      VALUES $sql_insert";
135                  if ( !$result = $db->sql_query($sql) )
136                  {
137                      $error = $db->sql_error();
138                      die("Couldn't INSERT words :: " . $sql . " :: " . $error['message']);
139                  }
140   
141                  // Get the word_id's out of the DB (to see if they are already there)
142                  $sql = "SELECT word_id, word_text
143                      FROM " . SEARCH_WORD_TABLE . " 
144                      WHERE word_text IN ($sql_select)
145                      GROUP BY word_text";
146                  $result = $db->sql_query($sql);
147                  if ( !$result )
148                  {
149                      $error = $db->sql_error();
150                      die("Couldn't select words :: " . $sql . " :: " . $error['message']);
151                  }
152   
153                  $sql_insert = array();
154                  while( $row = $db->sql_fetchrow($result) )
155                  {
156                      $sql_insert[] = "($post_id" . $row['word_id'] . "$title_match)";
157                  }
158   
159                  $db->sql_freeresult($result);
160   
161                  $sql = "INSERT INTO " . SEARCH_MATCH_TABLE . "
162                      (post_id, word_id, title_match)
163                      VALUES " . implode(", ", $sql_insert);
164                  $result = $db->sql_query($sql); 
165                  if ( !$result )
166                  {
167                      $error = $db->sql_error();
168                      die("Couldn't insert new word match :: " . $sql . " :: " . $error['message']);
169                  }
170   
171              } // All posts
172          }
173   
174      //    $sql = "UNLOCK TABLES";
175      //    $result = $db->sql_query($sql); 
176   
177      }
178   
179      // Remove common words after the first 2 batches and after every 4th batch after that.
180      if( $batchcount % 4 == 3 )
181      {
182          print "<br>Removing common words (words that appear in more than $common_percent of the posts)<br>\n";
183          flush();
184          print "Removed ". remove_common("global", $common_percent) ." words that where too common.<br>";
185      }
186  }
187   
188  echo "<br>Done";
189   
190  ?>
191   
192  </body>
193  </html>
194