Why does my search bar bypass my dataset filter?

Hi,

I’ve used the “How to Create a Search for your Database” tutorial (Wix Code | How to Create a Search for Your Database - YouTube) to create a search feature on different “normal” (Non dynamic) pages.
Each page is connected to data and has a dataset filter based on the name of a collection category. So one page has a collection A filter. Page two has a collection B filter etc.

The search bar works smoothly however, once I perform a search and empty out the search bar ALL the films appear in a random order on the page rather then the one filtered.
So page one has collection A displayed. I perform a search, nothing wrong. I empty the search bar. ALL the collections appear!

How can I prevent that from happening?

Here is my code so far:

$w.onReady(() => {
waitForLoading();
});

export function button6_onClick(event) {
$w(‘#group1’).show();
waitForLoading();
}

function waitForLoading() {
setTimeout(() => {
$w(‘#group1’).hide(‘FadeOut’);
}, 2500);
}

import wixData from ‘wix-data’;

let lastFilterTitle;
let lastFilterCollection;
let debounceTimer;
export function input1_keyPress(event, $w) {
if (debounceTimer) {
clearTimeout(debounceTimer);
debounceTimer = undefined;
}
debounceTimer = setTimeout(() => {
filter($w(‘#input1’).value, lastFilterCollection);
}, 500);
}

function filter(title, collection) {
if (lastFilterTitle !== title || lastFilterCollection !== collection) {
let newFilter = wixData.filter();
if (title)
newFilter = newFilter.contains(‘title’, title);
if (collection)
newFilter = newFilter.contains(‘collection’, collection);
$w(‘#dataset1’).setFilter(newFilter);
lastFilterTitle = title;
lastFilterCollection = collection;
}
}