Full text search prefix matching

From: Heikki Rauhala <heikki(dot)rauhala(at)reaktor(dot)fi>
To: pgsql-general(at)postgresql(dot)org
Subject: Full text search prefix matching
Date: 2014-12-16 12:59:51
Message-ID: 2FE04E1C-13DC-4066-B29B-1E783CD77C8A@reaktor.fi
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-general

Hi,

I’m trying to use PostgreSQL's full text search for searching names with prefix matching. I’ve got a materialized view with the tsvector’s in an indexed column which I’m then searching with prefix matching, as in the sqlfiddle: http://sqlfiddle.com/#!15/a2389/6 and below.

My problem is that when using the ‘finnish’ text search configuration, the names are split before the end, and they’re not matched when searching with prefix search that has exactly one character more than the lexeme, as also demonstrated in the above fiddle. When there are two characters after the lexeme, it does match.

I’m working around the issue by using ‘simple’ configuration, which includes the full words in the lexemes.

Should text search prefixes work predicatably as documented in [1] even if the lexemes are shorter than the query? How can I get it to work?

Best regards,

Heikki Rauhala

[1] http://www.postgresql.org/docs/9.3/static/textsearch-controls.html#TEXTSEARCH-PARSING-QUERIES

create table names (name varchar);
insert into names (name) values ('Sofia');

create materialized view name_fulltext as
select
name,
to_tsvector('finnish', name) as
searchable_index_col
from names;

select * from name_fulltext;
select to_tsquery('finnish','sof:*');

select 'found sof', name
from name_fulltext
where searchable_index_col@@to_tsquery('finnish','sof:*');

select 'notfound sofi', name
from name_fulltext
where searchable_index_col@@to_tsquery('finnish','sofi:*');

select 'found sofia', name
from name_fulltext
where searchable_index_col@@to_tsquery('finnish','sofia:*');

Responses

Browse pgsql-general by date

  From Date Subject
Next Message Vick Khera 2014-12-16 13:06:40 Re: 9.3.5 failing to compile with dtrace on FreeBSD 10.1
Previous Message Luca Ferrari 2014-12-16 12:49:59 9.3.5 failing to compile with dtrace on FreeBSD 10.1