Show right match_count per text, not per last incoming chunk

This commit is contained in:
Stephan Porada 2020-10-09 16:15:47 +02:00
parent baebdbe399
commit 4ec3ce01fa
2 changed files with 19 additions and 2 deletions

View File

@ -33,13 +33,24 @@ function prepareQueryData() {
*/ */
function saveQueryData() { function saveQueryData() {
let [payload, client, results, rest] = arguments; let [payload, client, results, rest] = arguments;
// Get data matches length before new chunk data is being inserted
let dataLength = results.data.matches.length; let dataLength = results.data.matches.length;
if (client.dynamicMode) { if (client.dynamicMode) {
// get data matches length before new chunk data is being inserted // Incorporating new chunk data into full results
// incorporating new chunk data into full results
results.data.matches.push(...payload.chunk.matches); results.data.matches.push(...payload.chunk.matches);
results.data.addData(payload.chunk.cpos_lookup, 'cpos_lookup'); results.data.addData(payload.chunk.cpos_lookup, 'cpos_lookup');
results.data.addData(payload.chunk.text_lookup, 'text_lookup'); results.data.addData(payload.chunk.text_lookup, 'text_lookup');
console.log(payload.chunk.text_lookup);
/**
* Increment match_counts per text in a global results varaible because
* they are coming in chunkwise.
*/
for (let [text_key, value] of Object.entries(payload.chunk.text_lookup)) {
if (!(text_key in results.tmp_match_counts)) {
results.tmp_match_counts[text_key] = {match_count: 0};
}
results.tmp_match_counts[text_key].match_count += payload.chunk.text_lookup[text_key].match_count;
}
results.data.cpos_ranges = payload.chunk.cpos_ranges; results.data.cpos_ranges = payload.chunk.cpos_ranges;
let queryFormElement = document.querySelector('#query-form'); let queryFormElement = document.querySelector('#query-form');
results.data.getQueryStr(queryFormElement); results.data.getQueryStr(queryFormElement);
@ -51,6 +62,10 @@ function saveQueryData() {
console.info('Query data chunk saved', results.data); console.info('Query data chunk saved', results.data);
if (client.requestQueryProgress === 100) { if (client.requestQueryProgress === 100) {
client.isBusy = false; client.isBusy = false;
// Update text_lookup with tmp_match_counts.
for (let [text_key, value] of Object.entries(results.tmp_match_counts)) {
results.data.text_lookup[text_key].match_count = results.tmp_match_counts[text_key].match_count;
}
client.notifyView('query-data-recieved'); client.notifyView('query-data-recieved');
} }
} else { } else {

View File

@ -22,6 +22,8 @@ class Results {
this.fullResultsData.init(); this.fullResultsData.init();
this.subResultsData.init(); this.subResultsData.init();
this.inspectResultsData.init(); this.inspectResultsData.init();
// Temporarly save match counts per text
this.tmp_match_counts = {};
} }
} }