fix(live): tighten beIN Sports search matching (#27)

Require numeric query tokens to match numeric channel tokens exactly while preserving singular/plural and compact-name tolerance.

Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
This commit is contained in:
blomios
2026-10-06 17:48:28 +02:00
parent 0122df9489
commit ab554e12a4
4 changed files with 56 additions and 5 deletions

View File

@ -1214,7 +1214,7 @@
<script src="/js/services/channelLanguageFusion.js?v=1"></script>
<script src="/js/services/layaStatusPresentation.js?v=5"></script>
<script src="/js/services/liveAnalysisPresentation.js?v=1"></script>
<script src="/js/services/liveChannelProjection.js?v=4"></script>
<script src="/js/services/liveChannelProjection.js?v=5"></script>
<script src="/js/services/channelVariantGrouping.js?v=7"></script>
<script src="/js/components/ChannelList.js?v=13"></script>
<script src="/js/components/SourceManager.js?v=4"></script>

View File

@ -6,7 +6,10 @@
function normalizeSearch(value) {
return String(value || '')
.normalize('NFKD').replace(/[\u0300-\u036f]/g, '')
.toLowerCase().replace(/[^a-z0-9]+/g, ' ').trim()
.toLowerCase()
.replace(/([a-z])([0-9])/g, '$1 $2')
.replace(/([0-9])([a-z])/g, '$1 $2')
.replace(/[^a-z0-9]+/g, ' ').trim()
.split(/\s+/).filter(Boolean)
.map(token => token.length > 3 && token.endsWith('s') ? token.slice(0, -1) : token);
}
@ -20,7 +23,10 @@
variant.name, variant.tvgId, variant.categoryName, variant.groupTitle
])
].filter(Boolean).join(' '));
return wanted.every(token => corpus.some(candidate => candidate.includes(token)));
return wanted.every(token => corpus.some(candidate => {
if (/^\d+$/.test(token)) return /^\d+$/.test(candidate) && Number(candidate) === Number(token);
return candidate.includes(token);
}));
}
function normalizeLanguage(language) {

View File

@ -1,7 +1,10 @@
function normalizeSearch(value) {
return String(value || '')
.normalize('NFKD').replace(/[\u0300-\u036f]/g, '')
.toLowerCase().replace(/[^a-z0-9]+/g, ' ').trim()
.toLowerCase()
.replace(/([a-z])([0-9])/g, '$1 $2')
.replace(/([0-9])([a-z])/g, '$1 $2')
.replace(/[^a-z0-9]+/g, ' ').trim()
.split(/\s+/).filter(Boolean)
.map(token => token.length > 3 && token.endsWith('s') ? token.slice(0, -1) : token);
}
@ -13,7 +16,10 @@ function matchesSearch(channel, query) {
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)));
return wanted.every(token => corpus.some(candidate => {
if (/^\d+$/.test(token)) return /^\d+$/.test(candidate) && Number(candidate) === Number(token);
return candidate.includes(token);
}));
}
module.exports = { matchesSearch, normalizeSearch };

View File

@ -0,0 +1,39 @@
const test = require('node:test');
const assert = require('node:assert/strict');
const backendSearch = require('../server/services/flexibleChannelSearch');
const frontendProjection = require('../public/js/services/liveChannelProjection.js');
function channel(displayName) {
return {
displayName,
standardName: displayName,
fingerprint: displayName.toLowerCase(),
variants: [{
name: `${displayName} HD`,
tvgId: displayName.replace(/\s+/g, '.').toLowerCase(),
categoryName: 'Sports',
groupTitle: 'Sports'
}]
};
}
test('backend beIN search keeps singular/plural tolerance without matching Max channels', () => {
assert.equal(backendSearch.matchesSearch(channel('beIN Sports 1'), 'bein sports 1'), true);
assert.equal(backendSearch.matchesSearch(channel('beIN Sports 1'), 'Bein Sport 1'), true);
assert.equal(backendSearch.matchesSearch(channel('beIN Sports Max 10'), 'bein sports 1'), false);
assert.equal(backendSearch.matchesSearch(channel('beIN Sports Max 4'), 'bein sports 1'), false);
assert.equal(backendSearch.matchesSearch(channel('beIN Sports 2'), 'bein sports 1'), false);
assert.equal(backendSearch.matchesSearch(channel('beINSports1'), 'bein sports 1'), true);
assert.equal(backendSearch.matchesSearch(channel('beIN Sports 01'), 'bein sports 1'), true);
});
test('frontend local beIN search mirrors backend Max-channel exclusion', () => {
assert.equal(frontendProjection.matchesSearch(channel('beIN Sports 1'), 'bein sports 1'), true);
assert.equal(frontendProjection.matchesSearch(channel('beIN Sports 1'), 'Bein Sport 1'), true);
assert.equal(frontendProjection.matchesSearch(channel('beIN Sports Max 10'), 'bein sports 1'), false);
assert.equal(frontendProjection.matchesSearch(channel('beIN Sports Max 4'), 'bein sports 1'), false);
assert.equal(frontendProjection.matchesSearch(channel('beIN Sports 2'), 'bein sports 1'), false);
assert.equal(frontendProjection.matchesSearch(channel('beINSports1'), 'bein sports 1'), true);
assert.equal(frontendProjection.matchesSearch(channel('beIN Sports 01'), 'bein sports 1'), true);
});