full_search 0.3.5 → 0.3.6
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
- data/README.md +28 -0
- data/lib/full_search/errors.rb +1 -0
- data/lib/full_search/index.rb +4 -0
- data/lib/full_search/search.rb +9 -1
- data/lib/full_search/version.rb +1 -1
- data/lib/tasks/full_search.rake +23 -0
- metadata +1 -1
checksums.yaml
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
---
|
|
2
2
|
SHA256:
|
|
3
|
-
metadata.gz:
|
|
4
|
-
data.tar.gz:
|
|
3
|
+
metadata.gz: 01b6db287587e57e3bc4f7226eff10257303eadf30c6a6a64e53be1e2e52afb5
|
|
4
|
+
data.tar.gz: 01ec5e01cf2d479245338c5a7ab23f778a9f953c78c7a0a1ab4f428a4472c98c
|
|
5
5
|
SHA512:
|
|
6
|
-
metadata.gz:
|
|
7
|
-
data.tar.gz:
|
|
6
|
+
metadata.gz: 6a3bd6143a47be3e7abd89df28506f247ee562205372ee9b5bedf6064d463413e212b7bca67dffb3e980531963e55984750adfed5504cf70b7e0dc7fa250185b
|
|
7
|
+
data.tar.gz: 3b793c3bfd872cf1a247a18c030ade28433d16d40bc71438d35dc79be2cd306d15ec79f0afc371c0866ef9feeca8d3292ed9f8af35c9bb6c572b8073be88a12b
|
data/README.md
CHANGED
|
@@ -125,6 +125,22 @@ These two operations are often confused:
|
|
|
125
125
|
> within the same process/connection. For multi-process or multi-host deployments,
|
|
126
126
|
> run `full_search:rebuild` from a single deployment step.
|
|
127
127
|
|
|
128
|
+
### First-deploy setup
|
|
129
|
+
|
|
130
|
+
After `db:prepare` creates your application tables, FTS virtual tables like `customers_fts` do not yet exist. Run `full_search:prepare` to create them:
|
|
131
|
+
|
|
132
|
+
```bash
|
|
133
|
+
bin/rails full_search:prepare
|
|
134
|
+
```
|
|
135
|
+
|
|
136
|
+
For Docker-based deployments, add this to your entrypoint script after `db:prepare:with_data`:
|
|
137
|
+
|
|
138
|
+
```bash
|
|
139
|
+
./bin/rails full_search:prepare
|
|
140
|
+
```
|
|
141
|
+
|
|
142
|
+
The `full_search:prepare` task is idempotent — it only creates missing tables and installs triggers. It will not drop or rebuild existing indexes, making it safe to run on every deploy.
|
|
143
|
+
|
|
128
144
|
### Auto-rebuild on app load
|
|
129
145
|
|
|
130
146
|
When `auto_rebuild_schema` is enabled (default in the generated initializer), the railtie hooks into Rails `after_initialize` and:
|
|
@@ -162,6 +178,7 @@ bin/rails full_search:reset
|
|
|
162
178
|
|
|
163
179
|
| Task | Description |
|
|
164
180
|
|------|-------------|
|
|
181
|
+
| `full_search:prepare` | Idempotent setup — creates missing FTS tables and triggers without dropping existing ones. Safe to run on every deploy. Add to your Docker entrypoint after `db:prepare:with_data` for first-deploy automation. |
|
|
165
182
|
| `full_search:rebuild` | Drops and recreates the FTS virtual table only when the DSL config hash has changed (safe for production). Pass model names to target specific tables. |
|
|
166
183
|
| `full_search:reset` | Force a full rebuild — drops and recreates all FTS tables regardless of config hash. Use when data may be out of sync. |
|
|
167
184
|
| `full_search:optimize` | Run FTS5 [`optimize`](https://www.sqlite.org/fts5.html#the_optimize_command) to merge b-tree segments. Useful after bulk updates. |
|
|
@@ -223,6 +240,17 @@ end
|
|
|
223
240
|
|
|
224
241
|
When this option is `true`, the first search that detects a stale index automatically calls `FullSearch::Index.rebuild_if_needed!` and then proceeds with the query, so you don't need to restart the server or run a Rake task during iterative development. In production, this defaults to `false`; use `full_search:rebuild` or boot-time `auto_rebuild_schema` instead.
|
|
225
242
|
|
|
243
|
+
### Missing table error
|
|
244
|
+
|
|
245
|
+
When the FTS table does not exist and a search is attempted, `full_search` raises `MissingTableError` with a clear message:
|
|
246
|
+
|
|
247
|
+
```
|
|
248
|
+
FullSearch::MissingTableError: FTS table `customers_fts` does not exist.
|
|
249
|
+
Run `bin/rails full_search:prepare` to create it.
|
|
250
|
+
```
|
|
251
|
+
|
|
252
|
+
This mirrors how Rails handles missing database tables — you see the error, run the task, and move on. Add `full_search:prepare` to your deploy pipeline or Docker entrypoint after `db:prepare:with_data` to prevent the error in production.
|
|
253
|
+
|
|
226
254
|
## Query operators
|
|
227
255
|
|
|
228
256
|
```ruby
|
data/lib/full_search/errors.rb
CHANGED
data/lib/full_search/index.rb
CHANGED
data/lib/full_search/search.rb
CHANGED
|
@@ -78,7 +78,15 @@ module FullSearch
|
|
|
78
78
|
end
|
|
79
79
|
|
|
80
80
|
def check_stale_config!
|
|
81
|
-
|
|
81
|
+
if FullSearch::Index.missing_table?(model)
|
|
82
|
+
raise MissingTableError, "FTS table `#{FullSearch::Index.fts_table_name(model)}` does not exist. Run `bin/rails full_search:prepare` to create it."
|
|
83
|
+
end
|
|
84
|
+
|
|
85
|
+
stored = begin
|
|
86
|
+
FullSearch::Index.stored_config_hash(model)
|
|
87
|
+
rescue StandardError
|
|
88
|
+
nil
|
|
89
|
+
end
|
|
82
90
|
return unless stored
|
|
83
91
|
|
|
84
92
|
return if stored == dsl.config_hash
|
data/lib/full_search/version.rb
CHANGED
data/lib/tasks/full_search.rake
CHANGED
|
@@ -17,6 +17,29 @@ def resolve_full_search_models(args)
|
|
|
17
17
|
end
|
|
18
18
|
|
|
19
19
|
namespace :full_search do
|
|
20
|
+
desc "Create full_search FTS tables and triggers if missing (idempotent, safe for first deploy)"
|
|
21
|
+
task :prepare, [:models] => :environment do |_t, args|
|
|
22
|
+
Rails.application.eager_load!
|
|
23
|
+
|
|
24
|
+
models = if args[:models]
|
|
25
|
+
args[:models].split(",").map do |name|
|
|
26
|
+
klass = begin
|
|
27
|
+
name.singularize.camelize.constantize
|
|
28
|
+
rescue NameError, LoadError
|
|
29
|
+
FullSearch.models.find { |m| m.table_name == name }
|
|
30
|
+
end
|
|
31
|
+
klass
|
|
32
|
+
end.compact
|
|
33
|
+
else
|
|
34
|
+
FullSearch.models
|
|
35
|
+
end
|
|
36
|
+
|
|
37
|
+
FullSearch.setup!
|
|
38
|
+
models.each do |model|
|
|
39
|
+
puts "Prepared #{FullSearch::Index.fts_table_name(model)}"
|
|
40
|
+
end
|
|
41
|
+
end
|
|
42
|
+
|
|
20
43
|
desc "Rebuild indexes when DSL has changed (checks config hash; safe for production)"
|
|
21
44
|
task :rebuild, [:models] => :environment do |_t, args|
|
|
22
45
|
Rails.application.eager_load!
|