Re: Modelling tags - Mailing list pgsql-general

From Ivan Zolotukhin
Subject Re: Modelling tags
Date
Msg-id 751e56400708061405p19081259oee1c6cc6a39acd71@mail.gmail.com
Whole thread Raw
In response to Modelling tags  (cluster <skrald@amossen.dk>)
List 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

pgsql-general by date:

Previous
From: "Ed L."
Date:
Subject: Re: 8.1.2 select for update issue
Next
From: Henrik Zagerholm
Date:
Subject: Re: [PERFORM] Planner making wrong decisions 8.2.4. Insane cost calculations.