Keyword search for multiple fields

If anyone is trying to create a page with a single search field that will search multiple fields within a database, you can try this code. My results are displayed in a table connected to a dataset.

import wixData from "wix-data";

$w.onReady(function (){

});

let debounceTimer;
export function iSearchBar_keyPress(event, $w) {
   if (debounceTimer) {
      clearTimeout(debounceTimer);
      debounceTimer = undefined;
   }
   debounceTimer = setTimeout(() => {
      filter($w('#iSearchBar').value);
   }, 200);
}

function filter(title, contact, postcode) {
   $w('#dataset1').setFilter(wixData.filter()
   .contains('title', $w('#iSearchBar').value)
      .or(wixData.filter()
         .contains('contact', $w('#iSearchBar').value))
            .or(wixData.filter()
               .contains('postcode', $w('#iSearchBar').value))
            )
}

Thank you for your contribution. It would be even more helpful if you nicely formatted your code and put it into a Code Block to make it easeir to read.

Here’s how you can add a code block:

Thanks, Yisrael, fixed now :slight_smile: