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?
and()
filter, and run it1import wixSearch from 'wix-search';23// ...45const geLikeFilter = wixSearch6 .filter()7 .ge("likeCount", 20)89const geViewFilter = wixSearch10 .filter()11 .ge("viewCount", 100)1213const gtDateFilter = wixSearch14 .filter()15 .gt("lastActivityDate", "2020-04-26T00:00:00.000Z")1617wixSearch.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 });
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.
1import wixSearch from 'wix-search';23// ...45const filterBuilder = wixSearch.filter();67const gtJanFilter = filterBuilder.gt("lastActivityDate", "2020-01-01T00:00:00.000Z");8const ltFebFilter = filterBuilder.lt("lastActivityDate", "2020-02-01T00:00:00.000Z");910const gtAprilFilter = filterBuilder.gt("lastActivityDate", "2020-04-01T00:00:00.000Z");11const ltMayFilter = filterBuilder.lt("lastActivityDate", "2020-05-01T00:00:00.000Z");1213const januaryFilter = filterBuilder.and(gtJanFilter, ltFebFilter);14const aprilFilter = filterBuilder.and(gtAprilFilter, ltMayFilter);1516const dateFilter = filterBuilder.or(januaryFilter, aprilFilter)1718const viewFilter = filterBuilder.gt("viewCount", 200)1920wixSearch.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 });