Multiple Search Fields Database

Hi!

I am a designer and do not know code at all. However, I was able to code a search for my database through viewing this video: Wix Code | How to Create a Search for Your Database - YouTube

The code works fine, but I would love add some more to it.

I have created a page where my users should be able to search for technical papers. My database includes: Author name, Title of the paper, Date published, and a link to the PDF of the file. This is what it looks like in the editor:

The code I have used for the search bar so far only lets my users search for papers by their title. I would like to give them the opportunity to also search for papers by author name or year. What could I add to the code to make this happen?

Here is what the code looks like today:

Remember, I do not know code at all, so I don’t understand much of this…

Hope someone can help me out and that there is a quick way to add to the code!

All answers are appreciated.

Best regards,
Ragnhild

Hi Ragnhild,

You could try using the or() function…

$w("#dataset1").setFilter(wixData.filter()
   .contains("title", title)
   .or(wixData.filter()
      .contains("author", author))
   .or(wixData.filter()
      .contains("year", year))

:slight_smile:

Thanks for your reply, Rachel!

Now it looks like this:


But as i changed the code, nothing happens when I type in the search field anymore. Any suggestions?

Try this…

$w("#dataset1").setFilter(wixData.filter() 
     .contains("title", $w("#iKeyword").value) 
     .or(wixData.filter() 
          .contains("author", $w("#iKeyword").value)) 
     .or(wixData.filter() 
          .contains("datePublished", $w("#iKeyword").value)))