Search.../

or( )

Creates a filter for matching documents that meet the condition of any of the specified filters.

Description

The or() function joins WixSearchFilters with an inclusive or condition and creates another WixSearchFilter. A search with an or() returns all the documents that match the condition of any of the filters.

Syntax

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

or Parameters

NAME
TYPE
DESCRIPTION
filters
WixSearchFilter

One or more search filters.

Returns

A WixSearchFilter object.

Return Type:

WixSearchFilter
NAME
TYPE
DESCRIPTION
filterDefinition
Object

An object containing the filter definition.

Was this helpful?

Create an or() search filter

Copy Code
1import wixSearch from 'wix-search';
2
3// ...
4
5const orFilter = wixSearch
6 .filter()
7 .or(myFilter1, myFilter2);
Create multiple filters and combine them

This example demonstrates how to create a filter that will 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 filterBuilder = wixSearch.filter();
6
7const geLikeFilter = filterBuilder.ge("likeCount", 20);
8
9const geViewFilter = filterBuilder.ge("viewCount", 100);
10
11const orFilter = filterBuilder.or(geLikeFilter, geViewFilter);
Create multiple search filters and add them to a search

This example demonstrates how to create multiple search filters and combine them to search for forum posts with more than 200 views that were posted either in the month of January or April of 2020.

Copy Code
1import wixSearch from 'wix-search';
2
3// ...
4
5const filterBuilder = wixSearch.filter();
6
7const gtJanFilter = filterBuilder.gt("lastActivityDate", "2020-01-01T00:00:00.000Z");
8const ltFebFilter = filterBuilder.lt("lastActivityDate", "2020-02-01T00:00:00.000Z");
9
10const gtAprilFilter = filterBuilder.gt("lastActivityDate", "2020-04-01T00:00:00.000Z");
11const ltMayFilter = filterBuilder.lt("lastActivityDate", "2020-05-01T00:00:00.000Z");
12
13const januaryFilter = filterBuilder.and(gtJanFilter, ltFebFilter);
14const aprilFilter = filterBuilder.and(gtAprilFilter, ltMayFilter);
15
16const dateFilter = filterBuilder.or(januaryFilter, aprilFilter)
17
18const viewFilter = filterBuilder.gt("viewCount", 200)
19
20wixSearch.search(phrase)
21 .documentType("Forum/Content")
22 .and(dateFilter, viewFilter)
23 .find()
24 .then( (results) => {
25 if(results.documents.length > 0) {
26 let documents = results.documents;
27 } else {
28 console.log("No matching results");
29 }
30 })
31 .catch( (error) => {
32 console.log(error);
33 });