From dd4dede5cdb7e7b8956ab41752eb264413fb487f Mon Sep 17 00:00:00 2001 From: HeNine <> Date: Tue, 16 Nov 2021 14:08:48 +0100 Subject: [PATCH] search optimization 2 --- buscribe-api/buscribeapi/buscribeapi.py | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/buscribe-api/buscribeapi/buscribeapi.py b/buscribe-api/buscribeapi/buscribeapi.py index 517719b..52a7f8e 100644 --- a/buscribe-api/buscribeapi/buscribeapi.py +++ b/buscribe-api/buscribeapi/buscribeapi.py @@ -141,14 +141,14 @@ def fetch_lines(db_conn, start_time, end_time, ts_query=None, limit=None, offset query = f""" WITH q AS ( - SELECT convert_query(${"%(text_query)s" if ts_query is not None else ""}) + SELECT convert_query({"%(text_query)s" if ts_query is not None else "NULL"}) ) (SELECT *, ts_headline(transcription_line, (SELECT * FROM q), 'StartSel='''', StopSel=') AS highlighted_text FROM buscribe_all_transcriptions2 WHERE start_time >= %(start_time)s AND end_time <= %(end_time)s - ${"AND verified_line_ts @@ (SELECT * FROM q)" if ts_query is not None else ""} - ORDER BY ${"ts_rank_cd(coalesce(transcription_line_ts, ''::tsvector) ||" + + {"AND verified_line_ts @@ (SELECT * FROM q)" if ts_query is not None else ""} + ORDER BY {"ts_rank_cd(coalesce(transcription_line_ts, ''::tsvector) ||" + "coalesce(names_ts, ''::tsvector), (SELECT * FROM q)) DESC," if ts_query is not None else ""} start_time) UNION @@ -156,8 +156,8 @@ def fetch_lines(db_conn, start_time, end_time, ts_query=None, limit=None, offset 'StartSel='''', StopSel=') AS highlighted_text FROM buscribe_all_transcriptions2 WHERE start_time >= %(start_time)s AND end_time <= %(end_time)s - ${"AND machine_line_ts @@ (SELECT * FROM q)" if ts_query is not None else ""} - ORDER BY ${"ts_rank_cd(coalesce(transcription_line_ts, ''::tsvector) ||" + + {"AND machine_line_ts @@ (SELECT * FROM q)" if ts_query is not None else ""} + ORDER BY {"ts_rank_cd(coalesce(transcription_line_ts, ''::tsvector) ||" + "coalesce(names_ts, ''::tsvector), (SELECT * FROM q)) DESC," if ts_query is not None else ""} start_time) """