Search.../

in( )

Refines a search to match documents whose specified field value equals any of the specified values.

Description

The in() function refines a WixSearchBuilder to only 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".

If other filters were previously used in the same WixSearchBuilder instance, in() is applied using an and condition with previously set filters.

Syntax

function in(field: string, values: Array<string> | Array<number>): WixSearchBuilder

in Parameters

NAME
TYPE
DESCRIPTION
field
string

The field whose value will be compared with values. The field must be of type string or number.

values
Array<string> | Array<number>

The values to match against.

Returns

A WixSearchBuilder object representing the refined query.

Return Type:

Was this helpful?

Add an in() filter to a search

Copy Code
1let newSearch = search
2 .documentType("Forum/Content")
3 .in("categoryId", ["5df7504fa8a9b30017fc1053", "4e14023806a63c0017e0c1d0"]);
Create a search, add an in() filter, and run it

This example demonstrates how to search for store products with any of the specified SKUs.

Copy Code
1import wixSearch from 'wix-search';
2
3// ...
4
5wixSearch.search()
6 .documentType("Stores/Products")
7 .in("sku", ["B04", "B07", "B08"])
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 });
19
20