not( )


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

The not() function adds a not condition to a WixSearchBuilder. A search with a not() returns all the documents that don't match all of the WixSearchFilters passed to the not() function. The not() function first applies an and condition between the filter parameters and then negates them. If a document does not meet the conditions of some but not all of the specified filters, the document will be included in the search results.

If other filtering functions were previously used in the same WixSearchBuilder instance, not() is applied using an and condition with previously set filters.

Method Declaration
Copy
function not(filters: Array<WixSearchFilter>): WixSearchBuilder;
Method Parameters
filtersArray<WixSearchFilter>Required

One or more filters.

Returns
Return Type:WixSearchBuilder
Create filters, create a search, add a not filter, and run it

This example demonstrates how to search for store products that are not both on sale and in stock.

Search results will exclude only products which return true for both onSale and inStock. Products that are onSale but not inStock or inStock but not onSale will be included in the search results.

JavaScript
import wixSearch from "wix-search"; // ... const eqStockFilter = wixSearch.filter().eq("inStock", true); const eqSaleFilter = wixSearch.filter().eq("onSale", true); wixSearch .search() .documentType("Stores/Products") .not(eqStockFilter, eqSaleFilter) .find() .then((results) => { if (results.documents.length > 0) { let documents = results.documents; } else { console.log("No matching results"); } }) .catch((error) => { console.log(error); });
Errors

This method doesn’t return any custom errors, but may return standard errors. Learn more about standard Wix errors.

Did this help?