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.
function not(filters: Array<WixSearchFilter>): WixSearchBuilder;
One or more filters.
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.
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);
});
Refines a search to match documents that meet the condition of any of the specified filters.
The or()
function joins WixSearchFilters
with an inclusive or
condition
and adds them to a WixSearchBuilder
. A search with an or()
returns all the documents that match the condition of any of the filters.
If the or()
function contains a single filter, the filter is applied directly to the WixSearchBuilder
.
If other filtering functions were previously used in the same WixSearchBuilder
instance, or()
is applied using an and
condition with previously set filters.
function or(filters: Array<WixSearchFilter>): WixSearchBuilder;
One or more filters.
This example demonstrates how to search for popular forum posts with either 20 or more likes or 100 or more views.
import wixSearch from "wix-search";
// ...
const geLikeFilter = wixSearch.filter().ge("likeCount", 20);
const geViewFilter = wixSearch.filter().ge("viewCount", 100);
wixSearch
.search()
.documentType("Forum/Content")
.or(geLikeFilter, geViewFilter)
.find()
.then((results) => {
if (results.documents.length > 0) {
let documents = results.documents;
} else {
console.log("No matching results");
}
})
.catch((error) => {
console.log(error);
});
Sets the search phrase to search for.
The query()
function provides an alternate method for setting the search phrase for your search. Instead
of setting the search phrase directly as a parameter of the search()
function,
you can set the search phrase using the query()
function chained to a WixSearchBuilder
.
Setting the search phrase with query()
allows you to build searches dynamically. For example,
you could use a different search phrase depending on whether a specific condition is met.
function query(phrase: string): WixSearchBuilder;
The phrase to run the search on.
let newSearch = search.query(phrase);