filter only movies matching query

This commit is contained in:
SansGuidon 2025-05-25 02:42:29 +02:00
parent 7d234903d1
commit 635d21524d
2 changed files with 12 additions and 1 deletions

View File

@ -1 +1 @@
0.0.6
0.0.7

View File

@ -72,6 +72,17 @@ function mergeResults(arrays, query = '', limit = 5) {
if (query) {
out.forEach(f => f.__score = getMatchScore(f, query));
out = out.sort((a, b) => b.__score - a.__score);
// PATCH: filter only films with ALL significant query words in title
const normQuery = query.trim().toLowerCase();
const skip = new Set(['the','le','la','les','de','du','des','and','et','a','an','un','une','dans','en','on']);
const queryWords = normQuery.split(/\s+/).filter(w => w.length > 3 && !skip.has(w));
if (queryWords.length) {
out = out.filter(film => {
const title = (film.title || '').toLowerCase();
return queryWords.every(qw => title.includes(qw));
});
}
}
// Remove internals, trim to limit
return out.slice(0, limit).map(f => {