From 8733526c01f181acebd4b5e54d164b877fbfb6d0 Mon Sep 17 00:00:00 2001 From: HeNine <> Date: Tue, 16 Nov 2021 14:17:08 +0100 Subject: [PATCH] search optimization 3 --- buscribe-api/buscribeapi/buscribeapi.py | 29 +++++++------------------ 1 file changed, 8 insertions(+), 21 deletions(-) diff --git a/buscribe-api/buscribeapi/buscribeapi.py b/buscribe-api/buscribeapi/buscribeapi.py index 52a7f8e..e90749a 100644 --- a/buscribe-api/buscribeapi/buscribeapi.py +++ b/buscribe-api/buscribeapi/buscribeapi.py @@ -118,27 +118,6 @@ def get_json(): def fetch_lines(db_conn, start_time, end_time, ts_query=None, limit=None, offset=None): - query = "SELECT *" + \ - ( - ",ts_headline(transcription_line, convert_query(%(text_query)s), 'StartSel='''', StopSel=') AS highlighted_text" if ts_query is not None else ",transcription_line AS highlighted_text") + \ - " FROM buscribe_all_transcriptions WHERE start_time >= %(start_time)s AND end_time <= %(end_time)s " - - if ts_query is not None: - query += "AND (coalesce(transcription_line_ts, ''::tsvector) || coalesce(names_ts, ''::tsvector)) @@ " \ - "convert_query(%(text_query)s) " \ - "ORDER BY ts_rank_cd(coalesce(transcription_line_ts, ''::tsvector) || coalesce(names_ts, ''::tsvector), convert_query(%(text_query)s)) DESC, " \ - "start_time " - else: - query += "ORDER BY start_time " - - if limit is not None: - query += "LIMIT %(limit)s " - - if offset is not None: - query += "OFFSET %(limit)s " - - query += ";" - query = f""" WITH q AS ( SELECT convert_query({"%(text_query)s" if ts_query is not None else "NULL"}) @@ -162,6 +141,14 @@ def fetch_lines(db_conn, start_time, end_time, ts_query=None, limit=None, offset start_time) """ + if limit is not None: + query += "LIMIT %(limit)s " + + if offset is not None: + query += "OFFSET %(limit)s " + + query += ";" + return database.query(db_conn, query, start_time=start_time if start_time is not None else '-infinity', end_time=end_time if end_time is not None else 'infinity',