diff --git a/app/corpora/events.py b/app/corpora/events.py index 974792f6..a597f8e6 100644 --- a/app/corpora/events.py +++ b/app/corpora/events.py @@ -43,13 +43,13 @@ def recv_query(message): analysis_client = analysis_clients[request.sid] """ Prepare and execute a query """ corpus = 'CORPUS' - query = '"and";' + query = message['query'] query_subcorpus = 'Results' analysis_client.cqp_query(corpus, query_subcorpus, query) """ Evaluate query results """ match_corpus = '{}:{}'.format(corpus, query_subcorpus) match_num = analysis_client.cqp_subcorpus_size(match_corpus) - match_num = min(19, match_num) + match_num = min(int(message['hits_per_page']) - 1, match_num) if match_num == 0: print('No matches found.') exit() @@ -67,6 +67,7 @@ def recv_query(message): pos = analysis_client.cl_cpos2str('{}.pos'.format(corpus), range(match_start, match_end + 1)) matches.append({'tokens': tokens, 'pos': pos}) logger.warning(matches) + socketio.emit('query_results', matches, room=request.sid) def observe_corpus_analysis_connection(app, corpus_id, session_id): diff --git a/app/templates/corpora/corpus_analysis.html.j2 b/app/templates/corpora/corpus_analysis.html.j2 index edba6c56..ed35532a 100644 --- a/app/templates/corpora/corpus_analysis.html.j2 +++ b/app/templates/corpora/corpus_analysis.html.j2 @@ -76,18 +76,17 @@ socket.on('query_results', function(json_results) { console.log('Results recieved') console.log(json_results) - let json_results = json_results; + var queryResultsElement = document.getElementById("query-results"); + for (let json_result of json_results) { + queryResultsElement.innerHTML += json_result['tokens'] + '
'; + } });
Query Results - - {% for hit in json_results %} - - {% endfor %} -
+