From 655a39e35c01e5716c25a2ba28fe0442c52dac5c Mon Sep 17 00:00:00 2001 From: iPromKnight <156901906+iPromKnight@users.noreply.github.com> Date: Sat, 30 Mar 2024 01:54:06 +0000 Subject: [PATCH] patch the query with execute (#191) --- deployment/docker/docker-compose.yaml | 14 +++++++------- .../docker/src/components/knightcrawler.yaml | 14 +++++++------- .../migrations/013_imdb_change_ratio_fix.sql | 19 +++++++++++++++++++ 3 files changed, 33 insertions(+), 14 deletions(-) create mode 100644 src/migrator/migrations/013_imdb_change_ratio_fix.sql diff --git a/deployment/docker/docker-compose.yaml b/deployment/docker/docker-compose.yaml index 5224117..5855258 100644 --- a/deployment/docker/docker-compose.yaml +++ b/deployment/docker/docker-compose.yaml @@ -94,7 +94,7 @@ services: condition: service_healthy env_file: stack.env hostname: knightcrawler-addon - image: gabisonfire/knightcrawler-addon:2.0.14 + image: gabisonfire/knightcrawler-addon:2.0.15 labels: logging: promtail networks: @@ -117,7 +117,7 @@ services: redis: condition: service_healthy env_file: stack.env - image: gabisonfire/knightcrawler-consumer:2.0.14 + image: gabisonfire/knightcrawler-consumer:2.0.15 labels: logging: promtail networks: @@ -138,7 +138,7 @@ services: redis: condition: service_healthy env_file: stack.env - image: gabisonfire/knightcrawler-debrid-collector:2.0.14 + image: gabisonfire/knightcrawler-debrid-collector:2.0.15 labels: logging: promtail networks: @@ -152,7 +152,7 @@ services: migrator: condition: service_completed_successfully env_file: stack.env - image: gabisonfire/knightcrawler-metadata:2.0.14 + image: gabisonfire/knightcrawler-metadata:2.0.15 networks: - knightcrawler-network restart: "no" @@ -163,7 +163,7 @@ services: postgres: condition: service_healthy env_file: stack.env - image: gabisonfire/knightcrawler-migrator:2.0.14 + image: gabisonfire/knightcrawler-migrator:2.0.15 networks: - knightcrawler-network restart: "no" @@ -182,7 +182,7 @@ services: redis: condition: service_healthy env_file: stack.env - image: gabisonfire/knightcrawler-producer:2.0.14 + image: gabisonfire/knightcrawler-producer:2.0.15 labels: logging: promtail networks: @@ -207,7 +207,7 @@ services: deploy: replicas: ${QBIT_REPLICAS:-0} env_file: stack.env - image: gabisonfire/knightcrawler-qbit-collector:2.0.14 + image: gabisonfire/knightcrawler-qbit-collector:2.0.15 labels: logging: promtail networks: diff --git a/deployment/docker/src/components/knightcrawler.yaml b/deployment/docker/src/components/knightcrawler.yaml index 2b12bc7..1eb2b4a 100644 --- a/deployment/docker/src/components/knightcrawler.yaml +++ b/deployment/docker/src/components/knightcrawler.yaml @@ -20,7 +20,7 @@ x-depends: &knightcrawler-app-depends services: metadata: - image: gabisonfire/knightcrawler-metadata:2.0.14 + image: gabisonfire/knightcrawler-metadata:2.0.15 env_file: ../../.env networks: - knightcrawler-network @@ -30,7 +30,7 @@ services: condition: service_completed_successfully migrator: - image: gabisonfire/knightcrawler-migrator:2.0.14 + image: gabisonfire/knightcrawler-migrator:2.0.15 env_file: ../../.env networks: - knightcrawler-network @@ -40,7 +40,7 @@ services: condition: service_healthy addon: - image: gabisonfire/knightcrawler-addon:2.0.14 + image: gabisonfire/knightcrawler-addon:2.0.15 <<: [*knightcrawler-app, *knightcrawler-app-depends] restart: unless-stopped hostname: knightcrawler-addon @@ -48,22 +48,22 @@ services: - "7000:7000" consumer: - image: gabisonfire/knightcrawler-consumer:2.0.14 + image: gabisonfire/knightcrawler-consumer:2.0.15 <<: [*knightcrawler-app, *knightcrawler-app-depends] restart: unless-stopped debridcollector: - image: gabisonfire/knightcrawler-debrid-collector:2.0.14 + image: gabisonfire/knightcrawler-debrid-collector:2.0.15 <<: [*knightcrawler-app, *knightcrawler-app-depends] restart: unless-stopped producer: - image: gabisonfire/knightcrawler-producer:2.0.14 + image: gabisonfire/knightcrawler-producer:2.0.15 <<: [*knightcrawler-app, *knightcrawler-app-depends] restart: unless-stopped qbitcollector: - image: gabisonfire/knightcrawler-qbit-collector:2.0.14 + image: gabisonfire/knightcrawler-qbit-collector:2.0.15 <<: [*knightcrawler-app, *knightcrawler-app-depends] restart: unless-stopped depends_on: diff --git a/src/migrator/migrations/013_imdb_change_ratio_fix.sql b/src/migrator/migrations/013_imdb_change_ratio_fix.sql new file mode 100644 index 0000000..930bff2 --- /dev/null +++ b/src/migrator/migrations/013_imdb_change_ratio_fix.sql @@ -0,0 +1,19 @@ +-- Remove the old search function +DROP FUNCTION IF EXISTS search_imdb_meta(TEXT, TEXT, INT, INT); + +-- Add the new search function that allows for searching by year with a plus/minus one year range +CREATE OR REPLACE FUNCTION search_imdb_meta(search_term TEXT, category_param TEXT DEFAULT NULL, year_param INT DEFAULT NULL, limit_param INT DEFAULT 10, similarity_threshold REAL DEFAULT 0.95) + RETURNS TABLE(imdb_id character varying(16), title character varying(1000),category character varying(50),year INT, score REAL) AS $$ +BEGIN + EXECUTE format('SET pg_trgm.similarity_threshold = %L', similarity_threshold); + RETURN QUERY + SELECT imdb_metadata.imdb_id, imdb_metadata.title, imdb_metadata.category, imdb_metadata.year, similarity(imdb_metadata.title, search_term) as score + FROM imdb_metadata + WHERE (imdb_metadata.title % search_term) + AND (imdb_metadata.adult = FALSE) + AND (category_param IS NULL OR imdb_metadata.category = category_param) + AND (year_param IS NULL OR imdb_metadata.year BETWEEN year_param - 1 AND year_param + 1) + ORDER BY score DESC + LIMIT limit_param; +END; $$ + LANGUAGE plpgsql; \ No newline at end of file