Search.../

and( )

Refines a search to match documents that meet the conditions of all of the specified filters.

Description

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

Note that when chaining multiple WixSearchBuilder filtering functions to a search, an and condition is assumed. In such cases, you do not need to add a call to the and() function. and() is useful for combining compound filters created using WixSearchFilterBuilder filtering functions.

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

Authorization

Request

This endpoint does not take any parameters

Response Object

A WixSearchBuilder object representing the refined search.

Returns an empty object.

Status/Error Codes

Was this helpful?

Create filters, create a search, add an and() filter, and run it

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
13const gtDateFilter = wixSearch
14 .filter()
15 .gt("lastActivityDate", "2020-04-26T00:00:00.000Z")
16
17wixSearch.search()
18 .documentType("Forum/Content")
19 .and(geLikeFilter, geViewFilter, gtDateFilter)
20 .find()
21 .then( (results) => {
22 if(results.documents.length > 0) {
23 let documents = results.documents;
24 } else {
25 console.log("No matching results");
26 }
27 })
28 .catch( (error) => {
29 console.log(error);
30 });
Create multiple search filters and add them to a search

This example demonstrates how to create multiple WixSearchFilters 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 });