real problem here? deciding how relevant each result is. thats always going to be the problem. I'd assume that the script you have only searchs for each word, and once it finds it, it stores the file it found it in, and goes on to the next. If this is the case, you'll have to rewrite the script to provide some kind of weighting to the data (perhaps how many times the words appear, or how close they are to each other)
Sorry to say, but you've picked a deceptivly complex task to start on.