Search.../

hasSome( )

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

Description

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

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

Syntax

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

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

Return Type:

Was this helpful?

Add a has some filter to a search

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

This example demonstrates how to search for booking services run by any of the specified staff members.

Copy Code
1import wixSearch from 'wix-search';
2
3// ...
4
5wixSearch.search()
6 .documentType("Bookings/Services")
7 .hasSome("staffMembers", ["Mary Jane", "John Doe"])
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
Create a search, add filters, and run it

This example demonstrates how to search for store products that are on sale, are part of the "Spring" or "Summer" store collections, and to sort the results in alphabetical order according to the SKU.

Copy Code
1import wixSearch from 'wix-search';
2
3// ...
4
5wixSearch.search()
6 .documentType("Stores/Products")
7 .eq("onSale", true)
8 .hasSome("collections", ["Spring", "Summer"])
9 .ascending("sku")
10 .find()
11 .then( (results) => {
12 if(results.documents.length > 0) {
13 let documents = results.documents;
14 } else {
15 console.log("No matching results");
16 }
17 })
18 .catch( (error) => {
19 console.log(error);
20 });
21
22