About Search Builder Utilities

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.

Why use search builder utilities

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:

  • Chainable syntax. Construct search requests by chaining method calls such as .withSearchClause() and .withFilter(), rather than writing JSON objects by hand.
  • Programmatic composition. Build search expressions, filter, and sort dynamically based on runtime logic, then combine them into a single request.
  • Type safety. The utility methods are fully typed, providing autocompletion and compile-time checks in TypeScript projects.

Available utilities

Each SDK API exports the following utilities alongside its search methods:

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

Code examples

The following examples search for products matching "running shoes", filter to active items, and sort by price.

With search builder utilities

Copy

With a direct search request object

Copy

Building dynamic searches

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:

Copy

See also

Did this help?