Hi I'm involved in developing a website for a e-shopping company. i want to include a search functionality in the site. search should not be like google search for web pages. if the user enter a string it should search the database for the match with product name or manufacturer name from a single table(lengthy table). it should match the misspelled words also. i searched the net for this but i cant get the appropriate method can any one help me? Thanks in advance.
you just need a form with a text input, submit that to your results page, and that script needs to build a query to search for what has been put into the text field if you want to search specific fields then something like: SELECT * FROM products WHERE p_name LIKE '%searchterm%' AND p_description LIKE '%searchterm%' Code (markup): although if you want to search all fields then try: $fields_q = mysql_query("DESCRIBE products"); while($fields = mysql_fetch_array($fields_q)) { $tblFields[] = $fields[0]; } Code (markup): That will give you an array of the fields in the table, then modify the first query I gave to loop through the $tblFields array. Also dont forget to use mysql_escape_string()
You should first use a stemmer to stem each word the user wants to search for, Jon Abernathy has made a good stemming class which you can download here: www dot chuggnutt dot com/projects.php it runs the Porter Stemming Algorithm to get the stems of English words. After that you can just build an SQL LIKE statement FETCH * FROM <table> WHERE page_content LIKE <$word> Code (markup): . It's not really rocket science
It's not really rocket science PHP: It could feel like it to newbies, it won't feel easy to everyone . Think about when you started php.
Try this for the MySQL Query : SELECT P.* FROM products P WHERE MATCH(P.product_name, P.manufacture_name) AGAINST ('+(keywords)' IN BOOLEAN MODE)
Was just trying to imply that it should be quite do-able even for a new PHP user, it's supposed to be encouragement. Do you have any useful information to add regarding the search system?
Thanks for your replies.. but i had implemented the search using th like key word.. i am searching for misspelled words and i have to sort the results according to the no of matching string "for example if the search key word have 3 strings then it should display the result that matches all the 3 string first and then for two and at last for one". i have tried the FULL Text matching in Sql also.. and then my database will be so long in size so the query should be process all the tuples as quickly as possible. can any body help me? thanks in advance...