Problem with Database Search (wixData.filter)

I’m having trouble getting consistent results with the search terms from the database I have set up, and I don’t know what the problem is. You can look at the database here: www.aseatatthepiano.com/database

The code I have for the search right now is:

import wixData from 'wix-data';

export function input1_keyPress(event) {
 let SearchValue = $w("#input1").value;
    $w('#dataset1').setFilter(wixData.filter().contains('title', SearchValue)
        .or(wixData.filter().contains('birthyear', SearchValue)
            .or(wixData.filter().contains('compositionTitle', SearchValue)
                .or(wixData.filter().contains('duration', SearchValue)
                    .or(wixData.filter().contains('level', SearchValue)
                        .or(wixData.filter().contains('nationality', SearchValue))
                            .or(wixData.filter().contains('identifier', SearchValue)
                                .or(wixData.filter().contains('searchTerms', SearchValue))))))))
}

I’m wondering if it has something to do with the .or function? Does it stop filtering once it finds a match in the database?

For example, when searching for the piece Pickles and Peppers by Adaline Shepherd, you get the result when searching pickles and when searching Adaline, but not when searching adaline pickles.

I’m not very experience with this, so if anyone can help me out with this, that would be great!

What exactly are you attempting to accomplish? Searches can be done with the and condition, the or condition, and combinations.

For example, you can search for:

  • pickles - results include anything with peppers

  • pickles and peppers - results only include anything that has both pickles and peppers tother

  • pickles or peppers - results include anything that has pickles, or that has peppers

You need to clearly define exactly what it is you are trying to achieve with your database queries, and then you can go about trying to implement the code.

I would suggest reading Corvid: About Creating Searches and Filters of Displayed Data to get a better understanding of filters. You can then play with the Search a Database example to see how various searches and filter work in “real time”. You can also look at the Mega Search example for a much more complex look.

Hi Yisrael,

Thanks for the info - I remember looking at them when I was first putting this together, and I’ll take another look at them now.

What I’m most confused about is why the search seems to only work with one search term, and returns no results if there are multiple search terms in the text box input.

What I would like is for the user to be able to input any search term(s) and have the results displayed.