Search.../

hasAll( )

Refines a search to match documents whose specified field value contains all of the specified values.

Description

The hasAll() function refines a WixSearchBuilder to only match documents where the values of the array in the specified field equal all of the specified values.

Matching strings with hasAll() is case sensitive, so "text" is not equal to "Text".

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

Syntax

function hasAll(field: string, values: Array<string>): WixSearchBuilder

hasAll Parameters

NAME
TYPE
DESCRIPTION
field

string

The field whose value will be compared with values. The field type must be an array of strings.

values

Array<string>

The values to match against.

Returns

A WixSearchBuilder object representing the refined query.

Return Type:

Was this helpful?

Add a has all filter to a search

Code Example

Copy Code
1let newSearch = search
2 .documentType("Blog/Posts")
3 .hasAll("hashtags", ["vacation", "summer", "fun"]);
Create a search, add a has all filter, and run it

This example demonstrates how to search for store products that belong to both the "Shirts" and "Summer" store collections.

Code Example

Copy Code
1import wixSearch from 'wix-search';
2
3// ...
4
5wixSearch.search()
6 .documentType("Stores/Products")
7 .hasAll("collections", ["Shirts", "Summer"])
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