Looking to improve this mysql select statement for a search query:
Select * from table WHERE ( user = '$search_query'
OR user LIKE '$search_query %'
OR keyword LIKE '$search_query'
OR tag LIKE '$search_query'
OR tag LIKE '% $search_query'
OR tag LIKE '% $search_query%'
OR tag LIKE '$search_query%'
OR REPLACE(question, ',' ,'') LIKE '$search_query %'
OR REPLACE(question, ',' ,'') LIKE '% $search_query'
OR REPLACE(question, ',' ,'') LIKE '% $search_query %'
OR REPLACE( REPLACE( REPLACE( REPLACE( REPLACE( REPLACE( REPLACE(question, '\'', ''), ',', ''), '.',''), ':',''), ';',''), '!',''), '?','') LIKE '%$search_query%'
)
The reason it’s broke down the way it is, is because say if someone searches for “art”, I don’t want it showing results for “heart” as well.
I really need to have of these same functions but running fewer resources.
If your table is
MyISAM, you can create aFULLTEXTindex on it:This query will return
someandsomethingbut notawesome.Actually, the first step (creating the index) is not required, however, it will speed up the queries and allow more complex searches (not limited to
BOOLEAN MODE) and relevance ranging.By default, minimal length of a search query is
4characters, soartmentioned in your example would not be found.To work around this, you will have to change parameter
ft_min_word_lenin server settings.