diff --git a/VERSION b/VERSION index bcab45a..81340c7 100644 --- a/VERSION +++ b/VERSION @@ -1 +1 @@ -0.0.3 +0.0.4 diff --git a/aggregators/cinecheck-adapter.js b/aggregators/cinecheck-adapter.js index a6e7ca5..9ece1b6 100644 --- a/aggregators/cinecheck-adapter.js +++ b/aggregators/cinecheck-adapter.js @@ -45,6 +45,11 @@ async function getMovieClassification(movieUrl) { const label = $(el).find('span.vh').text().trim(); if (label) marks.push(label); }); + const normalizedMarks = marks.map(m => { + // Extract first number found, else null + const n = parseInt((m + '').replace(/\D/g, ''), 10); + return isNaN(n) ? null : n; + }).filter(x => x !== null); const details = []; $('.c-classificatie__item').each((_, el) => { const type = $(el).find('svg use').first().attr('xlink:href') || ''; @@ -61,6 +66,7 @@ async function getMovieClassification(movieUrl) { genres, img, marks, + normalizedMarks, details, summary }; diff --git a/merge.js b/merge.js index 87bcd01..65daaee 100644 --- a/merge.js +++ b/merge.js @@ -1,21 +1,28 @@ -// Utilitaire pour merger les résultats de plusieurs agrégateurs function normalizeTitle(str) { return str ? str.toLowerCase().replace(/[^a-z0-9]/g, '') : ''; } -function normalizeTitle(str) { - return str ? str.toLowerCase().replace(/[^a-z0-9]/g, '') : ''; +// Compute match score: exact > startsWith > includes > other +function getMatchScore(film, query) { + const nTitle = normalizeTitle(film.title); + const nQuery = normalizeTitle(query); + if (nTitle === nQuery) return 100; + if (nTitle.startsWith(nQuery)) return 80; + if (nTitle.includes(nQuery)) return 60; + return 10; } -function mergeResults(arrays) { + +// Merge and rank by match +function mergeResults(arrays, query = '', limit = 5) { const map = {}; arrays.flat().forEach(entry => { - // Note: only title, fallback if no year const key = normalizeTitle(entry.title) + (entry.year ? '|' + entry.year : ''); if (!map[key]) { map[key] = { title: entry.title, year: entry.year, - results: [] + results: [], + __raw: entry // For tie-break }; } map[key].results.push({ @@ -23,7 +30,16 @@ function mergeResults(arrays) { ...entry }); }); - return Object.values(map); + let out = Object.values(map); + if (query) { + out.forEach(f => f.__score = getMatchScore(f, query)); + out = out.sort((a, b) => b.__score - a.__score); + } + // Remove internals, trim to limit + return out.slice(0, limit).map(f => { + delete f.__score; delete f.__raw; + return f; + }); } module.exports = { mergeResults }; diff --git a/public/index.html b/public/index.html index 60df297..e0d54f3 100644 --- a/public/index.html +++ b/public/index.html @@ -41,107 +41,148 @@
- + } + document.getElementById('q').addEventListener('keydown', e => { if (e.key === 'Enter') search(); }); +