Fallzone
07-17-2005, 10:56 AM
Hiya
I have built a search engine for game cheats and im not really happy with it just yet.
Currently it does like this when trying to find results
$trimmed = trim($var); //trim whitespace from the stored variable
$query = "select * from cheatcc_com_pc where cheatcategory='$Category' AND title like \"%$trimmed%\"
order by title";
and id say that pretty much blows the way it checks so i wonder if someone knows a better solution.
Like lets say i have a game named "trevor likes: oranges"
and i search for "trevor likes oranges" without the : .
It doesnt find it at all in the database.
Anyone got better ideas?
Best Regards
Jawn
Tomer
07-17-2005, 11:00 AM
Try this:
$trimmed = ereg_replace(":", " ", trim($var));
$query = mysql_query("SELECT * FROM cheatcc_com_puc
WHERE cheatcategory = '$Category'
AND title LIKE '%$trimmed%'");
Fallzone
07-17-2005, 12:05 PM
Originally posted by Fallzone
Hiya
I have built a search engine for game cheats and im not really happy with it just yet.
Currently it does like this when trying to find results
$trimmed = trim($var); //trim whitespace from the stored variable
$query = "select * from cheatcc_com_pc where cheatcategory='$Category' AND title like \"%$trimmed%\"
order by title";
and id say that pretty much blows the way it checks so i wonder if someone knows a better solution.
Like lets say i have a game named "trevor likes: oranges"
and i search for "trevor likes oranges" without the : .
It doesnt find it at all in the database.
Anyone got better ideas?
Best Regards
Jawn
You see that wont work since the search engine is going by title name in the database.
$trimmed is the var of the search string.
Maybe i didnt post enough info sorry
Best Regards
Jawn
maxymizer
07-17-2005, 12:11 PM
Originally posted by Fallzone
[B]Hiya
I have built a search engine for game cheats and im not really happy with it just yet.
The best you can do is to use FULLTEXT search.
Fulltext search provides you with search options like when you're searching Google's database (you can exclude terms and so on).
Basically, you have to modify your varchar, char and text fields that you want to search and add them a FULLTEXT index (alter table tablename add fulltext(columname)).
That will create a FULLTEXT index.
I'll take your table for FULLTEXT search example.
$query = "SELECT * FROM cheatcc_com_puc WHERE cheatcategory = '$Category' AND MATCH(title) AGAINST ($trimmed)";
You specify column list in "MATCH" and AGAINST is word list or a phrase you're searching for.
Googling "mysql fulltext search" will give you lots of resources where you can see more advanced examples which will help you achieve better search results.
Also, fulltext searching is faster than using LIKE but that's not what we're debating upon here.
Good luck.