import { WixDataResult } from './WixDataResult'; import { WixDataReadOptions } from './types'; import { WixDataFilter } from './WixDataFilter'; /** * @builder * Represents a search operation to be performed on a Wix Data collection. * Allows for building complex search requests by specifying search expressions, modes, filters, sorting, and pagination. */ export interface WixDataSearch { /** * Specifies the text to search in the collection. * * The `expression()` method sets the search query. * * Search terms are separated by whitespace. For example, the expression `red car white roof` includes four search terms: `red`, `car`, `white`, and `roof`. Use [`andMode()`](https://dev.wix.com/docs/sdk/backend-modules/data/items/wix-data-search/and-mode) to require all terms to be present, or [`orMode()`](https://dev.wix.com/docs/sdk/backend-modules/data/items/wix-data-search/or-mode) to require at least one term to be present. * * @param queryText - Text to search in the collection. * @returns Refined WixDataSearch object. */ expression(queryText: string): WixDataSearch; /** * Enables fuzzy search for approximate text matching. * * The `fuzzy()` method enables fuzzy search. This allows for approximate matches that closely resemble the search expression even if they don't exactly match. * * @returns Refined WixDataSearch object. */ fuzzy(): WixDataSearch; /** * Sets the search mode to **AND**. * * When in **AND** mode, an item must include all specified search terms to be included in the results. For example, the search expression "red car" in **AND** mode only retrieves items that include both "red" and "car". * * @returns Refined WixDataSearch object. */ andMode(): WixDataSearch; /** * Sets the search mode to **OR**. * * When in **OR** mode, an item must include at least one of the specified search terms to be included in the results. For example, the search expression "red car" in **OR** mode retrieves items that include "red", "car", or both. * * @returns Refined WixDataSearch object. */ orMode(): WixDataSearch; /** * Runs the search operation. * * The `run()` method searches the collection for the specified expression. It returns a Promise that resolves to a [`WixDataResult`](https://dev.wix.com/docs/sdk/backend-modules/data/items/wix-data-result/introduction) that contains the matching items and search metadata. * * Search operations are [eventually consistent](https://dev.wix.com/docs/sdk/backend-modules/data/eventual-consistency) and might not reflect recent changes. * @param options - Options for building the search operation. * @returns Promise that resolves to a [`WixDataResult`](https://dev.wix.com/docs/sdk/backend-modules/data/items/wix-data-result/introduction) containing the matching items and search metadata. */ run(options?: WixDataReadOptions): Promise; /** * Sorts search results by the specified fields in descending order. * * The `descending()` method refines the search to sort results by the specified fields in descending order. If you specify more than one field, `descending()` sorts the results in descending order by each field in the order they are listed. * * You can sort the following types: * - **Number**: Sorts numerically. * - **Date**: Sorts by date and time. * - **String**: Sorts lexicographically, so `"abc"` comes before `"XYZ"`. * - **Reference**: Compares by the ID of the referenced item as a String. * * If a field contains a number as a String, that value is sorted alphabetically and not numerically. * Items that do not have a value for the specified sort field are ranked lowest. * * @public * @documentationMaturity preview * @param fields - Fields by which to sort results in descending order. * @requiredField fields * @returns Refined WixDataSearch object. */ descending(...fields: string[]): WixDataSearch; /** * @param fields - Array of fields by which to sort results in descending order. * @returns Refined WixDataSearch object. */ descending(fields: string[]): WixDataSearch; /** * @param fields - Fields by which to sort results in descending order. * @returns Refined WixDataSearch object. */ descending(...fields: any): WixDataSearch; /** * Sorts search results in ascending order by the specified fields. * * The `ascending()` method refines the search to sort results by the specified fields in ascending order. If you specify more than one field, `ascending()` sorts the results in ascending order by each field in the order they are listed. * * You can sort the following types: * - **Number**: Sorts numerically. * - **Date**: Sorts by date and time. * - **String**: Sorts lexicographically, so `"abc"` comes before `"XYZ"`. * - **Reference**: Compares by the ID of the referenced item as a String. * * If a field contains a number as a String, that value is sorted alphabetically and not numerically. * Items that do not have a value for the specified sort field are ranked lowest. * * @public * @documentationMaturity preview * @param fields - Fields by which to sort results in ascending order. * @requiredField fields * @returns Refined WixDataSearch object. */ ascending(...fields: string[]): WixDataSearch; /** * @param fields - Array of fields by which to sort results in ascending order. * @returns Refined WixDataSearch object. */ ascending(fields: string[]): WixDataSearch; /** * @param fields - Fields by which to sort results in ascending order. * @returns Refined WixDataSearch object. */ ascending(...fields: any): WixDataSearch; /** * Refines a search to match items where the value of the specified field equals the specified value. * * The `eq()` method refines the search to only match items where the value of the specified field equals the specified `value`. The method only matches values of the same [data type](https://dev.wix.com/docs/api-reference/business-solutions/cms/data-types-in-wix-data). For example, a number value stored as a number does not match the same number stored as a string. * * Matching strings with `eq()` is case-sensitive, so `"text"` is not considered equal to `"Text"`. * * If the field contains an array, `eq()` matches the item if at least one array element equals the specified `value`. * * @public * @documentationMaturity preview * @param field - Field whose value is compared with `value`. * @requiredField field * @param value - Value to match. * @requiredField value * @returns Refined WixDataSearch object. */ eq(field: string, value: any): WixDataSearch; /** * Refines a search to match items where the value of the specified field does not equal the specified value. * * The `ne()` method refines the search to only match items where the value of the specified field does not equal the specified `value`. * * The method only matches values of the same [data type](https://dev.wix.com/docs/api-reference/business-solutions/cms/data-types-in-wix-data). For example, a number value stored as a number is considered not equal to the same number stored as a string. * * Matching strings with `ne()` is case-sensitive, so `"text"` is not equal to `"Text"`. * * If the value of `field` is an array, `ne()` includes items in which none of the elements of the array match the specified `value`. * @public * @documentationMaturity preview * @param field - Field whose value is compared with `value`. * @requiredField field * @param value - Value to not match. * @requiredField value * @returns Refined WixDataSearch object. */ ne(field: string, value: any): WixDataSearch; /** * Refines a search to match items where the value of the specified field is greater than or equal to the specified value. * * The `ge()` method refines the search to only match items where the value of the specified field is greater than or equal to the specified `value`. * * The method only matches values of the same [data type](https://dev.wix.com/docs/api-reference/business-solutions/cms/data-types-in-wix-data). For example, a number value stored * as a number does not match the same number stored as a string. * * If a field contains a number as a String, that value is compared * alphabetically and not numerically. Items that do not have a value for the * specified field are ranked lowest. * * The following types of fields can be compared: * - Number: Compares numerically. * - Date: Compares JavaScript Date objects. * - String: Compares lexicographically, so `"abc"` is greater than or equal to `"ABC"`, but `"ABC"` is not greater than or equal to `"abc"`. * - Reference: Compares by the ID of the referenced item as a String. * @public * @documentationMaturity preview * @param field - Field whose value is compared with `value`. * @requiredField field * @param value - Value to compare against. * @requiredField value * @returns Refined WixDataSearch object. */ ge(field: string, value: string | number | Date): WixDataSearch; /** * Refines a search to match items where the value of the specified field is greater than the specified value. * * The `gt()` method refines the search to only match items where the value of the specified field is greater than the specified `value`. * * The method only matches values of the same [data type](https://dev.wix.com/docs/api-reference/business-solutions/cms/data-types-in-wix-data). For example, a number value stored as a number does not match the same number stored as a string. * * If a field contains a number as a String, that value is compared alphabetically and not numerically. Items that do not have a value for the specified field are ranked lowest. * * The following types of fields can be compared: * - Number: Compares numerically. * - Date: Compares JavaScript Date objects. * - String: Compares lexicographically, so `"text"` is greater than `"Text"`. * - Reference: Compares by the ID of the referenced item as a String. * @public * @documentationMaturity preview * @param field - Field whose value is compared with `value`. * @requiredField field * @param value - Value to compare against. * @requiredField value * @returns Refined WixDataSearch object. */ gt(field: string, value: string | number | Date): WixDataSearch; /** * Refines a search to match items where the value of the specified field is less than or equal to the specified value. * * The `le()` method refines the search to only match items where the value of the specified field is less than or equal to the specified value. * * The method only matches values of the same [data type](https://dev.wix.com/docs/api-reference/business-solutions/cms/data-types-in-wix-data). For example, a number value stored as a number does not match the same number stored as a string. * * If a field contains a number as a String, that value is compared alphabetically and not numerically. Items that do not have a value for the specified field are ranked lowest. * * The following types of fields can be compared: * - Number: Compares numerically. * - Date: Compares JavaScript Date objects. * - String: Compares lexicographically, so `"ABC"` is less than or equal to `"abc"`, but `"abc"` is not less than or equal to `"ABC"`. * - Reference: Compares by the ID of the referenced item as a string. * @public * @documentationMaturity preview * @param field - Field whose value is compared with `value`. * @requiredField field * @param value - Value to compare with. * @requiredField value * @returns Refined WixDataSearch object. */ le(field: string, value: string | number | Date): WixDataSearch; /** * Refines a search to match items where the value of the specified field is less than the specified value. * * The `lt()` method refines the search to only match items where the value of the specified field is less than the specified `value`. * * The method only matches values of the same [data type](https://dev.wix.com/docs/api-reference/business-solutions/cms/data-types-in-wix-data). For example, a number value stored as a number does not match the same number stored as a string. * * If a field contains a number as a string, that value is compared alphabetically and not numerically. Items that do not have a value for the specified field are ranked lowest. * * The following types of fields can be compared: * - Number: Compares numerically. * - Date: Compares JavaScript Date objects. * - String: Compares lexicographically, so `"Text"` is less than `"text"`. * - Reference: Compares by the ID of the referenced item as a String. * @public * @documentationMaturity preview * @param field - Field whose value is compared with `value`. * @requiredField field * @param value - Value to compare with. * @requiredField value * @returns Refined WixDataSearch object. */ lt(field: string, value: string | number | Date): WixDataSearch; /** * Refines a search to match items whose specified field has a value that isn't `null` or `undefined`. * * The `isNotEmpty()` method refines the search to only match items where the value of the specified field is not `null` or `undefined`. * * If the field contains any value at all for a given item, including an empty string or an invalid value, that item matches the search filter. * @public * @documentationMaturity preview * @param field - Field to check for a non-empty value. * @requiredField field * @returns Refined WixDataSearch object. */ isNotEmpty(field: string): WixDataSearch; /** * Refines a search to match items whose specified field does not exist or does not have any value (is null or undefined). * * The `isEmpty()` method refines the search to only match items where the specified field does not exist or where its value is `null` or `undefined`. * * If the field contains any value at all for a given item, including an empty string or an invalid value, that item does not match the search filter. * @public * @documentationMaturity preview * @param field - Field to check for an empty or non-existent value. * @requiredField field * @returns Refined WixDataSearch object. */ isEmpty(field: string): WixDataSearch; /** * Refines a search to match items where the value of the specified field starts with a specified value. * * The `startsWith()` method refines the search to only match items where the value of the specified field starts with the specified value. Matching with `startsWith()` is case-sensitive, so searching for `"Sun"` does not match an item that contains the text `"sunshine"`. * * You can only use `startsWith()` with a field whose value is a String or Reference. When using a Reference, `startsWith()` matches by the ID of the referenced item as a String. * @public * @documentationMaturity preview * @param field - Field whose value is compared with the `value` parameter. * @requiredField field * @param value - String to look for at the beginning of the specified field value. * @requiredField value * @returns Refined WixDataSearch object. */ startsWith(field: string, value: string): WixDataSearch; /** * Refines a search to match items where the value of the specified field equals any of the specified values. * * The `hasSome()` method refines the search to only match items where the value of the specified field equals any of the specified values. * * Matching strings with `hasSome()` is case-sensitive, so `"text"` is not considered equal to `"Text"`. * * If the specified field contains an array, `hasSome()` matches items where any of the array's elements match any of the specified values. * * If the specified field contains multiple references, pass item IDs as the values. `hasSome()` matches if any of the references match any of the specified ID values. * * You can specify multiple values to match by providing an array of strings, numbers, or dates. * @public * @documentationMaturity preview * @param field - Field whose value is compared with the specified values. * @requiredField field * @param values - Values to match. * @requiredField values * @returns Refined WixDataSearch object. */ hasSome(field: string, ...values: string[] | number[] | Date[]): WixDataSearch; /** * Overload for `hasSome()`. Refines a search to match items where the value of the specified field equals any of the specified values. * @public * @documentationMaturity preview * @param field - Field whose value is compared with the provided values. * @requiredField field * @param values - Array of values to match. * @requiredField values * @returns Refined WixDataSearch object. */ hasSome(field: string, values: string[] | number[] | Date[]): WixDataSearch; /** * Refines a search to match items where the value of the specified field equals all of the specified values. * * The `hasAll()` method refines the search to only match items where the value of the specified field equals all of the specified values. * * Matching strings with `hasAll()` is case-sensitive, so `"text"` is not equal to `"Text"`. * * If the value of the specified field is an array, `hasAll()` matches if there is a match in the elements of that array for all of the specified values. * * You can specify a list of values to match by providing an array of String, Number, or Date types as the `values` parameters. * @public * @documentationMaturity preview * @param field - Field whose value is compared with `values`. * @requiredField field * @param values - Values to match. All specified values must be present. * @requiredField values * @returns Refined WixDataSearch object. */ hasAll(field: string, ...values: string[] | number[] | Date[]): WixDataSearch; /** * Overload for `hasAll()`. Refines a search to match items where the value of the specified fields equals all of the specified values. * @public * @documentationMaturity preview * @param field - Field whose value is compared with the provided values. * @requiredField field * @param values - Array of values to match. All elements in the array must be present. * @requiredField values * @returns Refined WixDataSearch object. */ hasAll(field: string, values: string[] | number[] | Date[]): WixDataSearch; /** * Adds an `or` condition to the search filter. * * The `or()` method adds an inclusive `or` condition to the search filter. The search returns all the items that match the filter as defined up to the `or()` method, the items that match the filter passed to the `or()` method, and the items that match both. * * > **Note**: Calling `or()` without a filter may lead to unexpected results. * * @public * @documentationMaturity preview * @param filter - Filter to add to the initial filter as an `or` condition. * @requiredField filter * @returns Refined WixDataSearch object. */ or(filter: WixDataFilter): WixDataSearch; /** * Adds an `and` condition to the search filter. * * The `and()` method adds an `and` condition to the search filter. A search with an `and` returns all the items that match both the filter as defined up to the `and()` method, and the filter passed to the `and()` method. * * When chaining multiple filter methods to a search, an `and` condition is often assumed by default. For example, the search returns results whose status is active **and** age is greater than 25: * * ```javascript * items * .search("myCollection") * .expression("some text") * .eq("status", "active") * .gt("age", 25); * ``` * * The `and()` method is needed when using compound filters. For example, the final search in this set of operations returns results whose status is either pending or rejected **and** age is either less than 25 or greater than 65: * * ```javascript * let statusFilter = items * .filter() * .eq("status", "pending") * .or(items.filter().eq("status", "rejected")); * * let ageFilter = items * .filter() * .lt("age", 25) * .or(items.filter().gt("age", 65)); * * let finalSearch = items * .search("myCollection") * .expression("some text") * .and(statusFilter) * .and(ageFilter); * ``` * * > **Note**: Calling `and()` without a filter may lead to unexpected results. * * @public * @documentationMaturity preview * @param filter - Filter to add to the initial search filter as an `and` condition. * @requiredField filter * @returns Refined WixDataSearch object. */ and(filter: WixDataFilter): WixDataSearch; /** * Adds a `not` condition to the search filter. * * The `not()` method adds a `not` condition to the search filter. A search with a `not` returns all the items that match the filter as defined up to the `not()` method and don't match the filter passed to the `not()` method. * * If the search filter only contains a `not()` method, it returns all the items that don't match the filter specified to the method. * * @public * @documentationMaturity preview * @param filter - Filter to add to the initial filter as a `not` condition. * @requiredField filter * @returns Refined WixDataSearch object. */ not(filter: WixDataFilter): WixDataSearch; /** * Refines a search to match items where the value of the specified field is within a specified range. * * The `between()` method refines the search to only match items where the value of the specified field is greater than or equal to `rangeStart` and less than `rangeEnd`. * * The method only matches values of the same [data type](https://dev.wix.com/docs/api-reference/business-solutions/cms/data-types-in-wix-data). For example, a number value stored as a number does not match the same number stored as a string. * * If a field contains a number as a string, that value is compared alphabetically and not numerically. Items that do not have a value for the specified field are ranked lowest. * * The following types of fields can be compared: * - Number: Compares numerically. * - Date: Compares JavaScript Date objects. * - String: Compares lexicographically, so * - `"A"` and `"M"` are between `"A"` and `"Z"`, but `"a"`, `"m"`, `"z"` and `"Z"` are not. * - `"A"`, `"M"`, `"Z"`, and `"a"` are between `"A"` and `"z"`, but `"z"` is not. * @public * @documentationMaturity preview * @param field - Field whose value is compared with `rangeStart` and `rangeEnd`. * @requiredField field * @param rangeStart - Starting value of the range to match (inclusive). * @requiredField rangeStart * @param rangeEnd - Ending value of the range to match (exclusive). * @requiredField rangeEnd * @returns Refined WixDataSearch object. */ between(field: string, rangeStart: string | number | Date, rangeEnd: string | number | Date): WixDataSearch; /** * Lists the fields to return in the search results. * * The `fields()` method specifies which fields to return in the search results. * * You can use `include()` together with `fields()` to get referenced items. * * When `fields()` receives an empty or an invalid field, the search behaves as follows: * - When no fields are specified, the search returns all fields. * - When multiple fields are specified but some are invalid, invalid fields are ignored and valid fields are returned. * - When only invalid fields are specified, only the default `_id` field is returned. * @public * @documentationMaturity preview * @param fields - Fields to return. * @requiredField fields * @returns Refined WixDataSearch object. */ fields(...fields: string[]): WixDataSearch; /** * Limits the number of items the search returns. * * The `limit()` method defines the number of results a search operation returns in each page. Only one page of results is retrieved at a time. The `next()` and `prev()` methods of the [`WixDataResult`](https://dev.wix.com/docs/sdk/backend-modules/data/items/wix-data-result/introduction) object are used to navigate the pages of a search result. * * By default, `limit` is set to `100`. * * The maximum value that `limit()` can accept is `1000`. * * @public * @documentationMaturity preview * @param limitNumber - Number of items to return, which is also the `pageSize` of the results object. * @requiredField limitNumber * @returns Refined WixDataSearch object. */ limit(limitNumber: number): WixDataSearch; /** * Sets the number of items to skip before returning search results. * * The `skip()` method defines the number of results to skip in the search results before returning new search results. * * For example, if your search matches 50 items, but you set `skip` to 10, the results returned skips the first 10 items that match and return the 11th through 50th items. * * By default, `skip()` is set to 0. * @public * @documentationMaturity preview * @param skipCount - Number of items to skip before returning the results. * @requiredField skipCount * @returns Refined WixDataSearch object. */ skip(skipCount: number): WixDataSearch; /** * Includes referenced items for the specified fields. * * The `include()` method refines a search so that the items returned in the search results include the full referenced items for the specified fields. * * For example, suppose you have a **books** collection with an **author** field that references an **authors** collection. Searching the **books** collection with an `include("author")` returns the relevant book items, and each item includes the full referenced author item in the book's `author` field. * * When searching a collection that contains a reference field without using the `include()` method: * - Single reference field: returned items contain only the ID of the referenced item, and not the full referenced items. * - Multiple reference field: returned items do not contain the multiple reference field at all. * * When including a field with multiple references, the following limitations apply: * - Only one field with multiple references can be included. * - The search returns an error if more than 50 items are returned, regardless of any search limit set using the `limit()` method. * - Each returned item can include up to 50 referenced items. If there are more than 50 referenced items, only 50 are returned, and the `partialIncludes` field of the returned `WixDataResult` is `true`. * * > **Note:** The `include()` method is not supported for [single-item collections](https://support.wix.com/en/article/cms-adding-and-setting-up-a-single-item-collection). * * @public * @documentationMaturity preview * @param fields - Fields for which to include referenced items. * @requiredField fields * @returns Refined WixDataSearch object. */ include(...fields: string[]): WixDataSearch; /** * Overload for `include()`. Includes referenced items for the specified field in a search's results. * @public * @documentationMaturity preview * @param field - Field for which to include referenced items. * @param limit - Optional limit for the number of referenced items to include (behavior may vary). * @returns Refined WixDataSearch object. */ include(field: string, limit?: number): WixDataSearch; /** * Overload for `include()`. Includes referenced items for the specified fields in a search's results. * @public * @documentationMaturity preview * @param field1 - First field for which to include referenced items. * @param field2 - Second field for which to include referenced items. * @param limit - Optional limit for the number of referenced items to include (behavior may vary). * @returns Refined WixDataSearch object. */ include(field1: string, field2: string, limit?: number): WixDataSearch; /** * Overload for `include()`. Includes referenced items for the specified fields in a search's results. * @public * @documentationMaturity preview * @param field1 - First field. * @param field2 - Second field. * @param field3 - Third field. * @param limit - Optional limit. * @returns Refined WixDataSearch object. */ include(field1: string, field2: string, field3: string, limit?: number): WixDataSearch; /** * Overload for `include()`. Includes referenced items for the specified fields in a search's results. * @public * @documentationMaturity preview * @param field1 - First field. * @param field2 - Second field. * @param field3 - Third field. * @param field4 - Fourth field. * @param limit - Optional limit. * @returns Refined WixDataSearch object. */ include(field1: string, field2: string, field3: string, field4: string, limit?: number): WixDataSearch; /** * Overload for `include()`. Includes referenced items for the specified fields in a search's results. * @public * @documentationMaturity preview * @param field1 - First field. * @param field2 - Second field. * @param field3 - Third field. * @param field4 - Fourth field. * @param field5 - Fifth field. * @param limit - Optional limit. * @returns Refined WixDataSearch object. */ include(field1: string, field2: string, field3: string, field4: string, field5: string, limit?: number): WixDataSearch; /** * Overload for `include()`. Includes referenced items for the specified fields in a search's results. * Allows specifying multiple field names and an optional limit. * @public * @documentationMaturity preview * @param fieldNamesAndLimit - Array of field names, optionally followed by a limit number. * @returns Refined WixDataSearch object. */ include(...fieldNamesAndLimit: [...string[], number]): WixDataSearch; } //# sourceMappingURL=WixDataSearch.d.ts.map