Search.../

not( )

Creates a search filter for matching documents that do not meet the conditions of all of the specified filters.

Description

The not() function joins WixSearchFilters and adds a not condition. A search with a not() returns all the documents that don't match all of the filters passed to the not() function. The not() function first applies an and condition between the filter parameters and then negates them.

Syntax

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

not Parameters

NAME
TYPE
DESCRIPTION
filters
WixSearchFilter

One or more filters.

Returns

A WixSearchFilter object.

Return Type:

WixSearchFilter
NAME
TYPE
DESCRIPTION
filterDefinition
Object

An object containing the filter definition.

Was this helpful?

Create a not() search filter

Copy Code
1import wixSearch from 'wix-search';
2
3// ...
4
5const notFilter = wixSearch
6 .filter()
7 .not(myFilter1, myFilter2);
Create a has some filter and add a not filter

This example demonstrates how to create a filter that will search for forum posts that do not contain any of the specified hashtags.

Copy Code
1import wixSearch from 'wix-search';
2
3// ...
4
5const filterBuilder = wixSearch.filter();
6
7const hasSomeFilter = filterBuilder.hasSome("hashTags", ["promotion", "ad", "tip"]);
8
9const notFilter = filterBuilder.not(hasSomeFilter);
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