Page 1 of 1

Query Filter

Posted: Mon Apr 25, 2005 7:32 pm
by ra
I am trying to get the following script to filter out a lengthy list of unfavorable words (in a text file?), but i am extremely lost. Any help would be greatly appreciated.

Code: Select all

<?
function format_term($term) {
$term = str_replace('-','~~',$term);
return str_replace(' ','-',$term);
}
$res = mysql_query("SELECT * FROM $querytable ORDER BY q_id DESC") or die(mysql_error());
 
if (preg_match($pattern, $searchstring)) {
do_insert();
}
while (($line = mysql_fetch_assoc($res)) && strlen(ob_get_contents()) < 95*1024) {
echo "<a href='".constant('dir')."search/".format_term($line['q_query'])."'>".$line['q_query']."</a><br>";
}
?>
</div>

Posted: Tue Apr 26, 2005 2:04 am
by timvw
it's hard to understand what your posted code is doing...

but if you are retrieving the unfavorable words from a database, you could easily build your own array with words (and replacements) and then perform a strreplace or a preg_replace

in general, code would look like:

Code: Select all

$unfavorables = array();
$replacements = array();

$query = "SELECT unfavorable from table";
$result = mysql_query($query) or die(mysql_error());

while ($rows = mysql_fetch_assoc($result))
{
  $unfavorables[] = $row['word'];
  $replacements[] = '';
}

$filecontent = str_replace($unfavorables, $replacements, $filecontent);

Posted: Tue Apr 26, 2005 3:36 pm
by ra
I was hoping to put the bad words in a text file on the server that i could update frequently. And there is no need to replace the terms, just show actual terms that are filtered... What do you think? And thanks for responding.

Posted: Wed Apr 27, 2005 1:02 am
by n00b Saibot
Now, here, we know the source of keywords/badwords and we know the procedure for replacing/highlighting but where do we have to search them. you don't mention that anywhere... :?

Posted: Thu Apr 28, 2005 5:13 pm
by ra
I was hoping to store the words in a text file on the server... is that what you mean?

Posted: Mon May 02, 2005 1:54 am
by n00b Saibot
I mean where do you want them replaced :?:

Posted: Mon May 02, 2005 1:07 pm
by ra
I don't want them replaced; just removed from the original query. The page this code resides on pulls all of the search terms out of the db and displays everything. I want to be able to create a text file on the server that has a list of terms to remove from the display... Does that make sense?

Posted: Mon May 02, 2005 5:57 pm
by Sphen001
If I understand you correctly, you should probably use a loop to remove all of the bad words from the DB first, and then you can just get the full contents of the DB, and don't worry about the bad words. I don't know if it's possible to do it on the fly like you want...

Sphen001

Posted: Tue May 03, 2005 10:39 am
by ra
I think the probablem with removing the terms from the DB is that they are constantly being put back in by users and other search engines. Can I use the loop method in an environment like this and, if yes, how?

Posted: Thu May 05, 2005 9:27 am
by ra
is there a way to filter the database and then post those results as static content, and then refresh that content every hour?

Posted: Fri May 06, 2005 10:22 pm
by ra
help?

Posted: Mon May 09, 2005 5:51 pm
by ra
here is the page:

http://www.sodora.com/queries.html

I am manually adjusting values in the db for the bad words...