brokulo Posted November 27, 2006 Share Posted November 27, 2006 I'm building a simple tag search engine. each item has a multiple tags associated to him (10+). i.e. A user searches "can opener" and the query returns the items that have both "can" and "opener" as tags.So far I've only thought of three solutions: -keeping the tags in an item field and do a full text search, -a table for tags and other for items and a query like this:SELECT item.name, COUNT(1) as "Number of matches"FROM item, tag WHERE item.id=tag.item_id AND (tad.name='can' OR tag.name='opener')GROUP BY tag.nameORDER BY "Number of matches" DESC;or like this:...WHERE EXISTS ( SELECT * FROM ... WHERE item.id=tag.item_id AND tag.name='can')AND EXISTS ( SELECT * FROM ... WHERE item.id=tag.item_id AND tag.name='opener');I havent tried these yet, I'm at a public internet point, but you get the idea behind itWould a many to mant relation between tags and items make sense? Would it improve speed? I'm so lost... my SQL skills aren't great eitherI'm doing this for a very big DB with lot's of queries/second, so what do you think the best way to do it is?Thanks Quote Link to comment https://forums.phpfreaks.com/topic/28599-help-query-for-tag-simple-search-engine/ Share on other sites More sharing options...
fenway Posted November 27, 2006 Share Posted November 27, 2006 As long as you've got a reason number of tags, then yes, use a single record for each tag/item pair. Quote Link to comment https://forums.phpfreaks.com/topic/28599-help-query-for-tag-simple-search-engine/#findComment-130999 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.