Skip to content

Commit

Permalink
fix for the empty matches error
Browse files Browse the repository at this point in the history
  • Loading branch information
madneal committed Jan 2, 2025
1 parent 92a9d8c commit dec4932
Showing 1 changed file with 14 additions and 10 deletions.
24 changes: 14 additions & 10 deletions web/src/view/searchResult/searchResult.vue
Original file line number Diff line number Diff line change
Expand Up @@ -265,17 +265,21 @@ export default {
}
let result = "";
for (let i = 0; i < val.length; i++) {
const matches = val[i].matches;
let index = [];
matches.forEach(ele => {
index = index.concat(ele.indices);
});
let fragment = val[i].fragment;
fragment = fragment.slice(0, index[0]) + "" + fragment.slice(index[0]);
fragment = fragment.slice(0, index[index.length-1]+1) + "" + fragment.slice(index[index.length-1]+1);
result = result + fragment;
const fragment = val[i].fragment;
if (!val[i].matches) {
result += fragment;
} else {
const matches = val[i].matches;
let index = [];
matches.forEach(ele => {
index = index.concat(ele.indices);
});
let processedFragment = fragment.slice(0, index[0]) + "" + fragment.slice(index[0]);
processedFragment = processedFragment.slice(0, index[index.length-1]+1) + "" + processedFragment.slice(index[index.length-1]+1);
result += processedFragment;
}
if (i !== val.length - 1) {
result = result + "\n=====================================\n";
result += "\n=====================================\n";
}
}
return result;
Expand Down

0 comments on commit dec4932

Please sign in to comment.