Class: Workarea::Search::Settings
- Inherits:
-
Object
- Object
- Workarea::Search::Settings
- Includes:
- ApplicationDocument
- Defined in:
- app/models/workarea/search/settings.rb
Class Method Summary collapse
-
.current ⇒ Search::Settings
The site-specific Settings to use for the current request.
- .current=(settings) ⇒ Object
Instance Method Summary collapse
-
#elasticsearch_settings ⇒ Hash
The settings for creation of Elasticsearch indexes.
-
#name ⇒ String
For compatibility with admin features, models must respond to this method.
- #sanitized_synonyms ⇒ Object
Methods included from ApplicationDocument
Methods included from Sidekiq::Callbacks
add_worker, assert_valid_config!, async, caching_classes?, disable, enable, inline, #run_callbacks, workers, workers_list
Methods included from Mongoid::Document
Class Method Details
.current ⇒ Search::Settings
The site-specific Workarea::Search::Settings to use for the current request. Thread-safe.
21 22 23 24 |
# File 'app/models/workarea/search/settings.rb', line 21 def self.current Thread.current[:current_search_settings] || find_or_create_by(index: Elasticsearch::Document.current_index_prefix) end |
.current=(settings) ⇒ Object
26 27 28 |
# File 'app/models/workarea/search/settings.rb', line 26 def self.current=(settings) Thread.current[:current_search_settings] = settings end |
Instance Method Details
#elasticsearch_settings ⇒ Hash
The settings for creation of Elasticsearch indexes. Using them from here adds the synonyms as defined by the admin.
56 57 58 59 60 61 62 63 64 65 |
# File 'app/models/workarea/search/settings.rb', line 56 def elasticsearch_settings result = Workarea.config.elasticsearch_settings.deep_dup result[:analysis][:filter][:synonym] = { type: 'synonym', synonyms: sanitized_synonyms } result end |
#name ⇒ String
For compatibility with admin features, models must respond to this method.
34 35 36 |
# File 'app/models/workarea/search/settings.rb', line 34 def name 'Search Settings' end |
#sanitized_synonyms ⇒ Object
38 39 40 41 42 43 44 45 46 47 48 49 |
# File 'app/models/workarea/search/settings.rb', line 38 def sanitized_synonyms result = synonyms.to_s.split(/\r?\n/) # empty synonym filter breaks everything! if result.blank? ['synonims, synonyms'] else result.map do |line| line.gsub(/[-–]/, ' ').gsub(/\s?,\s?/, ',').gsub(/(\A\s|\s\z)/, '').downcase end end end |