I know most of the time people just do a
LIKE '%$search_query%'
but see the thing is, in my case someone may be searching for things like
that cow is fat
now, the thing is in my database i wouldnt be storing it exactly as "the cow is fat" i'd be storing it something like "fat cow" so using
LIKE '%$search_query%'
wouldn't work.
Can anyone point me in the right direction for an efficient way to search my database like I have explained?
Thanks
You are looking for full-text search , with the restriction that the default minimum word length there is 4 by default, so it won't work for your examples.
An example that searches for "house" and "barn" in records that do not contain "sheep" in boolean mode:
SELECT * FROM table WHERE MATCH (columnname)
AGAINST ('+house +barn -sheep' IN BOOLEAN MODE);
Alternatively, natural language may work better for full sentences.
Full text search is a rather complex field, though, with many caveats and gotchas. It is worth reading the manual carefully.
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.