I am having a product table with following schema:
products (itemname VARCHAR(50), itemid INT(10));
Sample records are shown below (itemname, itemid):
- blackberry curve 3g (black), 1
- samsung ace, 3
- blackberry curve 3g (white), 2
- apple iphone 4 32gb (black), 4
Now suppose user enters the query into the search box of the website and accordingly results are displayed. i.e. if user enters blackberry then Blackberry mobiles should be displayed
I am looking answers for the following questions:
- How can search text be matched with the items? For example: user may
enter
blackberryin the search box then how it can be searched? Should I search forblackberryword as a sub-string ofitemnamecolumn of the above table? - If the user enters two words like:
apple 32gb. Now if I use the above mentioned method of sub-string then it wont work because there is no row in the table havingapple 32gbas sub-string. How to search in this case? - If the user enters a very generic search text like:
mobiles. In this case, all the mobile phones should be displayed. Matching theitemnameas a sub-string will not work in this case also. - User may enter search text:
apple 32gb black color. In this case, apple products of 32GB capacity and black color should be displayed.
I know that implementing the search 100% correct is not possible. I am just looking for hints/how to proceed. I am using PHP, MySQL, Apache.