it's been bugging me for some time now how to make an AdSense (or ContextLink or any similar) style app.

What it does is "read" your entire page (in which it's placed), make a list of all the words in it and look if any of these are listed in their DB. If it is, it places an ad based on it.

Now, I'm not trying to run against Google But I would like to know is if anybody has an idea how to match (let's say) a 1000 words to a table with a (let's say) 1000 words? Running a 1000 queries and passing them out sounds a lot..