1 year ago
#388772

Sergey Kozlov
PostgreSQL FTS text should be combined into one line
I have a table that has columns with title and content.
CREATE TABLE t_items (
item_id varchar PRIMARY KEY,
title varchar,
content varchar);
insert into t_items values ('111', 'Madrid title n1', 'The Madrid papers Open revelled in Reals win, with AS describing Chelsea as shipwrecked having been completely unsettled by Mendys error for');
insert into t_items values ('222', 'test title 22', 'Así fue el Mutua Madrid Open 2019, un torneo inolvidable. En la última edición, Novak Djokovic y Kiki Bertens se proclamaron campeones, David Ferrer se');
insert into t_items values ('333', 'Madrid title 33', 'Real Madrid play at Stamford Bridge for just the second time ever, and the first time with fans in the stands. Its going to be epic');
insert into t_items values ('444', 'test title 44', 'You can change the date of your tickets because of Covid-19 without any problems. A little bit of action · Zoo Aquarium de Madrid | Disfruta de tus animales');
insert into t_items values ('555', 'test title 554', 'In a former electrical substation, Kunsthalle Praha is sparking new energy in the Czech capital with inaugural show 100 year');
insert into t_items values ('661', 'test title 4554', 'Bistro Praha is the place to go if you want a warm atmosphere, authentic goulash, cabbage soup, wiener schnitzel or a range of European style dishes.');
I need to make a query that will return a prepared response for later full text search. But all the results of the found text should be combined into one line. Also, all found document IDs should be combined into one array.
SELECT to_tsvector('english', t_items.content || t_items.title),
array_agg(t_items.item_id) as id_array
FROM t_items
WHERE
to_tsvector(title) || to_tsvector(content)
@@ plainto_tsquery('Madrid & Open')
GROUP BY t_items.content, t_items.title;
My query incorrectly returns scattered rows.
-----------+----------
'2019':7 '22':27 'así':1 | {222}
'chelsea':12 'complet':17 'describ':11 | {111}
(2 rows)
I need the result of a union that includes all the results in one line:
-----------+----------
'2019':7 '22':27 'así':1 'chelsea':12 'complet':17 'describ':11 | {222, 111}
(1 rows)
Here is a working example: https://onecompiler.com/postgresql/3xyf3pfq5
postgresql
full-text-search
0 Answers
Your Answer