Class: Kms::SearchService
- Inherits:
-
Object
- Object
- Kms::SearchService
- Defined in:
- app/services/kms/search_service.rb
Class Method Summary collapse
-
.register(resource, attributes_map) ⇒ Object
resource is a class attributes_map is a Hash where keys are SearchItem attributes like “title”, “link” and “content” and values are corresponding resource attributes.
Instance Method Summary collapse
-
#initialize(query = '') ⇒ SearchService
constructor
A new instance of SearchService.
- #search ⇒ Object
Constructor Details
#initialize(query = '') ⇒ SearchService
Returns a new instance of SearchService.
7 8 9 |
# File 'app/services/kms/search_service.rb', line 7 def initialize(query='') @query = query end |
Class Method Details
.register(resource, attributes_map) ⇒ Object
resource is a class attributes_map is a Hash where keys are SearchItem attributes like “title”, “link” and “content” and values are corresponding resource attributes
15 16 17 |
# File 'app/services/kms/search_service.rb', line 15 def self.register(resource, attributes_map) self.resources[resource] = attributes_map end |
Instance Method Details
#search ⇒ Object
19 20 21 22 23 24 25 26 27 |
# File 'app/services/kms/search_service.rb', line 19 def search return [] if @query.blank? search_results = Kms::SearchService.resources.map do |resource, attributes_map| resource_items = resource.advanced_search(keywords.join('|')) resource_items.map {|resource_item| Kms::SearchItem.item_for_searchable(resource_item, keywords, attributes_map) } end search_results.flatten end |