BUG #16592: websearch_to_tsquery() returns queries that don't result in expected matches

Previous Topic Next Topic
 
classic Classic list List threaded Threaded
3 messages Options
Reply | Threaded
Open this post in threaded view
|

BUG #16592: websearch_to_tsquery() returns queries that don't result in expected matches

PG Doc comments form
The following bug has been logged on the website:

Bug reference:      16592
Logged by:          Barry Pederson
Email address:      [hidden email]
PostgreSQL version: 12.4
Operating system:   Ubuntu 20.04
Description:        

In the regression tests src/test/regress/expected/tsearch.out there's an
example relating to double-quoted searches:

select websearch_to_tsquery('english', '"pg_class pg"');
    websearch_to_tsquery    
-----------------------------
 ( 'pg' & 'class' ) <-> 'pg'
(1 row)

However, if you ran a query like that against that exact text 'pg_class pg',
the result is false when I'd expect it should be true

   select to_tsvector('pg_class pg') @@ websearch_to_tsquery('"pg_class
pg"');

I'd think websearch_to_tsquery('english', '"pg_class pg"') should ideally
return
 
    'pg' <-> 'class'  <-> 'pg'

which does match the original string, e.g:

      select to_tsvector('pg_class pg') @@ to_tsquery('pg <-> class <->
pg');

does return true

Reply | Threaded
Open this post in threaded view
|

Re: BUG #16592: websearch_to_tsquery() returns queries that don't result in expected matches

Alexander Korotkov-4
Hi!

On Tue, Aug 25, 2020 at 11:24 PM PG Bug reporting form
<[hidden email]> wrote:

> In the regression tests src/test/regress/expected/tsearch.out there's an
> example relating to double-quoted searches:
>
> select websearch_to_tsquery('english', '"pg_class pg"');
>     websearch_to_tsquery
> -----------------------------
>  ( 'pg' & 'class' ) <-> 'pg'
> (1 row)
>
> However, if you ran a query like that against that exact text 'pg_class pg',
> the result is false when I'd expect it should be true
>
>    select to_tsvector('pg_class pg') @@ websearch_to_tsquery('"pg_class
> pg"');
>
> I'd think websearch_to_tsquery('english', '"pg_class pg"') should ideally
> return
>
>     'pg' <-> 'class'  <-> 'pg'
>
> which does match the original string, e.g:
>
>       select to_tsvector('pg_class pg') @@ to_tsquery('pg <-> class <->
> pg');
>
> does return true

It really looks at least counterintuitive for me.  I'm going to check this out.

------
Regards,
Alexander Korotkov


Reply | Threaded
Open this post in threaded view
|

Re: BUG #16592: websearch_to_tsquery() returns queries that don't result in expected matches

Alexander Korotkov-4
On Sun, Aug 30, 2020 at 4:44 AM Alexander Korotkov <[hidden email]> wrote:

> On Tue, Aug 25, 2020 at 11:24 PM PG Bug reporting form
> <[hidden email]> wrote:
> > In the regression tests src/test/regress/expected/tsearch.out there's an
> > example relating to double-quoted searches:
> >
> > select websearch_to_tsquery('english', '"pg_class pg"');
> >     websearch_to_tsquery
> > -----------------------------
> >  ( 'pg' & 'class' ) <-> 'pg'
> > (1 row)
> >
> > However, if you ran a query like that against that exact text 'pg_class pg',
> > the result is false when I'd expect it should be true
> >
> >    select to_tsvector('pg_class pg') @@ websearch_to_tsquery('"pg_class
> > pg"');
> >
> > I'd think websearch_to_tsquery('english', '"pg_class pg"') should ideally
> > return
> >
> >     'pg' <-> 'class'  <-> 'pg'
> >
> > which does match the original string, e.g:
> >
> >       select to_tsvector('pg_class pg') @@ to_tsquery('pg <-> class <->
> > pg');
> >
> > does return true
>
> It really looks at least counterintuitive for me.  I'm going to check this out.
I've done a quick investigation.  It seems that this behavior was
never well-thought out.

I wrote a patch for this issue.  It just replaces OP_AND with
OP_PHRASE inside quotes.  This patch is not perfect in terms of
abstractions and needs more work.  But on the user side it probably
does the right thing.  Could you review its user-level behavior?

------
Regards,
Alexander Korotkov

websearch_fix.patch (726 bytes) Download Attachment