Module: Decidim::Searchable
- Extended by:
- ActiveSupport::Concern
- Included in:
- Accountability::Result, Assembly, Blogs::Post, Budgets::Budget, Budgets::Project, CollaborativeTexts::Document, Comments::Comment, Conference, Debates::Debate, Dev::DummyResource, Initiative, Meetings::Meeting, ParticipatoryProcess, ParticipatoryProcessGroup, Proposals::Proposal, User
- Defined in:
- decidim-core/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 'decidim-core/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
51 52 53 54 55 56 57 58 |
# File 'decidim-core/lib/decidim/searchable.rb', line 51 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
47 48 49 |
# File 'decidim-core/lib/decidim/searchable.rb', line 47 def self.searchable_resources_of_type_comment searchable_resources.select { |r| r == "Decidim::Comments::Comment" } end |
.searchable_resources_of_type_component ⇒ Object
39 40 41 42 43 44 45 |
# File 'decidim-core/lib/decidim/searchable.rb', line 39 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 'decidim-core/lib/decidim/searchable.rb', line 29 def self.searchable_resources_of_type_participant searchable_resources.slice("Decidim::User") end |
.searchable_resources_of_type_participatory_space ⇒ Object
33 34 35 36 37 |
# File 'decidim-core/lib/decidim/searchable.rb', line 33 def self.searchable_resources_of_type_participatory_space searchable_resources .select { |r| r.constantize.reflect_on_association(:organization).present? } .reject { |r| searchable_resources_of_type_participant.keys.include?(r) } end |