Inilah SQL yang Anda butuhkan:
SELECT
id,
title,
substring(body,
case
when locate('mysql', lower(body)) <= 20 then 1
else locate('mysql', lower(body)) - 20
end,
case
when locate('mysql', lower(body)) + 20 > length(body) then length(body)
else locate('mysql', lower(body)) + 20
end)
FROM content
WHERE lower(body) LIKE '%mysql%'
OR title LIKE '%mysql%'
limit 8;
FYI:Diuji dan berfungsi.