Class: Locomotive::SearchService

Inherits:
Object
  • Object
show all
Defined in:
app/services/locomotive/search_service.rb

Instance Method Summary collapse

Instance Method Details

#from_backoffice(site, text, options = { radius: 150 }) ⇒ Object



4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
# File 'app/services/locomotive/search_service.rb', line 4

def from_backoffice(site, text, options = { radius: 150 })
  # scope the search by the site
  conditions = { 'site_id' => site._id }

  # locale agnostic
  options[:locale] = false

  # launch the search with the current engine
  ::ActiveSearch.search(text, conditions, options).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