Class: Autoselect::TaxonName::Levels::Fast
- Defined in:
- lib/autoselect/taxon_name/levels/fast.rb
Overview
Fast level: prefix-only match on the cached column via direct Arel.
Goal: satisfy 80%+ of queries with minimal DB overhead (no GIN, no similarity).
Constant Summary
Constants inherited from Level
Level::DEFAULT_FUSE_MS, Level::EXTERNAL_FUSE_MS, Level::MINIMUM_RESULTS
Instance Method Summary collapse
-
#call(term:, operator: nil, project_id: nil, user_id: nil, **_kwargs) ⇒ Array
Of TaxonName instances.
- #description ⇒ Object
- #key ⇒ Object
- #label ⇒ Object
Methods inherited from Level
#external?, #fuse_ms, #metadata, #minimum_results, #model_key, #record_info, #record_info_html, #record_label, #record_label_html
Instance Method Details
#call(term:, operator: nil, project_id: nil, user_id: nil, **_kwargs) ⇒ Array
Returns of TaxonName instances.
24 25 26 27 28 29 30 31 32 33 34 35 36 37 |
# File 'lib/autoselect/taxon_name/levels/fast.rb', line 24 def call(term:, operator: nil, project_id: nil, user_id: nil, **_kwargs) return [] if term.blank? sanitized = ::ApplicationRecord.sanitize_sql_like(term) t = ::TaxonName.arel_table exact = t[:cached].eq(term) prefix = t[:cached].matches("#{sanitized}%") clause = exact.or(prefix) scope = ::TaxonName.where(clause.to_sql) scope = scope.where(project_id:) if project_id.present? scope.order(:cached).limit(20).to_a end |
#description ⇒ Object
17 18 19 |
# File 'lib/autoselect/taxon_name/levels/fast.rb', line 17 def description 'Prefix match on cached display name (fastest, no fuzzy matching)' end |
#key ⇒ Object
9 10 11 |
# File 'lib/autoselect/taxon_name/levels/fast.rb', line 9 def key :fast end |
#label ⇒ Object
13 14 15 |
# File 'lib/autoselect/taxon_name/levels/fast.rb', line 13 def label 'Fast' end |