The Wix JavaScript SDK provides search builder utility methods that let you construct search requests using a chainable syntax. You can pass the resulting search object directly to any SDK search method.
SDK search methods accept a search request object that specifies a full-text expression, filter conditions, sort order, and paging. While you can write these objects directly, building them can be difficult, especially when conditions depend on runtime logic.
Search builder utilities offer the following benefits:
.withSearchClause() and .withFilter(), rather than writing JSON objects by hand.Each SDK API exports the following utilities alongside its search methods:
| Utility | Purpose |
|---|---|
SearchParams(expression) | Creates a search clause for a full-text expression. Supports .fuzzy() for approximate matching, .mode() to control whether all or any terms must match, and .fields() to restrict the search to specific fields. |
SearchBuilder() | Combines a search clause, filters, sorts, and paging into a complete search request object. Supports .withSearchClause(), .withFilter(), .withSorting(), .withPaging(), and .build(). |
Filter(fieldName) | Creates a filter condition for a specified field. Supports operators like .eq(), .ne(), .gt(), .gte(), .lt(), .lte(), .in(), .nin(), .exists(), .startsWith(), .isEmpty(), .hasAll(), and .hasSome(). Same utility used with QueryBuilder. |
Sort(fieldName) | Creates a sort condition for a specified field. Supports .asc() for ascending and .desc() for descending order. Same utility used with QueryBuilder. |
The following examples search for products matching "running shoes", filter to active items, and sort by price.
Search builder utilities are particularly useful when you need to construct search requests based on conditions that aren't known until runtime. Instead of manually assembling a JSON object, you can compose search parameters programmatically.
For example, the following helper method builds a search request where the filter, sort, and fuzzy matching are optional and determined by the caller: