Search.../

hasAll( )

Creates a search filter for matching documents whose specified field value contains all of the specified values.

Description

The hasAll() function is chained to a WixSearchFilterBuilder to create a WixSearchFilter. You can use the filter to 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".

Syntax

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

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 WixSearchFilter object representing the refined query.

Return Type:

WixSearchFilter
NAME
TYPE
DESCRIPTION
filterDefinition
Object

An object containing the filter definition.

Was this helpful?

Create a has all search filter

Copy Code
1import wixSearch from 'wix-search';
2
3// ...
4
5const hasAllFilter = wixSearch
6 .filter()
7 .hasAll("hashtags", ["vacation", "summer", "fun"]);
Create filters and add them to a search

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.

Copy Code
1import wixSearch from 'wix-search';
2
3// ...
4
5const filterBuilder = wixSearch.filter();
6
7const gtFilter = filterBuilder.gt("lastActivityDate", "2020-01-01T00:00:00.000Z");
8
9const hasAllFilter = filterBuilder.hasAll("hashTags", ["summer", "fun"]);
10
11const eqFilter = filterBuilder.eq(categoryId, "5df7504fa8a9b30017fc1053");
12
13wixSearch.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 });