|
|
@ -118,36 +118,51 @@ def get_json():
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
def fetch_lines(db_conn, start_time, end_time, ts_query=None, limit=None, offset=None):
|
|
|
|
def fetch_lines(db_conn, start_time, end_time, ts_query=None, limit=None, offset=None):
|
|
|
|
query = f"""
|
|
|
|
if ts_query is None:
|
|
|
|
WITH q AS (
|
|
|
|
query = "SELECT *" + \
|
|
|
|
SELECT convert_query({"%(text_query)s" if ts_query is not None else "NULL"})
|
|
|
|
",transcription_line AS highlighted_text" + \
|
|
|
|
)
|
|
|
|
" FROM buscribe_all_transcriptions WHERE start_time >= %(start_time)s AND end_time <= %(end_time)s " + \
|
|
|
|
(SELECT *, ts_headline(transcription_line, (SELECT * FROM q),
|
|
|
|
"ORDER BY start_time "
|
|
|
|
'StartSel=''<span class=\"highlight\">'', StopSel=</span>') AS highlighted_text
|
|
|
|
|
|
|
|
FROM buscribe_all_transcriptions2
|
|
|
|
if limit is not None:
|
|
|
|
WHERE start_time >= %(start_time)s AND end_time <= %(end_time)s
|
|
|
|
query += "LIMIT %(limit)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) ||" +
|
|
|
|
if offset is not None:
|
|
|
|
"coalesce(names_ts, ''::tsvector), (SELECT * FROM q)) DESC," if ts_query is not None else ""}
|
|
|
|
query += "OFFSET %(limit)s "
|
|
|
|
start_time)
|
|
|
|
|
|
|
|
UNION
|
|
|
|
query += ";"
|
|
|
|
(SELECT *, ts_headline(transcription_line, (SELECT * FROM q),
|
|
|
|
|
|
|
|
'StartSel=''<span class=\"highlight\">'', StopSel=</span>') AS highlighted_text
|
|
|
|
else:
|
|
|
|
FROM buscribe_all_transcriptions2
|
|
|
|
query = f"""
|
|
|
|
WHERE start_time >= %(start_time)s AND end_time <= %(end_time)s
|
|
|
|
WITH q AS (
|
|
|
|
{"AND machine_line_ts @@ (SELECT * FROM q)" if ts_query is not None else ""}
|
|
|
|
SELECT convert_query({"%(text_query)s" if ts_query is not None else "NULL"})
|
|
|
|
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 ""}
|
|
|
|
(SELECT *, ts_headline(transcription_line, (SELECT * FROM q),
|
|
|
|
start_time)
|
|
|
|
'StartSel=''<span class=\"highlight\">'', StopSel=</span>') AS highlighted_text
|
|
|
|
"""
|
|
|
|
FROM buscribe_all_transcriptions2
|
|
|
|
|
|
|
|
WHERE start_time >= %(start_time)s AND end_time <= %(end_time)s
|
|
|
|
if limit is not None:
|
|
|
|
{"AND verified_line_ts @@ (SELECT * FROM q)" if ts_query is not None else ""}
|
|
|
|
query += "LIMIT %(limit)s "
|
|
|
|
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 ""}
|
|
|
|
if offset is not None:
|
|
|
|
start_time)
|
|
|
|
query += "OFFSET %(limit)s "
|
|
|
|
UNION
|
|
|
|
|
|
|
|
(SELECT *, ts_headline(transcription_line, (SELECT * FROM q),
|
|
|
|
query += ";"
|
|
|
|
'StartSel=''<span class=\"highlight\">'', StopSel=</span>') 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) ||" +
|
|
|
|
|
|
|
|
"coalesce(names_ts, ''::tsvector), (SELECT * FROM q)) DESC," if ts_query is not None else ""}
|
|
|
|
|
|
|
|
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,
|
|
|
|
return database.query(db_conn, query,
|
|
|
|
start_time=start_time if start_time is not None else '-infinity',
|
|
|
|
start_time=start_time if start_time is not None else '-infinity',
|
|
|
|