ProblemHelpPlease Posted August 31, 2010 Share Posted August 31, 2010 I am trying to find the most efficient way to search 2 columns for a matching query. The problem is that the match can be in either column or only match when both columns are combined, for examplecolumn 1 containslong greenshort redlong yellowcolumn 2 containsspotty sockscotton socksitchy socksI am current using LIKE '%$search%' in my query on both fieldsSELECT * FROM table WHERE column1 LIKE '%$search%' OR column2 LIKE '%$search%'This works if I search for 'long' or 'long green' or 'green' or 'spotty' etc but not if I search for 'long green spotty socks' or 'long socks'.I can't combine the fields or create a new field from the 2 seperate fields physically in the database as it would cause too many issues with other scripts.I know I could potentially use some kind of JOIN but need to find the mose efficient way as this code runs on a livesearch basis.Thanks in advance Link to comment Share on other sites More sharing options...
justsomeguy Posted August 31, 2010 Share Posted August 31, 2010 You need to break up the words in the search term and search for each word individually in both fields. Link to comment Share on other sites More sharing options...
ProblemHelpPlease Posted September 1, 2010 Author Share Posted September 1, 2010 I had thought of doing it that way but was hoping that mysql would provide a faster way of checking the data. As this is used in a livesearch it needs to return results instantly as the user performs the search so i can't have a delay in the results appearing. The table in question will have around 4000 to 5000 rows, do you think that the delay in searhcing by word would cause a delay with this size of table. Link to comment Share on other sites More sharing options...
justsomeguy Posted September 1, 2010 Share Posted September 1, 2010 As this is used in a livesearch it needs to return results instantly as the user performs the search so i can't have a delay in the results appearing.Nothing is instantaneous, everything has a delay. The question is how much.The table in question will have around 4000 to 5000 rows, do you think that the delay in searhcing by word would cause a delay with this size of table.It will be worth a test. You may be able to speed things up by using indexes or a fulltext search. Link to comment Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.