Add word highlights for "expression-based" accounts search
This commit is contained in:
parent
36da78d804
commit
717d1bba06
|
@ -27,17 +27,34 @@ window.view.instance = {
|
|||
},
|
||||
html_add_search_spans: function(html, search) {
|
||||
search = search.trim();
|
||||
const hwords = html.split(/\b/);
|
||||
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 {
|
||||
search = search.toLowerCase();
|
||||
const words = search.split(' ');
|
||||
const hwords = html.split(/\b/);
|
||||
for (var i = 0; i < words.length; i++) {
|
||||
const w = words[i];
|
||||
for (var j = 0; j < hwords.length; 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>');
|
||||
}
|
||||
}
|
||||
|
@ -255,7 +272,7 @@ window.view.instance = {
|
|||
payload = JSON_to_URLEncoded(payload);
|
||||
|
||||
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;
|
||||
page--; if (page < 0) page = 0;
|
||||
|
||||
|
|
Loading…
Reference in New Issue