Creating a searchable database

According to this video , a search feature can filter database elements. The following code block filters search results:

let lastFilterTitle;
function filter(title) {
 if (lastFilterTitle !== title) {
        $w('#dataset1').setFilter(wixData.filter().contains('articleTitle', title));
        lastFilterTitle = title;
    }
}

My question is, what is #dataset1 referencing? Is it the articles collection? If #dataset1 is the ID for the articles collection, how can I locate the ID for my own collection?

My search feature is not working correctly. I’m getting TypeError: $w(…).setFilter is not a function.

My code blocks look like this:

import wixData from "wix-data";

let debounceTimer;
export function librarySearch_keyPress(event, $w) {
 if (debounceTimer) {
        clearTimeout(debounceTimer);
        debounceTimer = undefined;
    }

    debounceTimer = setTimeout(() => {
        filter($w('#librarySearch').value);
    }, 200); 
}

let lastFilterMake;
function filter(make) {
 if (lastFilterMake !== make) {
        $w('#dataset1').setFilter(wixData.filter().contains('make', make));
        lastFilterMake = make;
    }
}

Hello Drew

Can you provide me a link to your site. I want to see what your trying to do.
I may have an easy fix for you.

Thanks Simon

Hi Simon, thanks for replying.

I’ve sorted out the ID question that I had. I’m trying to filter images by ‘make’ and ‘model’. Right now, I can filter by ‘make’ but filtering by ‘model’ renders nothing. Here is the link .

Here is my code:


import wixData from "wix-data";

let lastFilterMake; 
let lastFilterModel;
let debounceTimer;
export function librarySearch_keyPress(event, $w) {
 if (debounceTimer) {
        clearTimeout(debounceTimer);
        debounceTimer = undefined;
    }

    debounceTimer = setTimeout(() => {
        filter($w('#librarySearch').value, lastFilterModel);
    }, 200);
}

function filter(make, model) {
 if (lastFilterMake !== make || lastFilterModel !== model) {
 let newFilter = wixData.filter();
 
 if (make)
            newFilter = newFilter.contains('make', make);
 if (model)
            newFilter = newFilter.contains('model', model);

        $w('#libraryDataset').setFilter(newFilter);
        lastFilterMake = make;
        lastFilterModel = model;
    }
}