in( )
Creates a search filter for matching documents whose specified field value equals any of the specified values.
Description
The in()
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 any of
the specified values.
Matching strings with in()
is case sensitive, so "text"
is not equal to "Text"
.
Syntax
function in(field: string, values: Array<string> | Array<number>): WixSearchFilter
in Parameters
NAME
TYPE
DESCRIPTION
The field whose value will be compared with values
. The field must be of type string or number.
The values to match against.
Returns
A WixSearchFilterBuilder
object representing the refined query.
Return Type:
NAME
TYPE
DESCRIPTION
An object containing the filter definition.
Was this helpful?
in()
search filter1import wixSearch from 'wix-search';23// ...45const inFilter = wixSearch6 .filter()7 .in("sku", ["B04", "B07", "B08"]);
This example demonstrates how to create filters that search for forum posts that are not in the specified
category, that were posted by one of the specified owners, and that contain at least one of the specified hashtags.
The filters are joined and chained to a search using an and()
filter.
1import wixSearch from 'wix-search';23// ...45const filterBuilder = wixSearch.filter();67const inFilter = filterBuilder.in("owner", ["04b11aa6-d0a0-4c7a-a444-f4a5e452840c", "21cf071a-cc2f-444f-ad74-5a25db0b1b6a"]);89const hasSomeFilter = filterBuilder.hasSome("hashTags", ["summer", "fun", "vacation"]);1011const neFilter = filterBuilder.ne(categoryId, "5df7504fa8a9b30017fc1053");1213wixSearch.search(phrase)14 .documentType("Forum/Content")15 .and(inFilter, hasSomeFilter, neAllFilter)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 });