Skip to content

Phrase search fails with rum_tsvector_addon_ops #93

Closed
@ThomasWeiser

Description

@ThomasWeiser

Hello, thank you for this great extension!

I think I've spotted some problem. When searching

  • ... with a phrase-query like foo <-> bar
  • ... using an index of the rum_tsvector_addon_ops operator class
  • ... it doesn't find anything.

Let's setup a test table with text values a a, a b, a c and so on.

create extension rum;
create table text_table (id1 serial, t text);
create table rum_tbl (id serial, tsv tsvector);

insert into text_table(t) select chr(i) || ' ' || chr(j) from generate_series(65,90) i, generate_series(65,90) j; 
insert into rum_tbl(tsv) select to_tsvector('simple', t) from  text_table;

Without any index we can query on a <-> b, which works like expected:

select * from rum_tbl where tsv @@ to_tsquery('simple', 'a <-> b');
 id |     tsv     
----+-------------
  2 | 'a':1 'b':2
(1 row)

Now let's create an index using the rum_tsvector_addon_ops operator class:

create index rum_tbl_idx_addon
  on rum_tbl using rum (tsv rum_tsvector_addon_ops, id)
  with (attach ='id', to = 'tsv');

The same query now fails to return the matching row:

select * from rum_tbl where tsv @@ to_tsquery('simple', 'a <-> b');
 id | tsv 
----+-----
(0 rows)

Explain analyze says:

 Bitmap Heap Scan on rum_tbl  (cost=3.33..6.45 rows=4 width=28) (actual time=0.097..0.097 rows=0 loops=1)
   Recheck Cond: (tsv @@ '''a'' <-> ''b'''::tsquery)
   ->  Bitmap Index Scan on rum_tbl_idx_addon  (cost=0.00..3.33 rows=4 width=0) (actual time=0.093..0.093 rows=0 loop
s=1)
         Index Cond: (tsv @@ '''a'' <-> ''b'''::tsquery)

A query using an AND operator works correctly:

select * from rum_tbl where tsv @@ to_tsquery('simple', 'a & b');
-- ... result has 2 rows

Interestingly, the phrase-query also works correctly if we only have a rum_tsvector_ops index:

drop index rum_tbl_idx_addon;
create index rum_tbl_idx
  on rum_tbl using rum (tsv rum_tsvector_ops);

select * from rum_tbl where tsv @@ to_tsquery('simple', 'a <-> b');
-- ... result has 1 row

Tested with PostgreSQL 11.5 and RUM 1.3.7.

Any help greatly appreciated. Thank you in advance!

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions

      pFad - Phonifier reborn

      Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

      Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


      Alternative Proxies:

      Alternative Proxy

      pFad Proxy

      pFad v3 Proxy

      pFad v4 Proxy