or condition with dataset setFilter doesn't work

I need to filter a dataset based on a user’s search criteria. Specifically, I need compare what the user entered (critDesc) to a desc field and a photos field in the collection. If it is found in EITHER the desc or photos field then return the result. Here is my code:

$w(“#datasetBooks”).setFilter( wixData.filter()
.contains(“desc”, critDesc)
.or(
wixData.query(“Library_Books”)
.contains(“photos”, critDesc)
)

Zero items are always returned no matter what the critDesc variable contains. So, how do I use an or condition with dataset setFilter?

The second one is not a filter but a collection query.
If you want to filter the dataset, you should use wixData.filter().

Thanks. Now I need a little help with the syntax. This doesn’t work.

  1. //this throws a TypeError: is not a function

  2. $w(“#datasetBooks”).setFilter( wixData.filter()

  3.  .contains("desc", critDesc) 
    
  4.  .or( 
    
  5.        $w("#datasetBooks").setFilter( wixData.filter() 
    
  6.             .contains("photos", critDesc) 
    
  7.        ) 
    
  8.  ) 
    
  9. );

Note: if I simply use two .contains statements in the first filter, then the result is an “and” function instead of an “or” function.

  1. $w(“#datasetBooks”).setFilter( wixData.filter()

  2.  .contains("desc", critDesc) 
    
  3.  .contains("photos", critDesc)
    

Yes, you have a mistake there.
Try:

let filter1 = wixData.filter().contains("desc", critDesc);
let filter2 = wixData.filter().contains("photos", critDesc);
$w("#datasetBooks").setFilter(filter1.or(filter2));

(fixed)

This works!! Thanks J. D.