From a386158b30314a96171ff1ec2772d3a62b25663d Mon Sep 17 00:00:00 2001 From: Sebastian Lay Date: Tue, 2 Aug 2022 00:07:46 +0200 Subject: [PATCH] Improved search to better handle multiple terms --- js/script-index.js | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/js/script-index.js b/js/script-index.js index fed8114..9bfc153 100644 --- a/js/script-index.js +++ b/js/script-index.js @@ -12,9 +12,12 @@ Vue.createApp({ computed: { searchedfilms: function() { if(this.search) { - var search = this.search.toLowerCase(); + var searchTerms = this.search.toLowerCase().split(' '); 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 { return this.currentfilms;