|
20 | 20 | * + fluent setters over the long named-argument constructor: |
21 | 21 | * |
22 | 22 | * Field::text($categoryId, 'title', 'Title') |
23 | | - * ->required()->indexed()->searchable()->maxLength(200); |
| 23 | + * ->required()->indexed()->maxLength(200); |
24 | 24 | * |
25 | 25 | * Each setter returns a new `Field` (immutable value-object semantics |
26 | 26 | * preserved — no mutable builder, no two-phase init). |
| 27 | + * |
| 28 | + * ## Flag semantics |
| 29 | + * |
| 30 | + * - `$indexed` — when true, the storage layer creates a SQLite generated |
| 31 | + * column over `json_extract(data, '$.<name>')` so equality/range |
| 32 | + * predicates on this field avoid a JSON-scan. |
| 33 | + * - `$searchable` — when true, this field's value is written into the |
| 34 | + * `items_fts.body` FTS5 column on every save. False means the value is |
| 35 | + * excluded from full-text search. Honored from 2.2.0 onward; the |
| 36 | + * factories pick sensible per-type defaults (prose-typed fields default |
| 37 | + * to true; passwords, numeric/date/structured/file fields default to |
| 38 | + * false). `name` and `label` are structural columns on the FTS table and |
| 39 | + * are always indexed regardless of this flag. |
27 | 40 | */ |
28 | 41 | final readonly class Field |
29 | 42 | { |
@@ -63,87 +76,90 @@ public function __construct( |
63 | 76 |
|
64 | 77 | // --------------------------------------------------------------------- |
65 | 78 | // Static factories — one per FieldType case. All return a fresh |
66 | | - // (id = null) Field with default flags + empty config. |
| 79 | + // (id = null) Field with an empty config and per-type `searchable` |
| 80 | + // defaults: prose-typed factories (text, longText, editor, slug) |
| 81 | + // default to searchable:true; everything else defaults to false. |
| 82 | + // Callers always override with `->searchable(true|false)`. |
67 | 83 | // --------------------------------------------------------------------- |
68 | 84 |
|
69 | 85 | public static function text(int $categoryId, string $name, ?string $label = null): self |
70 | 86 | { |
71 | | - return new self(null, $categoryId, $name, $label, FieldType::Text); |
| 87 | + return new self(null, $categoryId, $name, $label, FieldType::Text, searchable: true); |
72 | 88 | } |
73 | 89 |
|
74 | 90 | public static function longText(int $categoryId, string $name, ?string $label = null): self |
75 | 91 | { |
76 | | - return new self(null, $categoryId, $name, $label, FieldType::LongText); |
| 92 | + return new self(null, $categoryId, $name, $label, FieldType::LongText, searchable: true); |
77 | 93 | } |
78 | 94 |
|
79 | 95 | public static function editor(int $categoryId, string $name, ?string $label = null): self |
80 | 96 | { |
81 | | - return new self(null, $categoryId, $name, $label, FieldType::Editor); |
| 97 | + return new self(null, $categoryId, $name, $label, FieldType::Editor, searchable: true); |
82 | 98 | } |
83 | 99 |
|
84 | 100 | public static function slug(int $categoryId, string $name, ?string $label = null): self |
85 | 101 | { |
86 | | - return new self(null, $categoryId, $name, $label, FieldType::Slug); |
| 102 | + return new self(null, $categoryId, $name, $label, FieldType::Slug, searchable: true); |
87 | 103 | } |
88 | 104 |
|
89 | 105 | public static function password(int $categoryId, string $name, ?string $label = null): self |
90 | 106 | { |
91 | | - return new self(null, $categoryId, $name, $label, FieldType::Password); |
| 107 | + return new self(null, $categoryId, $name, $label, FieldType::Password, searchable: false); |
92 | 108 | } |
93 | 109 |
|
94 | 110 | public static function integer(int $categoryId, string $name, ?string $label = null): self |
95 | 111 | { |
96 | | - return new self(null, $categoryId, $name, $label, FieldType::Integer); |
| 112 | + return new self(null, $categoryId, $name, $label, FieldType::Integer, searchable: false); |
97 | 113 | } |
98 | 114 |
|
99 | 115 | public static function decimal(int $categoryId, string $name, ?string $label = null): self |
100 | 116 | { |
101 | | - return new self(null, $categoryId, $name, $label, FieldType::Decimal); |
| 117 | + return new self(null, $categoryId, $name, $label, FieldType::Decimal, searchable: false); |
102 | 118 | } |
103 | 119 |
|
104 | 120 | public static function money(int $categoryId, string $name, ?string $label = null): self |
105 | 121 | { |
106 | | - return new self(null, $categoryId, $name, $label, FieldType::Money); |
| 122 | + return new self(null, $categoryId, $name, $label, FieldType::Money, searchable: false); |
107 | 123 | } |
108 | 124 |
|
109 | 125 | public static function checkbox(int $categoryId, string $name, ?string $label = null): self |
110 | 126 | { |
111 | | - return new self(null, $categoryId, $name, $label, FieldType::Checkbox); |
| 127 | + return new self(null, $categoryId, $name, $label, FieldType::Checkbox, searchable: false); |
112 | 128 | } |
113 | 129 |
|
114 | 130 | public static function dropdown(int $categoryId, string $name, ?string $label = null): self |
115 | 131 | { |
116 | | - return new self(null, $categoryId, $name, $label, FieldType::Dropdown); |
| 132 | + return new self(null, $categoryId, $name, $label, FieldType::Dropdown, searchable: false); |
117 | 133 | } |
118 | 134 |
|
119 | 135 | public static function datepicker(int $categoryId, string $name, ?string $label = null): self |
120 | 136 | { |
121 | | - return new self(null, $categoryId, $name, $label, FieldType::Datepicker); |
| 137 | + return new self(null, $categoryId, $name, $label, FieldType::Datepicker, searchable: false); |
122 | 138 | } |
123 | 139 |
|
124 | 140 | public static function hidden(int $categoryId, string $name, ?string $label = null): self |
125 | 141 | { |
126 | | - return new self(null, $categoryId, $name, $label, FieldType::Hidden); |
| 142 | + return new self(null, $categoryId, $name, $label, FieldType::Hidden, searchable: false); |
127 | 143 | } |
128 | 144 |
|
129 | 145 | public static function arrayList(int $categoryId, string $name, ?string $label = null): self |
130 | 146 | { |
131 | | - return new self(null, $categoryId, $name, $label, FieldType::ArrayList); |
| 147 | + return new self(null, $categoryId, $name, $label, FieldType::ArrayList, searchable: false); |
132 | 148 | } |
133 | 149 |
|
134 | 150 | public static function file(int $categoryId, string $name, ?string $label = null): self |
135 | 151 | { |
136 | | - return new self(null, $categoryId, $name, $label, FieldType::Fileupload); |
| 152 | + return new self(null, $categoryId, $name, $label, FieldType::Fileupload, searchable: false); |
137 | 153 | } |
138 | 154 |
|
139 | 155 | public static function image(int $categoryId, string $name, ?string $label = null): self |
140 | 156 | { |
141 | | - return new self(null, $categoryId, $name, $label, FieldType::Imageupload); |
| 157 | + return new self(null, $categoryId, $name, $label, FieldType::Imageupload, searchable: false); |
142 | 158 | } |
143 | 159 |
|
144 | 160 | public static function filePicker(int $categoryId, string $name, ?string $label = null): self |
145 | 161 | { |
146 | | - return new self(null, $categoryId, $name, $label, FieldType::Filepicker); |
| 162 | + return new self(null, $categoryId, $name, $label, FieldType::Filepicker, searchable: false); |
147 | 163 | } |
148 | 164 |
|
149 | 165 | // --------------------------------------------------------------------- |
|
0 commit comments