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
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • 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.