Some cleanup
This commit is contained in:
parent
bbd81b563b
commit
77e1483c11
|
@ -8,27 +8,6 @@ has per_page => 5;
|
||||||
|
|
||||||
has date_format => 'Dy, FMDD Mon YYYY HH24:MI:SS TZHTZM';
|
has date_format => 'Dy, FMDD Mon YYYY HH24:MI:SS TZHTZM';
|
||||||
|
|
||||||
# args: date_format, search_query, limit, offset
|
|
||||||
# SELECT 'thread' AS post_type,
|
|
||||||
# thread_id AS post_id,
|
|
||||||
# TO_CHAR(thread_date, $1) AS post_date,
|
|
||||||
# thread_author AS post_author,
|
|
||||||
# thread_body AS post_body,
|
|
||||||
# ts_rank(search_tokens, plainto_tsquery('english', $2)) AS search_rank
|
|
||||||
# FROM threads
|
|
||||||
# WHERE search_tokens @@ plainto_tsquery('english', $2)
|
|
||||||
# UNION ALL
|
|
||||||
# SELECT 'remark',
|
|
||||||
# remark_id,
|
|
||||||
# remark_date,
|
|
||||||
# remark_author,
|
|
||||||
# remark_body,
|
|
||||||
# ts_rank(search_tokens, plainto_tsquery('english', $2))
|
|
||||||
# FROM remarks
|
|
||||||
# WHERE search_tokens @@ plainto_tsquery('english', $2)
|
|
||||||
# ORDER BY search_rank DESC, post_date DESC
|
|
||||||
# LIMIT $3 OFFSET $4;
|
|
||||||
|
|
||||||
sub search($self, $search_query, $this_page = 1) {
|
sub search($self, $search_query, $this_page = 1) {
|
||||||
my $date_format = $self->date_format;
|
my $date_format = $self->date_format;
|
||||||
my $row_count = $self->per_page;
|
my $row_count = $self->per_page;
|
||||||
|
@ -41,18 +20,18 @@ sub search($self, $search_query, $this_page = 1) {
|
||||||
TO_CHAR(thread_date, $1) AS post_date,
|
TO_CHAR(thread_date, $1) AS post_date,
|
||||||
thread_author AS post_author,
|
thread_author AS post_author,
|
||||||
thread_body AS post_body,
|
thread_body AS post_body,
|
||||||
ts_rank(search_tokens, plainto_tsquery('english', $2)) AS search_rank
|
TS_RANK(search_tokens, PLAINTO_TSQUERY('english', $2)) AS search_rank
|
||||||
FROM threads
|
FROM threads
|
||||||
WHERE search_tokens @@ plainto_tsquery('english', $2)
|
WHERE search_tokens @@ PLAINTO_TSQUERY('english', $2)
|
||||||
UNION ALL
|
UNION ALL
|
||||||
SELECT 'remark',
|
SELECT 'remark',
|
||||||
remark_id,
|
remark_id,
|
||||||
TO_CHAR(remark_date, $1),
|
TO_CHAR(remark_date, $1),
|
||||||
remark_author,
|
remark_author,
|
||||||
remark_body,
|
remark_body,
|
||||||
ts_rank(search_tokens, plainto_tsquery('english', $2))
|
TS_RANK(search_tokens, PLAINTO_TSQUERY('english', $2))
|
||||||
FROM remarks
|
FROM remarks
|
||||||
WHERE search_tokens @@ plainto_tsquery('english', $2)
|
WHERE search_tokens @@ PLAINTO_TSQUERY('english', $2)
|
||||||
ORDER BY search_rank DESC, post_date DESC
|
ORDER BY search_rank DESC, post_date DESC
|
||||||
LIMIT $3 OFFSET $4;
|
LIMIT $3 OFFSET $4;
|
||||||
END_SQL
|
END_SQL
|
||||||
|
|
|
@ -4,11 +4,11 @@ CREATE EXTENSION pg_trgm;
|
||||||
|
|
||||||
-- Create column for seearch tokens
|
-- Create column for seearch tokens
|
||||||
ALTER TABLE threads
|
ALTER TABLE threads
|
||||||
ADD COLUMN search_tokens tsvector
|
ADD COLUMN search_tokens TSVECTOR
|
||||||
GENERATED ALWAYS AS
|
GENERATED ALWAYS AS
|
||||||
(to_tsvector('english', thread_author) ||
|
(TO_TSVECTOR('english', thread_author) ||
|
||||||
to_tsvector('english', thread_title ) ||
|
TO_TSVECTOR('english', thread_title ) ||
|
||||||
to_tsvector('english', thread_body )) STORED;
|
TO_TSVECTOR('english', thread_body )) STORED;
|
||||||
|
|
||||||
-- Create GIN index for search tokens
|
-- Create GIN index for search tokens
|
||||||
CREATE INDEX threads_search_idx
|
CREATE INDEX threads_search_idx
|
||||||
|
@ -17,10 +17,10 @@ CREATE INDEX threads_search_idx
|
||||||
|
|
||||||
-- Same for remarks
|
-- Same for remarks
|
||||||
ALTER TABLE remarks
|
ALTER TABLE remarks
|
||||||
ADD COLUMN search_tokens tsvector
|
ADD COLUMN search_tokens TSVECTOR
|
||||||
GENERATED ALWAYS AS
|
GENERATED ALWAYS AS
|
||||||
(to_tsvector('english', remark_author) ||
|
(TO_TSVECTOR('english', remark_author) ||
|
||||||
to_tsvector('english', remark_body )) STORED;
|
TO_TSVECTOR('english', remark_body )) STORED;
|
||||||
|
|
||||||
CREATE INDEX remarks_search_idx
|
CREATE INDEX remarks_search_idx
|
||||||
ON remarks
|
ON remarks
|
||||||
|
|
Loading…
Reference in a new issue