Add word highlights for "expression-based" accounts search

This commit is contained in:
Bofh 2022-12-14 22:50:47 +01:00
parent 36da78d804
commit 717d1bba06
1 changed files with 21 additions and 4 deletions

View File

@ -27,17 +27,34 @@ window.view.instance = {
}, },
html_add_search_spans: function(html, search) { html_add_search_spans: function(html, search) {
search = search.trim(); search = search.trim();
const hwords = html.split(/\b/);
if (search.startsWith('expr:')) { if (search.startsWith('expr:')) {
console.log('EXPR'); search = search.substr(5).trim();
var sxs = search.replaceAll('(', '').replaceAll(')','').split(/OR|AND/);
for (var i = 0; i < sxs.length; i++) {
var sx = sxs[i].trim();
if (sx.startsWith('!'))
continue;
sx = sx.substr(sx.indexOf('"')+1);
sx = sx.substr(0, sx.indexOf('"'));
sx = sx.trim().split(' ');
for (var j = 0; j < sx.length; j++) {
const w = sx[j];
for (var k = 0; k < hwords.length; k++) {
const h = hwords[k];
if (normalize_for_search(h).includes(normalize_for_search(w)))
html = html.replaceAll(h, '<span class="sr">'+h+'</span>');
}
}
}
} else { } else {
search = search.toLowerCase(); search = search.toLowerCase();
const words = search.split(' '); const words = search.split(' ');
const hwords = html.split(/\b/);
for (var i = 0; i < words.length; i++) { for (var i = 0; i < words.length; i++) {
const w = words[i]; const w = words[i];
for (var j = 0; j < hwords.length; j++) { for (var j = 0; j < hwords.length; j++) {
const h = hwords[j]; const h = hwords[j];
if (normalize_for_search(h).startsWith(normalize_for_search(w))) if (normalize_for_search(h).includes(normalize_for_search(w)))
html = html.replaceAll(h, '<span class="sr">'+h+'</span>'); html = html.replaceAll(h, '<span class="sr">'+h+'</span>');
} }
} }
@ -255,7 +272,7 @@ window.view.instance = {
payload = JSON_to_URLEncoded(payload); payload = JSON_to_URLEncoded(payload);
page = page === undefined ? 1 : page; page = page === undefined ? 1 : page;
items_per_page = items_per_page === undefined ? 10 : items_per_page; items_per_page = items_per_page === undefined ? 20 : items_per_page;
if (page === 'null') return; if (page === 'null') return;
page--; if (page < 0) page = 0; page--; if (page < 0) page = 0;