Class: Searcher::Configuration
- Inherits:
-
Object
- Object
- Searcher::Configuration
- Defined in:
- app/models/searcher/configuration.rb
Instance Attribute Summary collapse
-
#facets ⇒ Object
Returns the value of attribute facets.
- #models(*names_or_clases) ⇒ Object
-
#scopes ⇒ Object
Returns the value of attribute scopes.
-
#searcher ⇒ Object
Returns the value of attribute searcher.
Instance Method Summary collapse
- #facet(name, &block) ⇒ Object
- #group(name) ⇒ Object
-
#initialize(searcher, &block) ⇒ Configuration
constructor
A new instance of Configuration.
- #keywords(field, options = {}, &block) ⇒ Object
- #more_like_this(*args) ⇒ Object
- #more_like_this? ⇒ Boolean
- #more_like_this_params ⇒ Object
- #property(field, options = {}, &block) ⇒ Object
- #scope(name = :default, &block) ⇒ Object
- #search_models ⇒ Object
Constructor Details
#initialize(searcher, &block) ⇒ Configuration
Returns a new instance of Configuration.
10 11 12 13 14 15 16 17 18 |
# File 'app/models/searcher/configuration.rb', line 10 def initialize(searcher, &block) self.searcher = searcher self.scopes = {} self.facets = {} self.models = [] scope :runtime scope :default instance_eval &block if block end |
Instance Attribute Details
#facets ⇒ Object
Returns the value of attribute facets.
4 5 6 |
# File 'app/models/searcher/configuration.rb', line 4 def facets @facets end |
#models(*names_or_clases) ⇒ Object
27 28 29 |
# File 'app/models/searcher/configuration.rb', line 27 def models(*names_or_clases) self.models = [*names_or_clases] end |
#scopes ⇒ Object
Returns the value of attribute scopes.
2 3 4 |
# File 'app/models/searcher/configuration.rb', line 2 def scopes @scopes end |
#searcher ⇒ Object
Returns the value of attribute searcher.
2 3 4 |
# File 'app/models/searcher/configuration.rb', line 2 def searcher @searcher end |
Instance Method Details
#facet(name, &block) ⇒ Object
77 78 79 |
# File 'app/models/searcher/configuration.rb', line 77 def facet(name, &block) facets[name] = block end |
#group(name) ⇒ Object
87 88 89 90 91 |
# File 'app/models/searcher/configuration.rb', line 87 def group(name) scope do group(name) end end |
#keywords(field, options = {}, &block) ⇒ Object
20 21 22 23 24 25 |
# File 'app/models/searcher/configuration.rb', line 20 def keywords(field, ={}, &block) search_object.create_field(field, ) scope do |sunspot| sunspot.fulltext(search_object.send(field), &block) if search_object.send(field).presence end end |
#more_like_this(*args) ⇒ Object
93 94 95 |
# File 'app/models/searcher/configuration.rb', line 93 def more_like_this(*args) @more_like_this = args end |
#more_like_this? ⇒ Boolean
97 98 99 |
# File 'app/models/searcher/configuration.rb', line 97 def more_like_this? !!@more_like_this end |
#more_like_this_params ⇒ Object
101 102 103 |
# File 'app/models/searcher/configuration.rb', line 101 def more_like_this_params @more_like_this end |
#property(field, options = {}, &block) ⇒ Object
37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 |
# File 'app/models/searcher/configuration.rb', line 37 def property(field, ={}, &block) modificators = [*[:modificator]] + [*[:modificators]] modificators.each do |modificator| request_field = [field, modificator].compact.join('_') search_object.create_field(request_field, ) if block scope &block else scope do |sunspot| sunspot.with(field).send(modificator, search_object.send(request_field)) if search_object.send(request_field).presence end end end if modificators.empty? search_object.create_field(field, ) if block scope &block else scope do |sunspot| if (value = search_object.send(field)).present? if value.is_a? Array sunspot.all_of do |all_of| value.each do |v| all_of.with(field, v) end end else sunspot.with(field, value) end end end end end end |
#scope(name = :default, &block) ⇒ Object
81 82 83 84 85 |
# File 'app/models/searcher/configuration.rb', line 81 def scope(name=:default, &block) scopes[name] ||= [] scopes[name] << block if block searcher end |
#search_models ⇒ Object
31 32 33 34 35 |
# File 'app/models/searcher/configuration.rb', line 31 def search_models @search_models ||= @models.map do |name_or_class| name_or_class.is_a?(Class) ? name_or_class : name_or_class.to_s.classify.constantize end end |