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';
|
||||
|
||||
# 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) {
|
||||
my $date_format = $self->date_format;
|
||||
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,
|
||||
thread_author AS post_author,
|
||||
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
|
||||
WHERE search_tokens @@ plainto_tsquery('english', $2)
|
||||
WHERE search_tokens @@ PLAINTO_TSQUERY('english', $2)
|
||||
UNION ALL
|
||||
SELECT 'remark',
|
||||
remark_id,
|
||||
TO_CHAR(remark_date, $1),
|
||||
remark_author,
|
||||
remark_body,
|
||||
ts_rank(search_tokens, plainto_tsquery('english', $2))
|
||||
TS_RANK(search_tokens, PLAINTO_TSQUERY('english', $2))
|
||||
FROM remarks
|
||||
WHERE search_tokens @@ plainto_tsquery('english', $2)
|
||||
WHERE search_tokens @@ PLAINTO_TSQUERY('english', $2)
|
||||
ORDER BY search_rank DESC, post_date DESC
|
||||
LIMIT $3 OFFSET $4;
|
||||
END_SQL
|
||||
|
|
|
@ -4,11 +4,11 @@ CREATE EXTENSION pg_trgm;
|
|||
|
||||
-- Create column for seearch tokens
|
||||
ALTER TABLE threads
|
||||
ADD COLUMN search_tokens tsvector
|
||||
ADD COLUMN search_tokens TSVECTOR
|
||||
GENERATED ALWAYS AS
|
||||
(to_tsvector('english', thread_author) ||
|
||||
to_tsvector('english', thread_title ) ||
|
||||
to_tsvector('english', thread_body )) STORED;
|
||||
(TO_TSVECTOR('english', thread_author) ||
|
||||
TO_TSVECTOR('english', thread_title ) ||
|
||||
TO_TSVECTOR('english', thread_body )) STORED;
|
||||
|
||||
-- Create GIN index for search tokens
|
||||
CREATE INDEX threads_search_idx
|
||||
|
@ -17,10 +17,10 @@ CREATE INDEX threads_search_idx
|
|||
|
||||
-- Same for remarks
|
||||
ALTER TABLE remarks
|
||||
ADD COLUMN search_tokens tsvector
|
||||
ADD COLUMN search_tokens TSVECTOR
|
||||
GENERATED ALWAYS AS
|
||||
(to_tsvector('english', remark_author) ||
|
||||
to_tsvector('english', remark_body )) STORED;
|
||||
(TO_TSVECTOR('english', remark_author) ||
|
||||
TO_TSVECTOR('english', remark_body )) STORED;
|
||||
|
||||
CREATE INDEX remarks_search_idx
|
||||
ON remarks
|
||||
|
|
Loading…
Reference in a new issue