@@ -379,7 +379,8 @@ type FieldFilter<
379379 : // primitive
380380 AddFuzzyFilterIfSupported <
381381 Schema ,
382- GetModelFieldType < Schema , Model , Field > ,
382+ Model ,
383+ Field ,
383384 AllowedKinds ,
384385 PrimitiveFilter <
385386 GetModelFieldType < Schema , Model , Field > ,
@@ -393,30 +394,36 @@ type FieldFilter<
393394 * Conditionally augments a primitive filter with the `fuzzy` operator when:
394395 * 1. The field's type is `String`, AND
395396 * 2. The `Fuzzy` filter kind is allowed for this field, AND
396- * 3. The schema's provider supports fuzzy search (postgres only).
397+ * 3. The schema's provider supports fuzzy search (postgres only), AND
398+ * 4. The field is annotated with `@fuzzy` in the ZModel schema.
397399 *
398400 * Returns `Base` unchanged when any condition fails — never `Base & {}`,
399401 * since intersecting with `{}` would strip `null`/`undefined` from `Base`.
400402 */
401403type AddFuzzyFilterIfSupported <
402404 Schema extends SchemaDef ,
403- FieldType extends string ,
405+ Model extends GetModels < Schema > ,
406+ Field extends GetModelFields < Schema , Model > ,
404407 AllowedKinds extends FilterKind ,
405408 Base ,
406- > = FieldType extends 'String'
407- ? 'Fuzzy' extends AllowedKinds
408- ? ProviderSupportsFuzzy < Schema > extends true
409- ? Base & {
410- /**
411- * Performs a fuzzy search on the string field. Only available when
412- * the schema's provider is `postgresql` (uses `pg_trgm`).
413- * See {@link FuzzyFilterPayload} for the full options reference.
414- */
415- fuzzy ?: FuzzyFilterPayload ;
416- }
409+ > =
410+ GetModelFieldType < Schema , Model , Field > extends 'String'
411+ ? 'Fuzzy' extends AllowedKinds
412+ ? ProviderSupportsFuzzy < Schema > extends true
413+ ? GetModelField < Schema , Model , Field > [ 'fuzzy' ] extends true
414+ ? Base & {
415+ /**
416+ * Performs a fuzzy search on the string field. Only available when
417+ * the schema's provider is `postgresql` (requires `pg_trgm` extension)
418+ * and the field is annotated with `@fuzzy` in the ZModel schema.
419+ * See {@link FuzzyFilterPayload} for the full options reference.
420+ */
421+ fuzzy ?: FuzzyFilterPayload ;
422+ }
423+ : Base
424+ : Base
417425 : Base
418- : Base
419- : Base ;
426+ : Base ;
420427
421428type EnumFilter <
422429 Schema extends SchemaDef ,
@@ -930,6 +937,14 @@ type StringFields<Schema extends SchemaDef, Model extends GetModels<Schema>> = {
930937 : never ;
931938} [ NonRelationFields < Schema , Model > ] ;
932939
940+ /**
941+ * String fields that have been annotated with `@fuzzy` and are therefore eligible
942+ * for `_fuzzyRelevance` ordering.
943+ */
944+ type FuzzyFields < Schema extends SchemaDef , Model extends GetModels < Schema > > = {
945+ [ Key in StringFields < Schema , Model > ] : GetModelField < Schema , Model , Key > [ 'fuzzy' ] extends true ? Key : never ;
946+ } [ StringFields < Schema , Model > ] ;
947+
933948/**
934949 * Payload for the `fuzzy` string filter operator. Performs a fuzzy search using
935950 * PostgreSQL `pg_trgm` (only available when the schema's provider is `postgresql`).
@@ -985,12 +1000,12 @@ export type FuzzyRelevanceOrderBy<Schema extends SchemaDef, Model extends GetMod
9851000 */
9861001 _fuzzyRelevance ?: {
9871002 /**
988- * String fields to compute relevance against (must be non-empty).
1003+ * String fields annotated with `@fuzzy` to compute relevance against (must be non-empty).
9891004 *
9901005 * When multiple fields are provided, the row's relevance score is the
9911006 * greatest per-field similarity, i.e. `GREATEST(similarity(field1, search), similarity(field2, search), ...)`.
9921007 */
993- fields : [ StringFields < Schema , Model > , ...StringFields < Schema , Model > [ ] ] ;
1008+ fields : [ FuzzyFields < Schema , Model > , ...FuzzyFields < Schema , Model > [ ] ] ;
9941009 /**
9951010 * The search term to compute relevance for.
9961011 */
0 commit comments