and( )
Creates a search filter for matching documents that meet the conditions of all of the specified filters.
Description
The add()
function joins WixSearchFilters
with an inclusive and
condition
and creates another WixSearchFilter
. A search with an and()
returns all the documents that match the conditions of all of the filters.
Syntax
function and(filters: ...WixSearchFilter): WixSearchFilter
and Parameters
NAME
TYPE
DESCRIPTION
One or more search filters.
Returns
A WixSearchFilter
object.
Return Type:
NAME
TYPE
DESCRIPTION
An object containing the filter definition.
Was this helpful?
and()
search filter1import wixSearch from 'wix-search';23// ...45const andFilter = wixSearch6 .filter()7 .and(myFilter1, myFilter2);
and()
filterThis example demonstrates how to create filters for searching for popular forum posts with 20 or more likes and 100 or more views.
1import wixSearch from 'wix-search';23// ...45const filterBuilder = wixSearch.filter();67const geLikeFilter = filterBuilder.ge("likeCount", 20);89const geViewFilter = filterBuilder.ge("viewCount", 100);1011const andFilter = filterBuilder.and(geLikeFilter, geViewFilter);
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.
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 });