feat(live): add language-aware flexible channel search (#23)
Add backend language detection, flexible live channel search, iptv-org catalog caching, and protected built-in EPG source registration. Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
This commit is contained in:
19
server/services/flexibleChannelSearch.js
Normal file
19
server/services/flexibleChannelSearch.js
Normal file
@ -0,0 +1,19 @@
|
||||
function normalizeSearch(value) {
|
||||
return String(value || '')
|
||||
.normalize('NFKD').replace(/[\u0300-\u036f]/g, '')
|
||||
.toLowerCase().replace(/[^a-z0-9]+/g, ' ').trim()
|
||||
.split(/\s+/).filter(Boolean)
|
||||
.map(token => token.length > 3 && token.endsWith('s') ? token.slice(0, -1) : token);
|
||||
}
|
||||
|
||||
function matchesSearch(channel, query) {
|
||||
const wanted = normalizeSearch(query);
|
||||
if (!wanted.length) return true;
|
||||
const corpus = normalizeSearch([
|
||||
channel.displayName, channel.standardName, channel.fingerprint,
|
||||
...(channel.variants || []).flatMap(variant => [variant.name, variant.tvgId, variant.categoryName])
|
||||
].filter(Boolean).join(' '));
|
||||
return wanted.every(token => corpus.some(candidate => candidate.includes(token)));
|
||||
}
|
||||
|
||||
module.exports = { matchesSearch, normalizeSearch };
|
||||
Reference in New Issue
Block a user