I also need the coding of keylogger or any such program which can keep track of key pressing activity
Sorry, wrong forum, wrong website. Find such code and applications somewhere else.
Further, for any other are of help, this is how it works here:
1. TRY first
what you want to do! You may find that it's not that hard.
2. Formulate what was done by you that looks like an issue/not working.
Now, for context based search engine, break into parts and explore what all you need to do. Pick a language you are comfortable and implement it.
There are papers published on it, read them, learn and try out. Examples:
Design and Implementation of a Content-Based Search Engine
Towards Context-Based Search Engine Selection