cirandas.net

ref: master

plugins/elasticsearch/lib/elasticsearch_plugin/api.rb


 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
require_relative '../../helpers/elasticsearch_helper'
require_relative 'entities'

class ElasticsearchPlugin::API < Grape::API
  include Api::Helpers
  helpers ElasticsearchHelper

  resource :search do
    get do
      target = process_results
      present target,
              :with => Elasticsearch::Entities::Result,
              :types => searchable_types.except(:all).keys.map { |key| key.to_s.classify }
    end

    get 'types' do
      types = {types: searchable_types.stringify_keys.keys }
      present types, with: Grape::Presenters::Presenter
    end

    get 'sort_types' do
      present sort_types, with: Grape::Presenters::Presenter
    end

  end

end