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
One or more filters.
Returns
A WixSearchFilter
object.
Return Type:
NAME
TYPE
DESCRIPTION
An object containing the filter definition.
Was this helpful?
not()
search filter1import wixSearch from 'wix-search';23// ...45const notFilter = wixSearch6 .filter()7 .not(myFilter1, myFilter2);
This example demonstrates how to create a filter that will search for forum posts that do not contain any of the specified hashtags.
1import wixSearch from 'wix-search';23// ...45const filterBuilder = wixSearch.filter();67const hasSomeFilter = filterBuilder.hasSome("hashTags", ["promotion", "ad", "tip"]);89const notFilter = filterBuilder.not(hasSomeFilter);
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.
1import wixSearch from 'wix-search';23// ...45const eqStockFilter = wixSearch6 .filter()7 .eq("inStock", true)89const eqSaleFilter = wixSearch10 .filter()11 .eq("onSale", true)1213wixSearch.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 });2728