Search.../

not( )

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

Description

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.

Syntax

function not(filters: ...WixSearchFilter): WixSearchBuilder

not Parameters

NAME
TYPE
DESCRIPTION
filters
WixSearchFilter

One or more filters.

Returns

A WixSearchBuilder object representing the refined search.

Return Type:

Was this helpful?

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.

Copy Code
1import wixSearch from 'wix-search';
2
3// ...
4
5const eqStockFilter = wixSearch
6 .filter()
7 .eq("inStock", true)
8
9const eqSaleFilter = wixSearch
10 .filter()
11 .eq("onSale", true)
12
13wixSearch.search()
14 .documentType("Stores/Products")
15 .not(eqStockFilter, eqSaleFilter)
16 .find()
17 .then( (results) => {
18 if(results.documents.length > 0) {
19 let documents = results.documents;
20 } else {
21 console.log("No matching results");
22 }
23 })
24 .catch( (error) => {
25 console.log(error);
26 });
27
28