Sha256: 495149314c8a41b6f61139579bd74a8ca8370fe55878f1ad3800627b7c63d820

Contents?: true

Size: 870 Bytes

Versions: 5

Compression:

Stored size: 870 Bytes

Contents

module Locomotive
  module Liquid
    module Tags

      class SearchFor < Solid::Block

        # register the tag
        tag_name :search_for

        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

        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

      end

    end
  end
end

Version data entries

5 entries across 5 versions & 1 rubygems

Version Path
locomotivecms-search-0.3.6 lib/locomotive/search/concerns/locomotive/liquid/tags/search_for.rb
locomotivecms-search-0.3.5 lib/locomotive/search/concerns/locomotive/liquid/tags/search_for.rb
locomotivecms-search-0.3.4 lib/locomotive/search/concerns/locomotive/liquid/tags/search_for.rb
locomotivecms-search-0.3.3 lib/locomotive/search/concerns/locomotive/liquid/tags/search_for.rb
locomotivecms-search-0.3.2 lib/locomotive/search/concerns/locomotive/liquid/tags/search_for.rb