diff --git a/buscribe-api/buscribeapi/buscribeapi.py b/buscribe-api/buscribeapi/buscribeapi.py
index e90749a..2c78810 100644
--- a/buscribe-api/buscribeapi/buscribeapi.py
+++ b/buscribe-api/buscribeapi/buscribeapi.py
@@ -118,36 +118,51 @@ def get_json():
def fetch_lines(db_conn, start_time, end_time, ts_query=None, limit=None, offset=None):
- query = f"""
- WITH q AS (
- 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) ||" +
- "coalesce(names_ts, ''::tsvector), (SELECT * FROM q)) DESC," if ts_query is not None else ""}
- start_time)
- UNION
- (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 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 += ";"
+ if ts_query is None:
+ query = "SELECT *" + \
+ ",transcription_line AS highlighted_text" + \
+ " FROM buscribe_all_transcriptions WHERE start_time >= %(start_time)s AND end_time <= %(end_time)s " + \
+ "ORDER BY start_time "
+
+ if limit is not None:
+ query += "LIMIT %(limit)s "
+
+ if offset is not None:
+ query += "OFFSET %(limit)s "
+
+ query += ";"
+
+ else:
+ query = f"""
+ WITH q AS (
+ 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) ||" +
+ "coalesce(names_ts, ''::tsvector), (SELECT * FROM q)) DESC," if ts_query is not None else ""}
+ start_time)
+ UNION
+ (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 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,
start_time=start_time if start_time is not None else '-infinity',