Refines a search to match documents that meet the conditions of all of the specified filters.
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.
function and(filters: Array<WixSearchFilter>): WixSearchBuilder;
One or more filters.
import wixSearch from "wix-search";
// ...
const geLikeFilter = wixSearch.filter().ge("likeCount", 20);
const geViewFilter = wixSearch.filter().ge("viewCount", 100);
const gtDateFilter = wixSearch
.filter()
.gt("lastActivityDate", "2020-04-26T00:00:00.000Z");
wixSearch
.search()
.documentType("Forum/Content")
.and(geLikeFilter, geViewFilter, gtDateFilter)
.find()
.then((results) => {
if (results.documents.length > 0) {
let documents = results.documents;
} else {
console.log("No matching results");
}
})
.catch((error) => {
console.log(error);
});
This method doesn’t return any custom errors, but may return standard errors. Learn more about standard Wix errors.