Search in multiple database columns

Hello, I have a database collection in Wix that displays some information but importantly that uses search and dropdown filters functionality and where I need help:

  • Business name by searching
  • Owner type by dropdown filter
  • City/State by dropdown filter
  • Product and Service by dropdown filter

I need to be able to search the service name as well from the search box without impacting the existing Product and service dropdown.

Here’s my code:


import wixData from "wix-data";

$w.onReady(() => {
    wixData.query('Directory')
 .find()
 .then(res => {
 let options = [{"value": '', 'label': 'All Cities'}];
        options.push(...res.items.map(city => {
 return {'value': city.cityState, 'label': city.cityState};
 }));
        $w('#iCity').options = options;
 })
})

$w.onReady(() => {
    wixData.query('Directory')
 .find()
 .then(res => {
 let options = [{"value": '', 'label': 'Select'}];
        options.push(...res.items.map(owners => {
 return {'value': owners.ownerType, 'label': owners.ownerType};
 }));
        $w('#iOwners').options = options;
 })
})

$w.onReady(() => {
    wixData.query('Directory')
 .find()
 .then(res => {
 let options = [{"value": '', 'label': 'Select'}];
        options.push(...res.items.map(productServices => {
 return {'value': productServices.productServiceType, 'label': productServices.productServiceType};
 }));
        $w('#iServices').options = options;
 })
})

let lastFilterTitle;
let lastFilterCity;
let lastFilterOwner;
let lastFilterServices;

let debounceTimer;
export function iTitle_keyPress(event, $w) {
 if (debounceTimer) {
        clearTimeout(debounceTimer);
        debounceTimer = undefined;
 }
    debounceTimer = setTimeout(() => {
    filter($w('#iTitle').value, lastFilterCity, lastFilterOwner, lastFilterServices);
 }, 500);
 
}

function filter(title, city, owners, productServices) {
 if (lastFilterTitle !== title || lastFilterCity !== city || lastFilterOwner !== owners || lastFilterServices !== productServices) {
 let newFilter = wixData.filter();
 if (title)
            newFilter = newFilter.contains('title', title);
 if (city)
            newFilter = newFilter.eq('cityState', city);
 if (owners)
            newFilter = newFilter.eq('ownerType', owners);
 if (productServices)
            newFilter = newFilter.eq('productServiceType', productServices);
 
        $w('#dataset1').setFilter(newFilter);
        lastFilterTitle = title;
        lastFilterCity = city;
        lastFilterOwner = owners;
        lastFilterServices = productServices;
 }
}

export function iCity_change(event, $w) {
    filter(lastFilterTitle, $w('#iCity').value, lastFilterOwner, lastFilterServices);
}

export function iOwners_change_2(event, $w) {
    filter(lastFilterTitle, lastFilterCity, $w('#iOwners').value, lastFilterServices);
}

export function iServices_change_1(event, $w) {
    filter(lastFilterTitle, lastFilterCity, lastFilterOwner, $w('#iServices').value);
}

I tried several things but none of them seems to be working. Any help is appreciated.

Searching for somethink like this?
https://www.media-junkie.com/pflegeservice

Tried to search but nothing shows up on search. Basically, what I want is to be able to search the product and services items as well from that search field. Currently, it is only searching for the business name.

@realblackmario
I showed you that example to help you to recognize, how your setup could work in your project.

How to use the example, to see my suggested functionality???

  1. Load the —> MAIN-DB.

  1. Navigate to the SEARCH-FIELD.

  1. By entering the SEARCH-Field, a new options-window will appear, to ask for wished DATAFIELD, to search in for results.


Choose the right DATAFIELD where you want to search for items.

  1. Type in several values into the SEARCH-FIELD, to search for…
    “Donald” “Angela” —> if you seearch in the —> “vorname” <— DATAFIELD

  1. Entered values sepparated by a —> SPACE!

  2. Take a look onto seruslts.