I’m doing a full-text search on a mysql table with PHP on the backend and I want to be able to select some text before and after the keywords that user searched and show it to them just like Google.
For example if user searched for “their worlds”
in a column where content is:
and these children that you spit on,
as they try to change their worlds are
immune to your consultations. They’re
quite aware of what they’re going
through…
the result would be like:
“…as they try to change their worlds
are imm…”
Is this possible to achieve something like that with SQL directly or should i fetch all the content and use PHP and maybe a regex?
Thank you.
Just from the top of my head, something like this should work (can’t test it), since locate will return the position where
wordis first found incolumn_nameand substring will return a substring ofcolumn_namestarting at the position of the first occurrence ofwordincolumn_nameminus 20 characters and 40 characters long.