Module: Decidim::Searchable
- Extended by:
- ActiveSupport::Concern
- Defined in:
- lib/decidim/searchable.rb
Overview
A concern with the features needed when you want a model to be searchable.
A Searchable should include this concern and declare its ‘searchable_fields`. You will also need to define it as `searchable` in its resource manifest, otherwise it will not appear as possible results.
The indexing of Searchables is managed through:
-
after_create callback configurable via ‘index_on_create`.
-
after_update callback configurable via ‘index_on_update`.
-
searchable_resources are destroyed when the Searchable is destroyed.
Class Method Summary collapse
-
.searchable_resources ⇒ Object
Public: a Hash of searchable resources where keys are class names, and values are the class instance for the resources.
- .searchable_resources_by_type ⇒ Object
- .searchable_resources_of_type_comment ⇒ Object
- .searchable_resources_of_type_component ⇒ Object
- .searchable_resources_of_type_participant ⇒ Object
- .searchable_resources_of_type_participatory_space ⇒ Object
Class Method Details
.searchable_resources ⇒ Object
Public: a Hash of searchable resources where keys are class names, and values
are the class instance for the resources.
23 24 25 26 27 |
# File 'lib/decidim/searchable.rb', line 23 def self.searchable_resources Decidim.resource_manifests.select(&:searchable).inject({}) do |searchable_resources, manifest| searchable_resources.update(manifest.model_class_name => manifest.model_class) end end |
.searchable_resources_by_type ⇒ Object
49 50 51 52 53 54 55 56 |
# File 'lib/decidim/searchable.rb', line 49 def self.searchable_resources_by_type [ searchable_resources_of_type_participant, searchable_resources_of_type_participatory_space, searchable_resources_of_type_component, searchable_resources_of_type_comment ] end |
.searchable_resources_of_type_comment ⇒ Object
45 46 47 |
# File 'lib/decidim/searchable.rb', line 45 def self.searchable_resources_of_type_comment searchable_resources.select { |r| r == "Decidim::Comments::Comment" } end |
.searchable_resources_of_type_component ⇒ Object
37 38 39 40 41 42 43 |
# File 'lib/decidim/searchable.rb', line 37 def self.searchable_resources_of_type_component searchable_resources .select { |r| r.constantize.ancestors.include?(Decidim::Searchable) } .reject { |r| searchable_resources_of_type_comment.keys.include?(r) } .reject { |r| searchable_resources_of_type_participant.keys.include?(r) } .reject { |r| searchable_resources_of_type_participatory_space.keys.include?(r) } end |
.searchable_resources_of_type_participant ⇒ Object
29 30 31 |
# File 'lib/decidim/searchable.rb', line 29 def self.searchable_resources_of_type_participant searchable_resources.slice("Decidim::User", "Decidim::UserGroup") end |
.searchable_resources_of_type_participatory_space ⇒ Object
33 34 35 |
# File 'lib/decidim/searchable.rb', line 33 def self.searchable_resources_of_type_participatory_space searchable_resources.select { |r| r.constantize.reflect_on_association(:components).present? } end |