We have a requirement to search in large text area field (for e.g. Description). We are using SOSL for the same.
While showing results on the VF page we want to only few sentence from Description field where the match keywords are found.
For e.g., Below can be the value of "Description" field :
Lorem ipsum dolor sit amet, stet graeco duo id, ut vis solum fierent molestiae. Sea simul elaboraret no, cu partiendo necessitatibus ius. Usu at iisque suscipiantur, suas mundi eum id. Eum eu homero evertitur, UNIQUEKEYWORD atomorum perpetua consequat ad nec. Ne vis quas ubique, quis ullum aperiam ea mei, suavitate argumentum interpretaris eu quo. Veri debet labitur ea qui, fugit pertinax pri ut. Ad laoreet apeirian vel.
Vis illud liber maiestatis id. Te graece recteque explicari sed, eu vero UNIQUEKEYWORD animal mea. Ne albucius oporteat eum, suscipit disputationi an est, vel id dissentiet definitiones. Ea purto omnis oratio sea. Has iusto euripidis moderatius id, no utinam aperiam omittam est, deserunt oportere at eum. Id illum atqui pri. Euripidis percipitur delicatissimi an has, ridens civibus sadipscing et eam. Vix ei reque facer, diam solum delicata eam at, ut cum erat malis dicunt.
If user will search for a word like "UNIQUEKEYWORD", we want to show result as below :
....Eum eu homero evertitur, UNIQUEKEYWORD atomorum perpetua consequat ad nec,... ....Te graece recteque explicari sed, eu vero UNIQUEKEYWORD animal mea....
I don't think similar thing will be possible using inbuilt SOSL/SOQL results/functionalities. One approach that I can think of now is to loop through all the result and find such sentence and display it in Visualforce page.
If anyone has done similar in Apex/Salesforce, please suggest some idea/thought for this problem.
text
property and substitute in a span withclass="highlightMe"
around the text that matches the searchkeyword. You could then strip away leading and trailing characters to limit the amount of text shown