full_search 0.3.8 → 0.3.9

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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: a86070d05b32fc24ce6ac007a33c673c3831760ce76554bbb9d636e6e0c6be0f
4
- data.tar.gz: 293b0be9931c7ffa5de9971aa52b2bf9014c2b0816d1364f839ccba57af8f814
3
+ metadata.gz: d8865ec65e8e55ecc1648ab56cd7f65f77ea7a05b6928f0771492a1e2ed1bf68
4
+ data.tar.gz: 8bbe570d9fa72cd9ed8d567174501807bc4b4d1726fcc4600e857219c3d59b2c
5
5
  SHA512:
6
- metadata.gz: cd9854cc22d14bd739723e5011a831fd34d0e523ef6a6df09bf45fa1f3a7880c466f4ba121eb07d9d92daf65449edf74b5e0ddc42dc15b521ea34e78b496be3a
7
- data.tar.gz: f704e822cee03ad98f2ed96dbc802e3e5b777df659ecdc3d8187ace6088494ab318b6f1598c74b840697909b465e539a76ee9f758d6a709041d9e0b198d45129
6
+ metadata.gz: 1d91fea14e22584bca2ecdd617119068a54ef60d3f8d79d9109c5e51a6f8b4cd562f0a37e34a3e0ce01ec4dda29ebe5e0ef85d7ef7a51a8d5a922efa59086fdc
7
+ data.tar.gz: 2089966acfa5bc274cde458cb27a7a739e70493d75027b507794ffa905048f772f2e72d8a213c8ad779f312424c8509181cf57ae1aeaccf252a9522e690099a4
data/README.md CHANGED
@@ -223,6 +223,18 @@ The rebuild task checks each model's stored config hash against the current DSL
223
223
  bin/rails full_search:reset
224
224
  ```
225
225
 
226
+ ### Schema dump
227
+
228
+ By default, `full_search` includes its FTS virtual tables in `db/schema.rb` so that `db:schema:load` produces a complete, loadable database. To exclude them:
229
+
230
+ ```ruby
231
+ FullSearch.configure do |config|
232
+ config.dump_schema_virtual_tables = false
233
+ end
234
+ ```
235
+
236
+ When disabled, you must run `bin/rails full_search:prepare` after every `db:schema:load` to recreate the indexes.
237
+
226
238
  ### Rake tasks
227
239
 
228
240
  | Task | Description |
@@ -4,7 +4,8 @@ module FullSearch
4
4
  class Config
5
5
  attr_accessor :auto_rebuild_schema, :stale_query_behavior, :lock_rebuilds,
6
6
  :default_async_reindex, :default_async_source_reindex,
7
- :default_tokenizer, :auto_rebuild_on_stale_query, :min_like_prefix_length
7
+ :default_tokenizer, :auto_rebuild_on_stale_query, :min_like_prefix_length,
8
+ :dump_schema_virtual_tables
8
9
 
9
10
  def initialize
10
11
  @auto_rebuild_schema = false
@@ -15,6 +16,7 @@ module FullSearch
15
16
  @default_tokenizer = FullSearch::Constants::DEFAULT_TOKENIZER
16
17
  @auto_rebuild_on_stale_query = false
17
18
  @min_like_prefix_length = FullSearch::Constants::DEFAULT_MIN_LIKE_PREFIX_LENGTH
19
+ @dump_schema_virtual_tables = true
18
20
  end
19
21
  end
20
22
 
@@ -6,7 +6,7 @@ module FullSearch
6
6
  TWO_TYPO_MIN_LENGTH = 9
7
7
  DEFAULT_MIN_LIKE_PREFIX_LENGTH = 3
8
8
  REBUILDING_HASH = "__rebuilding__"
9
- DEFAULT_TOKENIZER = "unicode61"
9
+ DEFAULT_TOKENIZER = "porter"
10
10
  MAX_EXACT_MATCH_BOOST_IDS = 100
11
11
  end
12
12
  end
@@ -36,7 +36,7 @@ module FullSearch
36
36
  end
37
37
 
38
38
  trigram_was_created = false
39
- if dsl.typo_tolerance? && !trigram_table_exists?(model)
39
+ if trigram_table_needed?(model) && !trigram_table_exists?(model)
40
40
  FullSearch::Typo.warn_unsupported!(model) unless FullSearch::Typo.supported?(model)
41
41
  conn.execute(create_trigram_virtual_table_sql(model))
42
42
  trigram_was_created = true
@@ -70,12 +70,12 @@ module FullSearch
70
70
  conn.execute("DROP TABLE IF EXISTS #{qt(fts_table_name(model))};")
71
71
  conn.execute("DROP TABLE IF EXISTS #{qt(trigram_table_name(model))};")
72
72
  conn.execute(create_virtual_table_sql(model))
73
- if dsl.typo_tolerance?
73
+ if trigram_table_needed?(model)
74
74
  FullSearch::Typo.warn_unsupported!(model) unless FullSearch::Typo.supported?(model)
75
75
  conn.execute(create_trigram_virtual_table_sql(model))
76
76
  end
77
77
  conn.execute(backfill_sql(model))
78
- conn.execute(backfill_trigram_sql(model)) if dsl.typo_tolerance?
78
+ conn.execute(backfill_trigram_sql(model)) if trigram_table_needed?(model)
79
79
  reindex_source_fields!(model) if dsl.fields.any?(&:source)
80
80
  create_triggers!(model)
81
81
  optimize!(model)
@@ -141,7 +141,7 @@ module FullSearch
141
141
  if model.full_search_dsl.soft_delete_column
142
142
  connection.execute(soft_delete_removal_trigger_sql(model))
143
143
  end
144
- if model.full_search_dsl.typo_tolerance?
144
+ if trigram_table_needed?(model)
145
145
  connection.execute(insert_trigram_trigger_sql(model))
146
146
  connection.execute(delete_trigram_trigger_sql(model))
147
147
  connection.execute(update_trigram_trigger_sql(model))
@@ -199,6 +199,16 @@ module FullSearch
199
199
  !table_exists?(model)
200
200
  end
201
201
 
202
+ def trigram_table_needed?(model)
203
+ model.full_search_dsl&.typo_tolerance? && model.full_search_dsl.tokenize != "trigram"
204
+ end
205
+
206
+ def trigram_table_exists?(model)
207
+ connection.execute(
208
+ "SELECT name FROM sqlite_master WHERE type='table' AND name=#{q(trigram_table_name(model))} LIMIT 1"
209
+ ).any?
210
+ end
211
+
202
212
  private
203
213
 
204
214
  def connection
@@ -292,7 +302,7 @@ module FullSearch
292
302
  ).map { |r| r["name"] }
293
303
 
294
304
  expected = trigger_names(model)
295
- expected += trigram_trigger_names(model) if model.full_search_dsl.typo_tolerance?
305
+ expected += trigram_trigger_names(model) if trigram_table_needed?(model)
296
306
  return if (expected - existing).empty? && (existing - expected).empty?
297
307
 
298
308
  rebuild!(model)
@@ -391,12 +401,6 @@ module FullSearch
391
401
  SQL
392
402
  end
393
403
 
394
- def trigram_table_exists?(model)
395
- connection.execute(
396
- "SELECT name FROM sqlite_master WHERE type='table' AND name=#{q(trigram_table_name(model))} LIMIT 1"
397
- ).any?
398
- end
399
-
400
404
  def create_trigram_virtual_table_sql(model)
401
405
  dsl = model.full_search_dsl
402
406
  columns = (dsl.fields + dsl.filters.map { |f| FilterColumnPlaceholder.new(name: f.name) } + extra_columns(model))
@@ -11,6 +11,8 @@ module FullSearch
11
11
  private
12
12
 
13
13
  def virtual_tables(stream)
14
+ return unless FullSearch.config.dump_schema_virtual_tables
15
+
14
16
  virtual_tables = @connection.virtual_tables.reject { |name, _| ignored?(name) }
15
17
 
16
18
  if virtual_tables.any?
@@ -146,6 +146,8 @@ module FullSearch
146
146
  return like_prefix_ids(term, candidate_limit: candidate_limit)
147
147
  end
148
148
 
149
+ return [] unless FullSearch::Index.trigram_table_exists?(model)
150
+
149
151
  trigram_table = qt(FullSearch::Index.trigram_table_name(model))
150
152
  tbl = qt(model.table_name)
151
153
 
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module FullSearch
4
- VERSION = "0.3.8"
4
+ VERSION = "0.3.9"
5
5
  end
@@ -12,4 +12,8 @@ FullSearch.configure do |config|
12
12
  # Reindex computed source: fields synchronously (false) or via background job (true).
13
13
  # Bulk imports should use FullSearch.bulk_import(Model) { ... } to defer reindexing.
14
14
  config.default_async_source_reindex = true
15
+
16
+ # Uncomment to exclude full_search virtual tables from db/schema.rb.
17
+ # When false, you must run `bin/rails full_search:prepare` after db:schema:load.
18
+ # config.dump_schema_virtual_tables = false
15
19
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: full_search
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.3.8
4
+ version: 0.3.9
5
5
  platform: ruby
6
6
  authors:
7
7
  - Ben D'Angelo