2

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.

  • couldn't you use jQuery on the VF page to manipulate the text property and substitute in a span with class="highlightMe" around the text that matches the searchkeyword. You could then strip away leading and trailing characters to limit the amount of text shown – cropredy Jul 3 '15 at 0:12
  • @crop1645, Yes using jQuery can be a good idea if our field size is small. But the text which want to process is of size 32000. After fetching all on VF page and then do jQuery processing will give View State and heavy web page issue. So, we are thinking to do this processing in server side and just store processed string in some custom property (wrapper class). So, page doesn't need to hold large text data in memory. If our field was smaller than your solution would be the best one. – Ashish Jul 10 '15 at 13:01
1

Finally, we have achieved this requirement by creating a "wrapper class" where we are storing required custom object details and one dynamic field for search result text.

After getting result, we are looping through this "Description" large text area field and storing sentences with keyword in custom wrapper class property.

By this, we are only querying large text field, but not storing it in view state(list).

Though, it may not be the perfect solution but at this moment we don't have another better solution than this.

| improve this answer | |

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.