algorithms – search message in a conversation like messenger

I want to implement a search feature in my chat application like a messenger, skype, whatsapp has done. What they have done is when we search a word then it would not only show the message with that word in the current viewable message list but also on the past messages. To see the message with matching word, they provide next and previous icon to traverse. My difficulty on solving this problem is, initially, we will have only 10-20 number of messages, but how can we now show the message with matching word which is around 1 month or say 1 year old.

For showing the list of messages I am following as per relay spec cursor based pagination which gives me edges, node, pageCursors which will have hasNextPage, hasPreviousPage, startCursor and endCursor.

How would you implement such search functionality? I am just in a need of algorithm instead of code.