filter only movies matching query
This commit is contained in:
parent
7d234903d1
commit
635d21524d
11
merge.js
11
merge.js
@ -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 => {
|
||||
|
Loading…
x
Reference in New Issue
Block a user