Search.../

hasSome( )

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

Description

The hasSome() function is chained to a WixSearchFilterBuilder to create a WixSearchFilter. You can use the filter to match documents where any of the values of the array in the specified field equal any of the specified values.

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

Syntax

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

hasSome 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.

Return Type:

WixSearchFilter
NAME
TYPE
DESCRIPTION
filterDefinition
Object

An object containing the filter definition.

Was this helpful?

Create a has some search filter

Copy Code
1import wixSearch from 'wix-search';
2
3// ...
4
5const hasSomeFilter = wixSearch
6 .filter()
7 .hasSome("hashtags", ["vacation", "summer", "fun"]);
Create a has some filter and add a not filter

This example demonstrates how to create a filter that will search for forum posts that don't contain any of the specified hashtags.

Copy Code
1import wixSearch from 'wix-search';
2
3// ...
4
5const filterBuilder = wixSearch.filter();
6
7const hasSomeFilter = filterBuilder.hasSome("hashTags", ["promotion", "ad", "tip"]);
8
9const notFilter = filterBuilder.not(hasSomeFilter);
Create filters and add them to a search

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.

Copy Code
1import wixSearch from 'wix-search';
2
3// ...
4
5const filterBuilder = wixSearch.filter();
6
7const inFilter = filterBuilder.in("owner", ["04b11aa6-d0a0-4c7a-a444-f4a5e452840c", "21cf071a-cc2f-444f-ad74-5a25db0b1b6a"]);
8
9const hasSomeFilter = filterBuilder.hasSome("hashTags", ["summer", "fun", "vacation"]);
10
11const neFilter = filterBuilder.ne(categoryId, "5df7504fa8a9b30017fc1053");
12
13wixSearch.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 });