First output of query results

This commit is contained in:
Patrick Jentsch 2019-11-12 16:45:54 +01:00
parent 28171eb525
commit 1152417419
2 changed files with 8 additions and 8 deletions

View File

@ -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):

View File

@ -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'] + '<br>';
}
});
</script>
<div class="col s12 m9 l9">
<div class="card">
<div class="card-content">
<span class="card-title">Query Results</span>
<table class="responsive highlight">
{% for hit in json_results %}
{% endfor %}
</table>
<p id="query-results"></p>
</div>
</div>
</div>