Re: Full text search ts_heading strange result

From: Tom Lane <tgl(at)sss(dot)pgh(dot)pa(dot)us>
To: Johann Spies <jspies(at)sun(dot)ac(dot)za>
Cc: pgsql-general(at)postgresql(dot)org
Subject: Re: Full text search ts_heading strange result
Date: 2012-07-25 23:04:23
Message-ID: 6020.1343257463@sss.pgh.pa.us
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-general

Johann Spies <jspies(at)sun(dot)ac(dot)za> writes:
> I am beginning to use the full text search facilities in Postgresql
> (9.0) and find the result of this query a bit strange:

> query:

> SELECT ts_headline('simple',title, to_tsquery('kerkreg|(church & polity)'))
> from akb_articles A
> where A.tsv@@ 'kerkreg|(church & polity)'

> Result

> "Kerkvereniging en <b>Kerkreg</b>: Geskiedenis, beginsel en praktyk.(<b>Church</b> unity and <b>church</b> polity: History, principle and practice.)"

> Why is 'polity' not highlighted?

I believe the problem is that the one-argument form of to_tsquery() uses
the default TS configuration, which you have probably not got set to
"simple". For me, the default TS configuration is "english", which will
stem "polity" as "politi":

regression=# select to_tsquery('(polity & church)');
to_tsquery
---------------------
'politi' & 'church'
(1 row)

However the "simple" configuration doesn't do anything to that lexeme:

regression=# select to_tsquery('simple', '(polity & church)');
to_tsquery
---------------------
'polity' & 'church'
(1 row)

So what you've got is ts_headline() parsing the given title against
the "simple" configuration and getting "polity", but the tsquery is
looking for "politi", hence no match.

In short: omit the 'simple' argument from the ts_headline call, and
things should play together better. You could alternatively insert
to_tsquery('simple', '(polity & church)'), but that won't exactly
match what the @@ in WHERE is doing: that's going to use the default
configuration.

regards, tom lane

In response to

Responses

Browse pgsql-general by date

  From Date Subject
Next Message Tom Lane 2012-07-25 23:12:14 Re: Smaller data types use same disk space
Previous Message Merlin Moncure 2012-07-25 22:49:25 Re: Smaller data types use same disk space