Introduction

The WixDataSearch methods enable you to perform search operations on your data collections. You can search for specific terms across all or some collection fields, use different search modes for flexible matching, apply fuzzy search for approximate matches, and add filters for precise results.

Build a search operation by calling the search() method, refine it by chaining WixDataSearch methods, and run the search by calling run().

Notes:

For example, the following code searches a products collection for items containing "pizza", and logs the results to the console:

Copy

Search Modes

Use different search modes to control how multiple search terms are matched. You can use the OR search mode, which returns an item if it contains at least one of the specified search terms. Alternatively, use the AND search mode to only return items that contain all search terms.

For example, the following code retrieves items that include both "pizza" and "cheese":

Copy

By contrast, the following code retrieves items that contain "pizza", "hamburger", or both:

Copy

You can refine your search by chaining filter methods to the search operations. For example, the following code searches for clients that contain "student", "college", or "university", allowing for fuzzy matches. It then filters the results for clients over 21 whose hobbies include the nightlife:

Copy

Note: Filtering is only supported for fields explicitly defined in the data collection structure. Fields not defined in the collection structure cannot be used for filtering.

Supported filters by field type

Each field type only supports some filter methods. Using a filter method that's not supported for a given field type causes the search to fail.

The table below summarizes which filter methods are supported for each field type:

Field TypeSupported Filters
Text, Image, Document, URL, Video, Audio, Time, Reference, Page Link, Rich Text, Rich Content, Addresseq(), ne(), gt(), ge(), lt(), le(), isEmpty(), isNotEmpty(), startsWith()
Number, Date, Date and Timeeq(), ne(), gt(), ge(), lt(), le(), isEmpty(), isNotEmpty()
Booleaneq(), ne(), isEmpty(), isNotEmpty()
Array of stringshasSome(), hasAll(), isEmpty(), isNotEmpty()
Array, Document Array, Object, Any, Media GalleryisEmpty(), isNotEmpty()

Learn more about data types in Wix Data.

Did this help?