I'm working on a feature for an internal site search tool. Marketing folks will be able to upload "ads" to appear alongside searches on our site.
These ads will need to use the same keyword matching types as offered by Google Adwords. For example:
Ad 1 - "custom widgets"
Ad 2 - [red furry widgets]
Ad 3 - widgets
Ad 4 - "furry widgets" -red
So, if, for example a user does a site search for red furry widgets then they should see Ad 2 and Ad 3. If they do a search for blue and green furry widgets, they'd see Ad 3 and Ad 4.
Here's my problem... For the life of me I cannot figure out how to set up these queries against the database! The only way I can think of is to actually loop through every row in the database and test it against the search terms, but there's got to be a better way.