full_search 0.4.11 → 0.4.12

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: 5a941ba183d7dd00eead669ac8b534b4028b32bd1d991db16bc0318345266e14
4
- data.tar.gz: 6b7709cd3c9816ee80d5033cca05d8867f6e35df9d73c4294485772c658bc779
3
+ metadata.gz: c106ce290a8691c0e999d9415ab823b6073251c752f6653092f05bbf2edd22af
4
+ data.tar.gz: b6bb5c9ccc32f7424b5cf6ba7bd8a591110b02b1cb4321b0b27d1238dceaecf1
5
5
  SHA512:
6
- metadata.gz: 8cbd0bc9321c9de12c1bea7831ba58f1b7d447c61d9997fc9bdf4ea4dbcd3e4b5d79f559057048ebec79cfcc1c3102ebbd436c939a84dbf82289d13bf339e373
7
- data.tar.gz: '069b642037b70d91c2f0afc4491ceebb9bfdd6f40a68bc74366813d77e563915293f4cdbe87c44dc9aa10c38eca92c462916e0bc174926436031bb87f4365e1c'
6
+ metadata.gz: a07209c3569f34c84da841210a626828e56b48c7e8300045c2e609893e6d750340e3443c62b9d0140e530aa98ceca8766836b84151a68ae54526094261b8d326
7
+ data.tar.gz: 9b92eb8318b503a3b27af8f3a46426aff657644c4e34d583de68c72810b474660c7cddb1bd0650b03aafe847223928a9cef05f086068a99e50b0089749cfd479
@@ -4,7 +4,11 @@ module FullSearch
4
4
  class Dsl
5
5
  attr_reader :fields, :exact_matches, :filters, :model_class, :highlight_config, :rank_bys, :index_if_sql
6
6
 
7
- Field = Data.define(:name, :weight, :source, :reindex_on, :async, :async_source, :as, :version)
7
+ Field = Data.define(:name, :weight, :source, :reindex_on, :async, :async_source, :as, :version) do
8
+ def fts_column_name
9
+ as || name
10
+ end
11
+ end
8
12
  ExactMatch = Data.define(:name, :source, :sql, :version, :normalize)
9
13
  Filter = Data.define(:name, :required)
10
14
  RankBy = Data.define(:column, :direction)
@@ -285,6 +285,38 @@ module FullSearch
285
285
  end
286
286
  end
287
287
 
288
+ # Builds the human-readable status line for a model, used by the
289
+ # `full_search:status` task. Reports missing FTS tables and counts rows
290
+ # whose source fields are empty, using the FTS column names (respecting
291
+ # `as:` aliases) rather than the DSL field names.
292
+ def status(model)
293
+ return "MISSING TABLE" if missing_table?(model)
294
+
295
+ stored = stored_config_hash(model)
296
+ current = model.full_search_dsl.config_hash
297
+ status = (stored == current) ? "ok" : "stale"
298
+
299
+ source_fields = model.full_search_dsl.fields.select(&:source).map(&:fts_column_name)
300
+
301
+ drift_info = if source_fields.any?
302
+ conn = connection
303
+ qc = ->(name) { conn.quote_column_name(name) }
304
+ qt = ->(name) { conn.quote_table_name(name) }
305
+ empty_count = conn.execute(<<~SQL).first["c"]
306
+ SELECT COUNT(*) AS c
307
+ FROM #{qt.call(fts_table_name(model))}
308
+ WHERE #{source_fields.map { |c| "#{qc.call(c)} = ''" }.join(" OR ")}
309
+ SQL
310
+ " | empty source fields: #{empty_count}"
311
+ else
312
+ ""
313
+ end
314
+
315
+ trigger_info = missing_triggers?(model) ? " | MISSING TRIGGERS" : ""
316
+
317
+ "#{status}#{drift_info}#{trigger_info}"
318
+ end
319
+
288
320
  private
289
321
 
290
322
  BUSY_RETRIES = 3
@@ -316,7 +348,7 @@ module FullSearch
316
348
  end
317
349
 
318
350
  def column_name(col)
319
- (col.respond_to?(:as) && col.as) ? col.as : col.name
351
+ col.respond_to?(:fts_column_name) ? col.fts_column_name : col.name
320
352
  end
321
353
 
322
354
  def qc(name)
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module FullSearch
4
- VERSION = "0.4.11"
4
+ VERSION = "0.4.12"
5
5
  end
@@ -86,28 +86,7 @@ namespace :full_search do
86
86
  task status: :environment do
87
87
  Rails.application.eager_load!
88
88
  FullSearch.sorted_models.each do |model|
89
- stored = FullSearch::Index.stored_config_hash(model)
90
- current = model.full_search_dsl.config_hash
91
- status = (stored == current) ? "ok" : "stale"
92
- source_fields = model.full_search_dsl.fields.select(&:source).map(&:name)
93
-
94
- drift_info = if source_fields.any?
95
- conn = ActiveRecord::Base.connection
96
- qc = ->(name) { conn.quote_column_name(name) }
97
- qt = ->(name) { conn.quote_table_name(name) }
98
- empty_count = ActiveRecord::Base.connection.execute(<<~SQL).first["c"]
99
- SELECT COUNT(*) AS c
100
- FROM #{qt.call(FullSearch::Index.fts_table_name(model))}
101
- WHERE #{source_fields.map { |c| "#{qc.call(c)} = ''" }.join(" OR ")}
102
- SQL
103
- " | empty source fields: #{empty_count}"
104
- else
105
- ""
106
- end
107
-
108
- trigger_info = FullSearch::Index.missing_triggers?(model) ? " | MISSING TRIGGERS" : ""
109
-
110
- puts "#{model.table_name}: #{status}#{drift_info}#{trigger_info}"
89
+ puts "#{model.table_name}: #{FullSearch::Index.status(model)}"
111
90
  end
112
91
  end
113
92
 
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.4.11
4
+ version: 0.4.12
5
5
  platform: ruby
6
6
  authors:
7
7
  - Ben D'Angelo
@@ -189,7 +189,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
189
189
  - !ruby/object:Gem::Version
190
190
  version: '2.0'
191
191
  requirements: []
192
- rubygems_version: 4.0.18
192
+ rubygems_version: 4.0.10
193
193
  specification_version: 4
194
194
  summary: SQLite FTS5 full-text search for Rails/ActiveRecord
195
195
  test_files: []