Using wixdata filtering with “or()” conditions

Hello.
Could someone tell me why my or() is not working for wixdata filtering.

I am attempting to use a wixdata filter function with “or” conditions on a collection, to search for a visitor inputted word, and populate a Pro Gallery.

I am using a single word entered and am searching 3 collection fields; the “name” field, the “story” field, and “searchWords” field. I am using an or() condition to link it. (eg. Search for the word “boat” in those 3 fields.)

The code works properly if I only use a single filter statement (eg. Search only the “name” field). But including all 3 filters it still only checks the 1st one. (as if the other 2 “or()” statements were not there).
I have copied the code from other Youtube developers who use and()’s and assume theirs works, but not mine with or()’s.

Any thought’s??? Below is my code.

// Word search for Pro Gallery
//
import wixData from ‘wix-data’;
$w.onReady(function(){

// When Search button is clicked
$w(“#button5”).onClick(function () {
const searchWord1 = $w(‘#input1’).value ;

let filter = wixData.filter() ;

if (searchWord1.length > 0 ){
	filter = filter.contains("itemName",searchWord1)
		.or (filter = filter.contains("story",searchWord1))
		.or (filter = filter.contains("searchWords1",searchWord1))
	console.log ("just created search criteria")
}

$w('#dataset1').setFilter(filter) ;

}) //end of onClick search - button 5

// Reset the filter ( search criteria, buttons and filter )
$w(“#button6”).onClick(function (){
$w(“#dataset1”).setFilter(wixData.filter()) ;
$w(‘#input1’).value = undefined ;
}) //end of onClick for reset - button6

}) //end of onReady

try this

// Word search for Pro Gallery
import wixData from 'wix-data';

$w.onReady(function(){

  // When Search button is clicked
  $w("#button5").onClick(function () {
    const searchWord1 = $w('#input1').value;

    let filter = wixData.filter();

    if (searchWord1.length > 0 ){
      filter = filter.contains("itemName",searchWord1)
        .or(wixData.filter().contains("story",searchWord1))
        .or(wixData.filter().contains("searchWords1",searchWord1));
      console.log("just created search criteria");
    }

    $w('#dataset1').setFilter(filter);
  }); //end of onClick search - button 5

  // Reset the filter ( search criteria, buttons and filter )
  $w("#button6").onClick(function (){
    $w("#dataset1").setFilter(wixData.filter());
    $w('#input1').value = undefined;
  }); //end of onClick for reset - button6

}); //end of onReady

Hi Dan,

It appears that the change you are recommending is to add the " wixData, " prefix to the “filter” statement for the 2nd and 3rd “filter” statement this gave me a format syntax error

Syntax error

I would expect the format for the 3 “filter” statements should be the same. The 1st one works. I expect there is a problem with the or() conditional I have between the 3 statements.

Thanks,

I havnt tested yet, but your screen shot code is slightly different to what I posted.

.or(wixData.filter().contains("story",searchWord1))

The .or() method is used to combine two filters, but in your code, you are trying to assign a new filter inside the .or() method

edit: I just dumped my code in a blank page and the only errors are the elements/dataset missing

Hi Dan,
Thanks for persisting! And for testing.
I just straight copied / pasted your code over mine and it works. Mostly - One of collection fields I am searching on is a “Rich Content” field. It doesn’t seem to work on that field type. Not a problem - I was already planning to change it back to plain text anyway.

I am new to WIX. I was a COBOL programmer but have not done programming for 45 years and this is no comparison!!! I can easily figure out what I want to do but haven’t been able to master the syntax yet.
Thanks for your help and sorry for the trouble from your first reply.

I am glad I could help you. 45 yrs is a decent stint. I have only been coding for around 10 and am no where near proficient compared to others.