Re: search by keyword

From: Date: Tue, 21 Oct 2003 16:10:43 +0000
Subject: Re: search by keyword
References: 1  Groups: php.general 
Request: Send a blank email to php-general+get-166973@lists.php.net to get a copy of this message
on the search_results page, what happens is: -i use explode() to break the comma-delimited string down into array elements, and count() to count the number of array elements -then i use a for loop to cycle through the list of array elements and run a sql query to search through a table for any matches to a particular array element. the for loop looks like //for loop that cycles through elements in an array, and searching through a mys ql table for matches for($j=0; $j<$count_elements; $j++) {$sql.="and columnname like '%keywords[$j]%' or columnname2 like '%keywords[$j]' or columnname3 like '%keywords[$j]%'...'";} i think this is technically working, since it's not giving me any errors, however it basically slows down searches to the point of unusability.
If you are using MySQL, look into FULL TEXT searches. MySQL 4 also has a binary mode which is pretty good. Make sure you've indexed your columns as well. Larry

« previous php.general (#166973) next »