Search.../

or( )

Refines a search to match documents that meet the condition of any of the specified filters.

Description

The or() function joins WixSearchFilters with an inclusive or condition and adds them to a WixSearchBuilder. A search with an or() returns all the documents that match the condition of any of the filters.

If the or() function contains a single filter, the filter is applied directly to the WixSearchBuilder.

If other filtering functions were previously used in the same WixSearchBuilder instance, or() is applied using an and condition with previously set filters.

Syntax

function or(filters: ...WixSearchFilter): WixSearchBuilder

or Parameters

NAME
TYPE
DESCRIPTION
filters
WixSearchFilter

One or more filters.

Returns

A WixSearchBuilder object representing the refined search.

Return Type:

Was this helpful?

Create a search, add an or, and run it

This example demonstrates how to search for popular forum posts with either 20 or more likes or 100 or more views.

Copy Code
1import wixSearch from 'wix-search';
2
3// ...
4
5const geLikeFilter = wixSearch
6 .filter()
7 .ge("likeCount", 20)
8
9const geViewFilter = wixSearch
10 .filter()
11 .ge("viewCount", 100)
12
13wixSearch.search()
14 .documentType("Forum/Content")
15 .or(geLikeFilter, geViewFilter)
16 .find()
17 .then( (results) => {
18 if(results.documents.length > 0) {
19 let documents = results.documents;
20 } else {
21 console.log("No matching results");
22 }
23 })
24 .catch( (error) => {
25 console.log(error);
26 });
27
28