Re: ts_headline

Поиск
Список
Период
Сортировка
От Richard Huxton
Тема Re: ts_headline
Дата
Msg-id 47BE962A.8050403@archonet.com
обсуждение исходный текст
Ответ на Re: ts_headline  (Stephen Davies <scldad@sdc.com.au>)
Ответы Re: ts_headline
Список pgsql-general
Stephen Davies wrote:
> Not quite:-(
>
> It is the ts_headline with the explicit "english" configuration that "fails"
> rather than the implicit "simple".

Hmm... arse.

> That's what is so weird.
>
> As you say, the ts_vector has "databas" so the "english" version of
> ts_headline should work - but it doesn't. The "simple" version does; despite
> the above.

[goes away, tests some more]

OK, so:

set default_text_search_config = 'simple';
SELECT ts_headline('my database is a database', to_tsquery('database'));
SELECT ts_headline('my database is a database', to_tsquery('simple',
'database'));
SELECT ts_headline('my database is a database', to_tsquery('english',
'database'));

The first two work, the last one doesn't.

set default_text_search_config = 'english';
SELECT ts_headline('my database is a database', to_tsquery('database'));
SELECT ts_headline('my database is a database', to_tsquery('simple',
'database'));
SELECT ts_headline('my database is a database', to_tsquery('english',
'database'));

The middle one doesn't work.

Note that there are no indexes involved here, we're just running against
the raw text.

[light goes on over sluggish London-based database chap]

When the ts_headline function is working on the text, it needs to
convert it from varchar/text type to tsvector so that it can use the
tsquery to find words to highlight.

When it converts the text to a tsvector, it's doing it based on
default_text_search_config - we've not told it otherwise. In an ideal
world, it would look "inside" the tsquery and see what config that was
using, but it can't (or at least doesn't).

Of course, if to_tsquery()'s config doesn't match to_tsheadline()'s then
we get a problem.

And, if I actually bother to read an up-to-date copy of the manual,
rather than the beta version I've got linked on my desktop I can see
there's a parameter for ts_headline. So...

set default_text_search_config = 'simple';
SELECT ts_headline('english', 'my database is a database',
   to_tsquery('english','database')
);

set default_text_search_config = 'english';
SELECT ts_headline('simple', 'my database is a database',
   to_tsquery('simple','database')
);


These all work fine. Phew!

--
   Richard Huxton
   Archonet Ltd

В списке pgsql-general по дате отправления:

Предыдущее
От: Stephen Davies
Дата:
Сообщение: Re: ts_headline
Следующее
От: Stephen Davies
Дата:
Сообщение: Re: ts_headline