Multiple search term types for database

I followed the Wix Search a Database example ( https://www.wix.com/corvid/example/search-a-database ) to create a search bar for my database and removed the code for the dropdown menu. Right now, my code is set to just search for “authors” but I would like to add the ability to pull results based on multiple variables. For example, I would like to be able to expand the search from just “authors” to also search “description” and “title.” So, someone could type in “John Smith” or they could type in “mental health.” How do I do this?

import wixData from "wix-data";
  
let lastFilterauthor;
let debounceTimer;
export function iSearch_keyPress(event, $w) {
 if (debounceTimer) {
    clearTimeout(debounceTimer);
    debounceTimer = undefined;
  }
  debounceTimer = setTimeout(() => {
    filter($w('#iSearch').value, lastFilterauthor);  
  }, 500);
}
  
function filter(author) {
 if (lastFilterauthor !== author) {
 let newFilter = wixData.filter();
 if (author)
      newFilter = newFilter.contains('author', author);
    $w('#dataset1').setFilter(newFilter);       
    lastFilterauthor = author; 
  }
}

Hi.

WixDataFilter has a handy method .or() which can help you in this case. You can combine two conditions like this:

const filterValue = $w("#filterInput").value
const byTitle = wixData.filter().contains("title", filterValue)
const byField2 = wixData.filter().contains("field2", filterValue)
$w("#dataset1").setFilter(byTitle.or(byField2))

Good luck!

Thank you for this!! However, when I try using this code, I get the following error:

TypeError: $w(...).setFilter is not a function

Any ideas?

Example;

import wixData from ‘wix-data’;
$w.onReady(function () {
});
export function input1_keypress() {
wixData.query(‘Meditations’)
.or(wixData.query(‘Meditations’).contains(’ title’ , $w(’ #input1 ‘).value))
.or(wixData.query(‘Meditations’).contains(’ code ‘, $w(’ #input1 ‘).value))
.or(wixData.query(‘Meditations’).contains(’ author ‘, $w(’ #input1 ‘).value))
.find()
.then(res => {
$w(’ #table1 ').rows = res.items;
});
}