K_N Posted December 5, 2010 Share Posted December 5, 2010 Right now I'm using a query like SELECT * FROM `table` WHERE title LIKE '" .$searchterms. "' ORDER BY id" but this only returns exact results in most experiences. I need to be able to say, have "This is something to search for" in the database, and have the search return it in the results even if I just searched for "This is" or "This is something" or "Something to". (Obviously I'm going to filter out common words in the PHP later on, I just need the right SQL syntax right now) What else can I use to search? Quote Link to comment https://forums.phpfreaks.com/topic/220707-a-better-way-to-search/ Share on other sites More sharing options...
dreamwest Posted December 5, 2010 Share Posted December 5, 2010 SELECT * FROM `table` WHERE MATCH `title` AGAINST('{$searchterms}' IN BOOLEAN MODE) ORDER BY id asc You should ALWAYS look to MATCH AGAINST for your queries to start with, if you cant do it with that use other query types If you have an immense database like me, create an inverted index that way your only searching the word and not the whole document, and its SUPER effective Quote Link to comment https://forums.phpfreaks.com/topic/220707-a-better-way-to-search/#findComment-1143152 Share on other sites More sharing options...
K_N Posted December 7, 2010 Author Share Posted December 7, 2010 SELECT * FROM `table` WHERE MATCH `title` AGAINST('{$searchterms}' IN BOOLEAN MODE) ORDER BY id asc You should ALWAYS look to MATCH AGAINST for your queries to start with, if you cant do it with that use other query types If you have an immense database like me, create an inverted index that way your only searching the word and not the whole document, and its SUPER effective Ahh, thank you. This database only has about 10k entries, is that something I should use an inverted index for? Quote Link to comment https://forums.phpfreaks.com/topic/220707-a-better-way-to-search/#findComment-1144016 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.