class Locomotive::Liquid::Tags::SearchFor
Public Instance Methods
display(text, options = {}) { || ... }
click to toggle source
# File lib/locomotive/search/concerns/locomotive/liquid/tags/search_for.rb, line 10 def display(text, options = {}, &block) site_id = current_context.registers[:site]._id current_context.stack do current_context['search'] = search(site_id, text, options) yield end end
Protected Instance Methods
mounting_point()
click to toggle source
# File lib/locomotive/search/wagon/liquid/tags/search_for.rb, line 20 def mounting_point current_context.registers[:mounting_point] end
search(site_id, text, options = {})
click to toggle source
# File lib/locomotive/search/concerns/locomotive/liquid/tags/search_for.rb, line 22 def search(site_id, text, options = {}) search_options = { radius: 150 }.merge(options) conditions = { 'site_id' => site_id } begin ::ActiveSearch.search(text, conditions, search_options) rescue Exception => exception { 'error' => true, 'message' => exception.message } end end
search_for_content_entries(text)
click to toggle source
# File lib/locomotive/search/wagon/liquid/tags/search_for.rb, line 39 def search_for_content_entries(text) entries = mounting_point.content_entries.values entries.select { |entry| entry.searchable? && entry._label[text] }.map do |entry| { 'label' => entry._label, '_slug' => entry._slug, 'content_type_slug' => entry.content_type.slug, 'locale' => I18n.locale, 'highlighted' => { entry.content_type.label_field => "<em>#{entry._label}</em>" } } end end
search_for_pages(text)
click to toggle source
# File lib/locomotive/search/wagon/liquid/tags/search_for.rb, line 24 def search_for_pages(text) pages = mounting_point.pages.values pages.select { |page| page.searchable && page.title[text] }.map do |page| { 'title' => page.title, 'fullpath' => page.safe_fullpath, 'locale' => I18n.locale, 'highlighted' => { 'searchable_content' => "<em>#{page.title}</em>" } } end end