How to make a search bar with multiple parameters/properties to search on

Hi Developers!

Currently I have this problem where i need to create a search bar on my site, which allows the users to search on both title and description and maybe one more parameter.

I have this code which works on only 1 parameter, in this case the title (properties “title”) but not on the description (properties “beskrivelse”)

import wixData from “wix-data”;

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

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

I would like it to work as following:

  1. A user types “tomatsuppe” and finds the recipie for “tomatsuppe” because it is the title
    2 A user types “tomater” and find the same recipie, because “tomater” is a word from the description

I hope that you can help me out here! :slight_smile:

My site is https://alexanderweidinger.wixsite.com/test

OBS: If i switch “title” and “beskrivelse” in the code:
function filter(title, beskrivelse) {
example: function filter(beskrivelse, title) {
So it is “beskrivelse” which stands first it works with “beskrivelse” instead of “title”