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.
UPDATE
This is what I am talking about. Here you can see, When a user searched for the word "Netflix" it showed 1 of 27 results for "Netflix"
and beside it there is an icon for traversing to previous messages and recent messages which when clicked will reach you to the next messages with a word "Netflix" and that next messages might be 1 month old or 10 months old. While showing next messages it will show all the messages up to it and that message might be 400, 500 behind.