This particular wheel has already been invented. Use
if you want to accomplish this with a minimal amount of effort. Unless this is a programming assignment or for your own personal edification, in which case you'll need to exclude common words, research/choose/implement ranking algorithms, maybe even look into clustering techniques to find related/similar documents, etc.