mirror of
https://github.com/thiloho/archtika.git
synced 2025-11-22 10:51:36 +01:00
Use full text search instead of ilike for search functionality
This commit is contained in:
@@ -11,7 +11,7 @@ DECLARE
|
||||
_allowed_mimetypes TEXT[] := ARRAY['image/png', 'image/svg+xml', 'image/jpeg', 'image/webp'];
|
||||
_max_file_size INT := 5 * 1024 * 1024;
|
||||
BEGIN
|
||||
IF octet_length($1) = 0 THEN
|
||||
IF OCTET_LENGTH($1) = 0 THEN
|
||||
RAISE invalid_parameter_value
|
||||
USING message = 'No file data was provided';
|
||||
END IF;
|
||||
|
||||
86
rest-api/db/migrations/20240814175120_full_text_search.sql
Normal file
86
rest-api/db/migrations/20240814175120_full_text_search.sql
Normal file
@@ -0,0 +1,86 @@
|
||||
-- migrate:up
|
||||
ALTER TABLE internal.website
|
||||
ADD COLUMN title_search TSVECTOR GENERATED ALWAYS AS (TO_TSVECTOR('english', title)) STORED;
|
||||
|
||||
CREATE OR REPLACE VIEW api.website WITH ( security_invoker = ON
|
||||
) AS
|
||||
SELECT
|
||||
id,
|
||||
user_id,
|
||||
content_type,
|
||||
title,
|
||||
created_at,
|
||||
last_modified_at,
|
||||
last_modified_by,
|
||||
title_search -- New column
|
||||
FROM
|
||||
internal.website;
|
||||
|
||||
GRANT SELECT, UPDATE, DELETE ON api.website TO authenticated_user;
|
||||
|
||||
ALTER TABLE internal.article
|
||||
ADD COLUMN title_description_search TSVECTOR GENERATED ALWAYS AS (TO_TSVECTOR('english', COALESCE(title, '') || ' ' || COALESCE(meta_description, ''))) STORED;
|
||||
|
||||
CREATE OR REPLACE VIEW api.article WITH ( security_invoker = ON
|
||||
) AS
|
||||
SELECT
|
||||
id,
|
||||
website_id,
|
||||
user_id,
|
||||
title,
|
||||
meta_description,
|
||||
meta_author,
|
||||
cover_image,
|
||||
publication_date,
|
||||
main_content,
|
||||
created_at,
|
||||
last_modified_at,
|
||||
last_modified_by,
|
||||
title_description_search -- New column
|
||||
FROM
|
||||
internal.article;
|
||||
|
||||
GRANT SELECT, INSERT, UPDATE, DELETE ON api.article TO authenticated_user;
|
||||
|
||||
-- migrate:down
|
||||
DROP VIEW api.article;
|
||||
|
||||
CREATE VIEW api.article WITH ( security_invoker = ON
|
||||
) AS
|
||||
SELECT
|
||||
id,
|
||||
website_id,
|
||||
user_id,
|
||||
title,
|
||||
meta_description,
|
||||
meta_author,
|
||||
cover_image,
|
||||
publication_date,
|
||||
main_content,
|
||||
created_at,
|
||||
last_modified_at,
|
||||
last_modified_by
|
||||
FROM
|
||||
internal.article;
|
||||
|
||||
ALTER TABLE internal.article
|
||||
DROP COLUMN title_description_search;
|
||||
|
||||
DROP VIEW api.website;
|
||||
|
||||
CREATE VIEW api.website WITH ( security_invoker = ON
|
||||
) AS
|
||||
SELECT
|
||||
id,
|
||||
user_id,
|
||||
content_type,
|
||||
title,
|
||||
created_at,
|
||||
last_modified_at,
|
||||
last_modified_by
|
||||
FROM
|
||||
internal.website;
|
||||
|
||||
ALTER TABLE internal.website
|
||||
DROP COLUMN title_search;
|
||||
|
||||
Reference in New Issue
Block a user