Class: SearchController

Inherits:
ApplicationController show all
Defined in:
app/controllers/search_controller.rb

Instance Method Summary collapse

Instance Method Details

#indexObject



3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
# File 'app/controllers/search_controller.rb', line 3

def index
  @rule =  SEARCHRULES[params[:rule]]
  if @rule.nil? then
    respond_to do |format|
      format.html # index.html.erb
      format.json { render :json => {:success => false,  :quality => -9999, :msg => "ERROR: #{params[:rule]} model missing"} }
    end
  else
    result = @rule.model.query(@rule.fields, params)
    @features = result[:features]
    @quality = result[:quality]
    @success = @quality >= 0 

    respond_to do |format|
      format.html # index.html.erb
      if @success then
        format.json { render :json => {:success => @success, :features => features_for_json_reader(@features), :quality => @quality} }
      else
        @msg = result[:msg]
        format.json { render :json => {:success => @success, :features => features_for_json_reader(@features), :quality => @quality, :msg => @msg} }
      end
    end
  end
end

#locateObject



28
29
30
31
32
33
34
35
36
37
38
39
40
41
# File 'app/controllers/search_controller.rb', line 28

def locate
  rule = LOCATERULES[params[:rule]]
  if rule.nil?
    render :json => {:success => false, :msg => "ERROR: #{params[:rule]} model missing"}
  else
    location = rule.locate(params['locations'])
    unless location.nil?
      location[:success] = true
      render :json => location
    else
      render :json => {:success => false, :msg => "No features found"}
    end
  end
end

#soapObject



47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
# File 'app/controllers/search_controller.rb', line 47

def soap
  soap_action = nil
  soap_params = nil
  if params[:Envelope] && params[:Envelope][:Body]
    params[:Envelope][:Body].each do |key, value|
      soap_action = key
      soap_params = value
    end
  end

  if soap_action.nil? || soap_params.nil?
    # TODO: error response
    render :xml => "Invalid SOAP request"
    return
  end

  @rule =  SEARCHRULES[params[:rule]]
  result = @rule.model.soap_query(@rule.fields, soap_params, soap_action)
  if result[:error]
    #TODO: error response
    render :xml => result[:error]
  else
    @feature = result[:feature]
    @hits = result[:hits]
    @quality = result[:quality]
    @features = result[:features]
    render result[:template]
  end
end

#soap_wsdlObject



43
44
45
# File 'app/controllers/search_controller.rb', line 43

def soap_wsdl
  render "#{params[:rule]}_wsdl.xml"
end