Module: Decidim::Searchable

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'll also need to define it as `searchable` in its resource manifest, otherwise it won't 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

Class Method Details

.searchable_resourcesObject

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_of_type_commentObject


41
42
43
# File 'decidim-core/lib/decidim/searchable.rb', line 41

def self.searchable_resources_of_type_comment
  searchable_resources.select { |r| r == "Decidim::Comments::Comment" }
end

.searchable_resources_of_type_componentObject


37
38
39
# File 'decidim-core/lib/decidim/searchable.rb', line 37

def self.searchable_resources_of_type_component
  searchable_resources.select { |r| r.constantize.ancestors.include?(Decidim::HasComponent) }
end

.searchable_resources_of_type_participantObject


29
30
31
# File 'decidim-core/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_spaceObject


33
34
35
# 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(:components).present? }
end