Sha256: 75d05cdaabf8d2e3b361892d06fdb3b9c7dcc354fc7ea4b92bedd76886e13723
Contents?: true
Size: 1.49 KB
Versions: 1
Compression:
Stored size: 1.49 KB
Contents
module Locomotive class SearchService def from_backoffice(site, text, options = { radius: 150 }) # scope the search by the site conditions = { 'site_id' => site._id } # launch the search with the current engine ::ActiveSearch.search(text, conditions, radius: 150).map do |entry| # keep only what we really need to display in the suggestions list entry.slice('label', 'locale', 'search_type').tap do |_entry| _entry['path'] = entry_path(entry) _entry['content'] = entry_content(entry) _entry['with_locale'] = site.localized? end end end protected def entry_content(entry) content = nil # get the first non blank highligthed field entry['highlighted'].each do |name, value| content = value if content.nil? && value.present? end content end def entry_path(entry) case entry['original_type'] when 'Locomotive::Page' page_path(entry['original_id'], entry['locale']) when /^Locomotive::ContentEntry/ content_entry_path(entry['content_type_slug'], entry['original_id'], entry['locale']) else nil end end def page_path(id, locale) Locomotive::Engine.routes.url_helpers.edit_page_path(id, locale: locale) end def content_entry_path(content_type_slug, id, locale) Locomotive::Engine.routes.url_helpers.edit_content_entry_path(content_type_slug, id, locale: locale) end end end
Version data entries
1 entries across 1 versions & 1 rubygems
Version | Path |
---|---|
locomotivecms-search-0.3.0 | app/services/locomotive/search_service.rb |