Improved search to better handle multiple terms

This commit is contained in:
Sebastian Lay 2022-08-02 00:07:46 +02:00
parent 65a0ed616d
commit a386158b30
No known key found for this signature in database
GPG Key ID: A699D9B80D6068AA

View File

@ -12,9 +12,12 @@ Vue.createApp({
computed: { computed: {
searchedfilms: function() { searchedfilms: function() {
if(this.search) { if(this.search) {
var search = this.search.toLowerCase(); var searchTerms = this.search.toLowerCase().split(' ');
return this.currentfilms.filter(function (film) { return this.currentfilms.filter(function (film) {
return film.name.toLowerCase().indexOf(search) !== -1 || film.description.toLowerCase().indexOf(search) !== -1; const name = film.name.toLowerCase();
const description = film.description.toLowerCase();
const matches = (searchTerm) => name.includes(searchTerm) || description.includes(searchTerm);
return searchTerms.every(matches);
}); });
} else { } else {
return this.currentfilms; return this.currentfilms;