Jump to content

help: query for tag simple search engine


brokulo

Recommended Posts

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.name
ORDER 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 it

Would 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 either

I'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
Link to comment
https://forums.phpfreaks.com/topic/28599-help-query-for-tag-simple-search-engine/
Share on other sites

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.