eq( )
Creates a search filter for matching documents whose specified field value equals the specified value.
Description
The eq()
function is chained to a WixSearchFilterBuilder
to create a WixSearchFilter
.
You can use the filter to 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"
.
Syntax
function eq(field: string, value: *): WixSearchFilter
eq Parameters
NAME
TYPE
DESCRIPTION
The field whose value will be compared with value
.
The value to match against.
Returns
A WixSearchFilter
object.
Return Type:
NAME
TYPE
DESCRIPTION
An object containing the filter definition.
Was this helpful?
1import wixSearch from 'wix-search';23// ...45const eqFilter = wixSearch6 .filter()7 .eq("sku", "SHO-11-BLA");
This example demonstrates how to create filters that search for forum posts in a specific forum
category, that contain the hashtags "summer" and "fun", and that were posted/updated on or after January 1, 2020.
The filters are joined and chained to a search using an and()
filter.
1import wixSearch from 'wix-search';23// ...45const filterBuilder = wixSearch.filter();67const gtFilter = filterBuilder.gt("lastActivityDate", "2020-01-01T00:00:00.000Z");89const hasAllFilter = filterBuilder.hasAll("hashTags", ["summer", "fun"]);1011const eqFilter = filterBuilder.eq(categoryId, "5df7504fa8a9b30017fc1053");1213wixSearch.search(phrase)14 .documentType("Forum/Content")15 .and(gtFilter, hasAllFilter, eqFilter)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 });