Add highlighting

pull/414/head
HeNine 3 years ago
parent 25dc6c4261
commit 9803098a3d

@ -95,16 +95,19 @@ def get_json():
"end_bus_time": round_bus_time(row.start_time - app.bustime_start),
"verifier": row.verifier,
"speakers": row.names,
"text": row.transcription_line if row.transcription_line is not None else ""} for row in results])
"text": row.highlighted_text if row.highlighted_text is not None else ""} for row in results])
def fetch_lines(db_conn, start_time, end_time, ts_query=None, limit=None, offset=None):
query = "SELECT * FROM buscribe_all_transcriptions WHERE start_time > %(start_time)s AND end_time < %(end_time)s "
query = "SELECT *" + \
(
",ts_headline(transcription_line, convert_query(%(text_query)s), 'StartSel=''<span class=\"highlight\">'', StopSel=</span>') 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)) @@ " \
"(CASE WHEN websearch_to_tsquery(%(text_query)s)::text != '' THEN websearch_to_tsquery(%(text_query)s)::text || ':*' ELSE '' END)::tsquery " \
"ORDER BY ts_rank_cd(coalesce(transcription_line_ts, ''::tsvector) || coalesce(names_ts, ''::tsvector), (CASE WHEN websearch_to_tsquery(%(text_query)s)::text != '' THEN websearch_to_tsquery(%(text_query)s)::text || ':*' ELSE '' END)::tsquery) DESC, " \
"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 "
@ -117,6 +120,8 @@ def fetch_lines(db_conn, start_time, end_time, ts_query=None, limit=None, offset
query += ";"
print(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',

@ -44,6 +44,10 @@
grid-column: text;
//grid-row: span 2;
span.highlight {
font-weight: bold;
color: powderblue;
}
}
.line_speakers {

@ -111,4 +111,14 @@ SELECT id,
null AS names_ts
FROM buscribe_transcriptions;
ROLLBACK;
ROLLBACK;
-- Convert last lexeme in a query to prefix query.
CREATE FUNCTION convert_query(query_text text) RETURNS tsquery AS
$$
DECLARE
ws_query text := websearch_to_tsquery(query_text)::text;
BEGIN
RETURN (CASE WHEN ws_query != '' THEN ws_query || ':*' ELSE '' END)::tsquery;
END;
$$ LANGUAGE plpgsql;
Loading…
Cancel
Save