Class: Autoselect::AssertedEnvironment::Levels::Fast

Inherits:
Level
  • Object
show all
Defined in:
lib/autoselect/asserted_environment/levels/fast.rb

Overview

Fast level: prefix-only match on uri_label - selecting one clones its uri/uri_label onto a new AssertedEnvironment (see Autoselect::AssertedEnvironment::Autoselect #response_values), it does not reference the found row itself.

Constant Summary

Constants inherited from Level

Level::DEFAULT_FUSE_MS, Level::EXTERNAL_FUSE_MS, Level::MINIMUM_RESULTS

Instance Method Summary collapse

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 AssertedEnvironment instances, deduplicated by uri.

Parameters:

  • term (String)
  • project_id (Integer, nil) (defaults to: nil)

Returns:

  • (Array)

    of AssertedEnvironment instances, deduplicated by uri



26
27
28
29
30
31
32
33
34
35
36
37
38
# File 'lib/autoselect/asserted_environment/levels/fast.rb', line 26

def call(term:, operator: nil, project_id: nil, user_id: nil, **_kwargs)
  return [] if term.blank?

  sanitized = ::ApplicationRecord.sanitize_sql_like(term)
  t = ::AssertedEnvironment.arel_table

  clause = t[:uri_label].matches("#{sanitized}%")

  scope = ::AssertedEnvironment.where(clause.to_sql)
  scope = scope.where(project_id:) if project_id.present?

  scope.order(:uri_label).limit(40).to_a.uniq(&:uri).first(20)
end

#descriptionObject



19
20
21
# File 'lib/autoselect/asserted_environment/levels/fast.rb', line 19

def description
  'ENVO terms already used in this project (prefix match, fastest)'
end

#keyObject



11
12
13
# File 'lib/autoselect/asserted_environment/levels/fast.rb', line 11

def key
  :fast
end

#labelObject



15
16
17
# File 'lib/autoselect/asserted_environment/levels/fast.rb', line 15

def label
  'Fast'
end