Re: a little fix for text search

From: Oleg Bartunov <obartunov(at)gmail(dot)com>
To: Tom Lane <tgl(at)sss(dot)pgh(dot)pa(dot)us>
Cc: pgsql-docs(at)postgresql(dot)org
Subject: Re: a little fix for text search
Date: 2016-11-12 21:01:46
Message-ID: CAF4Au4yBWMc08FVQBA4zR_SphTgvxRWCY=dzMHWcbhgO1qGJJw@mail.gmail.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-docs

On Sat, Nov 12, 2016 at 11:49 PM, Tom Lane <tgl(at)sss(dot)pgh(dot)pa(dot)us> wrote:

> Oleg Bartunov <obartunov(at)gmail(dot)com> writes:
> > Hi there !
> > I don't know when exactly it was improved, but following notice in
> > https://www.postgresql.org/docs/current/static/textsearch-controls.html#
> TEXTSEARCH-HEADLINE
> > is currently not needed.
>
> > ts_headline uses the original document, not a tsvector summary, so it can
> > be slow and should be used with care. A typical mistake is to call
> > ts_headline for every matching document when only ten documents are to be
> > shown. SQL subqueries can help; here is an example:
>
> I don't see why that stopped being appropriate? The point is that it
> takes a raw text input which has to be re-parsed; that's still true
> AFAICS.
>

I mean that in the past we recommended to use subselect to avoid extra
ts_headline() call, which now, at least at 9.6, it's obsoleted and two sql
queries call ts_headline() exactly 5 times.

select ts_headline(body,to_tsquery('supernovae &
x-ray')),ts_rank(fts,to_tsquery('supernovae & x-ray')) as rank
from apod
where fts @@ to_tsquery('supernovae & x-ray') order by rank desc limit 5;
explain (analyze, costs off) select ts_headline(body,to_tsquery('supernovae
& x-ray')), rank from (
select body, ts_rank(fts,to_tsquery('supernovae & x-ray')) as rank from
apod where fts @@ to_tsquery('supernovae & x-ray')
order by rank desc limit 5
) as foo;

select ts_headline(body,to_tsquery('supernovae &
x-ray')),ts_rank(fts,to_tsquery('supernovae & x-ray')) as rank
from apod
where fts @@ to_tsquery('supernovae & x-ray') order by rank desc limit 5;

> regards, tom lane
>

In response to

Responses

Browse pgsql-docs by date

  From Date Subject
Next Message Tom Lane 2016-11-12 21:37:05 Re: a little fix for text search
Previous Message Tom Lane 2016-11-12 20:49:16 Re: a little fix for text search