eq( )
Refines a search to match documents whose specified field value equals the specified value.
Description
The eq()
filter function refines a WixSearchBuilder
to only
match documents where the value of the specified field equals the specified value
.
eq()
only matches values of the same type. For example, a number value stored
as a String type does not match the same number stored as a Number type.
Matching strings with eq()
is case sensitive, so "text"
is not equal to "Text"
.
If other filters were previously used in the same WixSearchBuilder
instance, eq()
is applied using an and
condition with previously set filters.
Syntax
function eq(field: string, value: *): WixSearchBuilder
eq Parameters
NAME
TYPE
DESCRIPTION
The field whose value will be compared with value
.
The value to match against.
Was this helpful?
1let newSearch = search2 .documentType("Stores/Products")3 .eq("onSale", true);
This example demonstrates how to search only for forum comments and not forum posts.
1import wixSearch from 'wix-search';23// ...45wixSearch.search()6 .documentType("Forum/Content")7 .eq("contentType", "COMMENTS")8 .find()9 .then( (results) => {10 if(results.documents.length > 0) {11 let documents = results.documents;12 } else {13 console.log("No matching results");14 }15 })16 .catch( (error) => {17 console.log(error);18 });1920
This example demonstrates how to search for store products that are on sale and are part of the "Spring" or "Summer" store collections. The results are sorted in alphabetical order according to the SKU.
1import wixSearch from 'wix-search';23// ...45wixSearch.search()6 .documentType("Stores/Products")7 .eq("onSale", true)8 .hasSome("collections", ["Spring", "Summer"])9 .ascending("sku")10 .find()11 .then( (results) => {12 if(results.documents.length > 0) {13 let documents = results.documents;14 } else {15 console.log("No matching results");16 }17 })18 .catch( (error) => {19 console.log(error);20 });2122