Re: Modelling tags

From: "Ivan Zolotukhin" <ivan(dot)zolotukhin(at)gmail(dot)com>
To: cluster <skrald(at)amossen(dot)dk>
Cc: pgsql-general(at)postgresql(dot)org
Subject: Re: Modelling tags
Date: 2007-08-06 21:05:18
Message-ID: 751e56400708061405p19081259oee1c6cc6a39acd71@mail.gmail.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-general

Hello,

> I am thinking about how to model tags for a web site in the database.
> Is tsearch2 the way to do it?

Yes, tsearch2 is the ultimate thing for all your text work in the PostgreSQL.

> Each site entry could then store its tags
> in a tsvector. That would make me able to perform partial matches and
> rate them.

Each site entry should store its tags in tsvector definitely but for
the reasons of search only, not for ratings. It's better to separate
ratings/counters from text work usually. Default pattern I use is
inheritance of all tables from one parent table e.g. to make use of
global across entities id column. After then you create "tag" and
~"entity2tag" table which stores links to tags for your users to be
able to tag every entity stored in the database. Then couple of
triggers (for counters/ratings and full-text stuff) finish the work.
You finally are able to draw tag clouds, organize ajax suggest when
user tags smth, select entities by tag rapidly, search across entities
using tsearch2 avantages, make partial matches, etc.

Schema can be more complex if you need to store personal tags and show
them to user but one can easily extend the basic idea to get the
features needed.

Regards,
Ivan

In response to

Browse pgsql-general by date

  From Date Subject
Next Message Henrik Zagerholm 2007-08-06 21:29:45 Re: [PERFORM] Planner making wrong decisions 8.2.4. Insane cost calculations.
Previous Message Ed L. 2007-08-06 20:19:10 Re: 8.1.2 select for update issue