I'm trying to develop a product search on my site

Just wondering what the 'idea' is behind matching products. Ie;

Say i have query:
"blue widgets by widgetCo"

what would you with that, break it up into 4 keywords and try match each... or
try match blue with all the brands, then widgets, with all the brands, then widgetCo with all the brands until it finds an existing brand, then match the rest with product names from that brand?

I dunno....
Anyone got any ideas on the logic behind matching the query with the relevant products?