The well-known Mozilla Thunderbird email client has a search bar called “filter these messages”. It allows the user to quickly filter messages by displaying only those whose title, sender or recipients contain the words that the user types.
How would you implement such a functionality, given that it has to be as fast as possible even when displaying tons of messages? Should one use a precomputed index or similar data structure? Or simply iterate through the messages?
The beauty of open source software is that you can see the source :). You can even view the source code online:
Be very careful and play nice when you look at Mozilla’s source code! It would be very rude if you violate their licensing.
I would initially start by doing a direct search and if the performance is insufficient, then I’ll try to find a way to improve it. If you’re really strapped for performance, then maybe try and implementing some of the data structures used by Google.