pg.ddx.io  pgsql-bugs@postgresql.org mailing list archive  
help / color / mirror / Atom feed
BUG #15277: ts_headline strips things that look like HTML tags and it cannot be disabled
3+ messages / 3 participants
[nested] [flat]

* BUG #15277: ts_headline strips things that look like HTML tags and it cannot be disabled
@ 2018-07-12 07:59  PG Bug reporting form <noreply@postgresql.org>
  0 siblings, 1 reply; 3+ messages in thread

From: PG Bug reporting form @ 2018-07-12 07:59 UTC (permalink / raw)
  To: pgsql-bugs@lists.postgresql.org; +Cc: grinnz@gmail.com

The following bug has been logged on the website:

Bug reference:      15277
Logged by:          Dan Book
Email address:      grinnz@gmail.com
PostgreSQL version: 9.6.9
Operating system:   CentOS 7
Description:        

This post has a good overview of the issue with a reproduction case:
https://stackoverflow.com/questions/40263956/why-is-postgresql-stripping-html-entities-in-ts-headlin...

I have text that is not HTML and contains things that look like HTML tags.
The headlines are HTML escaped when output. It is very odd to have this text
missing from the resulting headlines and no way to control the behavior.



^ permalink  raw  reply  [nested|flat] 3+ messages in thread

* Re: BUG #15277: ts_headline strips things that look like HTML tags and it cannot be disabled
@ 2018-07-12 09:22  Arthur Zakirov <a.zakirov@postgrespro.ru>
  parent: PG Bug reporting form <noreply@postgresql.org>
  0 siblings, 1 reply; 3+ messages in thread

From: Arthur Zakirov @ 2018-07-12 09:22 UTC (permalink / raw)
  To: grinnz@gmail.com; pgsql-bugs@lists.postgresql.org

Hello,

On Thu, Jul 12, 2018 at 07:59:40AM +0000, PG Bug reporting form wrote:
> I have text that is not HTML and contains things that look like HTML tags.
> The headlines are HTML escaped when output. It is very odd to have this text
> missing from the resulting headlines and no way to control the behavior.

<b> and </b> are recognized as "tag" token. By default they are
ignored. You need to modify existing configuration or create new one:

=# CREATE TEXT SEARCH CONFIGURATION english_tag (COPY = english);
=# alter text search configuration english_tag
   add mapping for tag with simple;

Then tags aren't skipped:

=# select * from ts_debug('english_tag', 'query <b>test</b>');
   alias   |   description   | token |  dictionaries  |  dictionary  | lexemes 
-----------+-----------------+-------+----------------+--------------+---------
 asciiword | Word, all ASCII | query | {english_stem} | english_stem | {queri}
 blank     | Space symbols   |       | {}             | (null)       | (null)
 tag       | XML tag         | <b>   | {simple}       | simple       | {<b>}
 asciiword | Word, all ASCII | test  | {english_stem} | english_stem | {test}
 tag       | XML tag         | </b>  | {simple}       | simple       | {</b>}

But even in this case ts_headline will skip tags. Because it is
hardcoded [1].

I think it isn't good to change the behaviour for existing versions of
PostgreSQL. But there is a workaround of course if it is appropriate for
someone. It is possible to create your own text search parser extension.
Example [2]. And change

#define HLIDREPLACE(x)	( (x)==TAG_T )

to

#define HLIDREPLACE(x)	( false )


1 - https://github.com/postgres/postgres/blob/master/src/backend/tsearch/wparser_def.c#L1923
2 - https://github.com/postgrespro/pg_tsparser

-- 
Arthur Zakirov
Postgres Professional: http://www.postgrespro.com
Russian Postgres Company




^ permalink  raw  reply  [nested|flat] 3+ messages in thread

* Re: BUG #15277: ts_headline strips things that look like HTML tags and it cannot be disabled
@ 2018-07-12 15:33  Dan Book <grinnz@gmail.com>
  parent: Arthur Zakirov <a.zakirov@postgrespro.ru>
  0 siblings, 0 replies; 3+ messages in thread

From: Dan Book @ 2018-07-12 15:33 UTC (permalink / raw)
  To: a.zakirov@postgrespro.ru; +Cc: pgsql-bugs@lists.postgresql.org

On Thu, Jul 12, 2018 at 5:22 AM Arthur Zakirov <a.zakirov@postgrespro.ru>
wrote:

> Hello,
>
> On Thu, Jul 12, 2018 at 07:59:40AM +0000, PG Bug reporting form wrote:
> > I have text that is not HTML and contains things that look like HTML
> tags.
> > The headlines are HTML escaped when output. It is very odd to have this
> text
> > missing from the resulting headlines and no way to control the behavior.
>
> <b> and </b> are recognized as "tag" token. By default they are
> ignored. You need to modify existing configuration or create new one:
>
> =# CREATE TEXT SEARCH CONFIGURATION english_tag (COPY = english);
> =# alter text search configuration english_tag
>    add mapping for tag with simple;
>
> Then tags aren't skipped:
>
> =# select * from ts_debug('english_tag', 'query <b>test</b>');
>    alias   |   description   | token |  dictionaries  |  dictionary  |
> lexemes
>
> -----------+-----------------+-------+----------------+--------------+---------
>  asciiword | Word, all ASCII | query | {english_stem} | english_stem |
> {queri}
>  blank     | Space symbols   |       | {}             | (null)       |
> (null)
>  tag       | XML tag         | <b>   | {simple}       | simple       |
> {<b>}
>  asciiword | Word, all ASCII | test  | {english_stem} | english_stem |
> {test}
>  tag       | XML tag         | </b>  | {simple}       | simple       |
> {</b>}
>
> But even in this case ts_headline will skip tags. Because it is
> hardcoded [1].
>
> I think it isn't good to change the behaviour for existing versions of
> PostgreSQL. But there is a workaround of course if it is appropriate for
> someone. It is possible to create your own text search parser extension.
> Example [2]. And change
>
> #define HLIDREPLACE(x)  ( (x)==TAG_T )
>
> to
>
> #define HLIDREPLACE(x)  ( false )
>

Thanks for the response. It's good to know this is possible but defining a
custom parser is not ideal.

-Dan

^ permalink  raw  reply  [nested|flat] 3+ messages in thread


end of thread, other threads:[~2018-07-12 15:33 UTC | newest]

Thread overview: 3+ messages (download: mbox mbox.gz follow: Atom feed)
-- links below jump to the message on this page --
2018-07-12 07:59 BUG #15277: ts_headline strips things that look like HTML tags and it cannot be disabled PG Bug reporting form <noreply@postgresql.org>
2018-07-12 09:22 ` Arthur Zakirov <a.zakirov@postgrespro.ru>
2018-07-12 15:33   ` Dan Book <grinnz@gmail.com>

This inbox is served by DDX for PostgreSQL; see mirroring instructions
for how to clone and mirror all data and code used for this inbox