pg.ddx.io pgsql-general@postgresql.org mailing list archive
help / color / mirror / Atom feedMultilang text search. Is this correct?
2+ messages / 2 participants
[nested] [flat]
* Multilang text search. Is this correct?
@ 2023-03-30 08:15 Florents Tselai <florents.tselai@gmail.com>
2023-03-30 18:28 ` Re: Multilang text search. Is this correct? Tom Lane <tgl@sss.pgh.pa.us>
0 siblings, 1 reply; 2+ messages in thread
From: Florents Tselai @ 2023-03-30 08:15 UTC (permalink / raw)
To: pgsql-general <pgsql-general@lists.postgresql.org>
In my table (mix of text and jsonb columns ) I have text in multiple languages.
I’d like search in all the possible regconfigs, so I’ve come up with the following recipe:
CREATE FUNCTION to_tsvector_multilang(text) RETURNS tsvector AS
$$
SELECT to_tsvector('english', $1) ||
to_tsvector('greek', $1) ||
to_tsvector('simple', $1)
$$ LANGUAGE sql IMMUTABLE;
CREATE FUNCTION jsonb_to_tsvector_multilang(jsonb, jsonb) RETURNS tsvector AS
$$
SELECT jsonb_to_tsvector('english', $1, $2) ||
jsonb_to_tsvector('simple', $1, $2) ||
jsonb_to_tsvector('greek', $1, $2)
$$ LANGUAGE sql IMMUTABLE;
CREATE FUNCTION to_tsquery_multilang(query text) RETURNS tsquery AS
$$
SELECT websearch_to_tsquery('english', query) ||
websearch_to_tsquery('simple', query) ||
websearch_to_tsquery('greek', query)
$$ LANGUAGE sql IMMUTABLE;
Thus, in searching I use to_tsvector_multilang(’TEXT') @@ to_tsquery_multilang(‘QUERY’);
Looks like it’s working as expected from my prelim tests, but anyone seeing any potential pitfalls?
Note: I’m using GIN & RUM indices as well.
^ permalink raw reply [nested|flat] 2+ messages in thread
* Re: Multilang text search. Is this correct?
2023-03-30 08:15 Multilang text search. Is this correct? Florents Tselai <florents.tselai@gmail.com>
@ 2023-03-30 18:28 ` Tom Lane <tgl@sss.pgh.pa.us>
0 siblings, 0 replies; 2+ messages in thread
From: Tom Lane @ 2023-03-30 18:28 UTC (permalink / raw)
To: Florents Tselai <florents.tselai@gmail.com>; +Cc: pgsql-general <pgsql-general@lists.postgresql.org>
Florents Tselai <florents.tselai@gmail.com> writes:
> In my table (mix of text and jsonb columns ) I have text in multiple languages.
> I’d like search in all the possible regconfigs, so I’ve come up with the following recipe:
> CREATE FUNCTION to_tsvector_multilang(text) RETURNS tsvector AS
> $$
> SELECT to_tsvector('english', $1) ||
> to_tsvector('greek', $1) ||
> to_tsvector('simple', $1)
> $$ LANGUAGE sql IMMUTABLE;
> Looks like it’s working as expected from my prelim tests, but anyone seeing any potential pitfalls?
Well, it'll work for some value of "work", but your tsvectors and
associated indexes will be bloated, and you're likely to get false
matches. (For example, common words like "the" will get indexed
and treated as matchable unless they're stopwords in all three
configurations.)
The usual compromise is to use just one config --- either 'simple',
or a specific language if you have a preponderance of data in that
language --- and tolerate the fact that searches won't be too bright
about things like reducing stemmed words.
regards, tom lane
^ permalink raw reply [nested|flat] 2+ messages in thread
end of thread, other threads:[~2023-03-30 18:28 UTC | newest]
Thread overview: 2+ messages (download: mbox mbox.gz follow: Atom feed)
-- links below jump to the message on this page --
2023-03-30 08:15 Multilang text search. Is this correct? Florents Tselai <florents.tselai@gmail.com>
2023-03-30 18:28 ` Tom Lane <tgl@sss.pgh.pa.us>
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