2
Let’s say I have this text stored in a table in my database:
Lorem ipsum dolor sit Amet, consectetur adipisicing Elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. Ut enim ad Minim veniam, wanted nostrud exercitation ullamco laboris nisi ut aliquip ex e Commodo consequat. Duis aute irure dolor in reprehenderit in voluptate Velit esse cillum dolore eu fugiat nulla pariatur. Excepteur sint occaecat cupidatat non proident, sunt in culpa qui officia deserunt mollit anim id est laborum.
If I read the word reprehenderit, I want in my application, in PHP/HTML display something similar to this:
... aute irure dolor in reprehenderit in voluptate Velit esse ...
I’ve been reading about the consultation FULL-TEXT, but I need you to return the words around the term of the query, instead of the whole text. It would be three or four words before and after the consulted term.
How do I do?
This type of functionality is often at the limit of what supports FULL-TEXT on relational databases can do it efficiently. Even if you find a smart solution to filter the text, in general I recommend you start thinking about using your own indexing and search tool like Elasticsearch or Apache Solr.
– Anthony Accioly
Only one SQL query serves? Do you need to be "Words" before and after? Cannot simply be a fixed piece (can cut the first/last)?
– Ismael
@Ismael can cut yes, man. I delete the first and the last already in the application. No problem. If you want to formalize an answer with your solution, thank you, but I believe it’s the same idea as Pope Charlie.
– LipESprY