Class: SearchController

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

Instance Method Summary collapse

Instance Method Details

#change_global_listmodeObject



261
262
263
264
265
266
267
268
# File 'app/controllers/search_controller.rb', line 261

def change_global_listmode
  @varglobal=session[:varglobal]
  if params[:mode][:list]=="groupbyfiles"
     render(:partial =>"show_results_global_groupbyfile", :object => @varglobal)
  else
     render(:partial =>"show_results_global", :object => @varglobal)
  end
end

#change_partial_listmodeObject



252
253
254
255
256
257
258
259
# File 'app/controllers/search_controller.rb', line 252

def change_partial_listmode
  @varpartial=session[:varpartial]
  if params[:mode][:list]=="groupbyfiles"
     render(:partial =>"show_results_partial_groupbyfile", :object => @varpartial)
  else
     render(:partial =>"show_results_partial", :object => @varpartial)
  end
end

#change_points_listmodeObject



242
243
244
245
246
247
248
249
# File 'app/controllers/search_controller.rb', line 242

def change_points_listmode
  @varpoints=session[:varpoints]
  if params[:mode][:list]=="groupbyfiles"
     render(:partial =>"show_results_points_groupbyfile", :object => @varpoints)
  else
     render(:partial =>"show_results_points", :object => @varpoints)
  end
end

#change_resultsObject



215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
# File 'app/controllers/search_controller.rb', line 215

def change_results
  @varpoints = session[:varpoints] || []
  @varpartial = session[:varpartial] || []
  @varglobal = session[:varglobal] || []
  @varno_region = session[:varno_region] || []
  @mode = params[:show][:list]
  case @mode
  when "points"
    @no="p"
    @variables = @varpoints
  when "partial"
    @no="p"
    @variables = @varpartial
  when "global"
    @no="g"
    @variables = @varglobal
  when "no_region"
    @no=""
    @variables = @varno_region
  else
    @no=""
    @variables = @varpoints + @varpartial + @varglobal + @varno_region
  end
  render(:partial =>"show_results")
end

#indexObject



4
5
6
7
# File 'app/controllers/search_controller.rb', line 4

def index
  mapsearch
  return
end

#listvariablesObject



200
201
202
203
204
205
206
207
208
209
210
211
212
# File 'app/controllers/search_controller.rb', line 200

def listvariables
  @all_group = session[:all_points_group]
  @mode = params[:mode]
  
  if @mode=="points"
    @all_group = session[:all_points_group]
  elsif @mode=="partial"
    @all_group = session[:all_partial_group]
  end
  @points_group = @all_group[params[:gid]]
  @gid=params[:gid]
  render(:partial=>"show_variablelist")
end

#mapsearchObject



146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
# File 'app/controllers/search_controller.rb', line 146

def mapsearch
  @google_map_key = GFDNAVI_GOOGLE_MAP_KEY
  @page_title = 'search by google-map'

  if request.post?
    res = msearch
  else
    @query=Query.new();
  end

  session[:varglobal]=@varglobal
  session[:varpartial]=@varpartial
  session[:varpoints]=@varpoints
  session[:varno_region] = @varno_region
  session[:query]=@query
  session[:results]=@results
  session[:all_partial_group]=@all_partial_group
  session[:all_points_group]=@all_points_group

  @variables = Array.new
  [@varpoints, @varpartial, @varglobal, @varno_region].each{|ary|
    @variables += ary if Array === ary
  }
  render :action => "mapsearch"
end

#msearchObject



10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
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
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
# File 'app/controllers/search_controller.rb', line 10

def msearch
  debug="**debug**"
  @query = Query.new(params[:query])
  if(query_points = @query.querystring("points"))
    @varpoints = Node.find_by_sql( [query_points.gsub(/%/,'%%')] )
    @results = true
  else
    @varpoints = nil
  end

  if @query.spatial_region
    lon_len = @query.start_lon - @query.end_lon if @query.start_lon >= @query.end_lon
    lon_len = @query.end_lon - @query.start_lon if @query.start_lon < @query.end_lon
    lat_len = @query.start_lat - @query.end_lat if @query.start_lat >= @query.end_lat
    lat_len = @query.end_lat - @query.start_lat if @query.start_lat < @query.end_lat

    #e = lon_len / 5.0 if lon_len >= lat_len
    #e = lat_len / 5.0 if lat_len > lon_len
    # 
    #if ((@query.zoomlevel).to_i) < ((@query.oldzoomlevel).to_i)
    #   e = e * 2.0*(((@query.oldzoomlevel).to_f) - ((@query.zoomlevel).to_f))
    #elsif ((@query.zoomlevel).to_i) > ((@query.oldzoomlevel).to_i)
    #   e = e / 2.0 / (((@query.zoomlevel).to_f)-((@query.oldzoomlevel).to_f))
    #end
    e = params[:query][:span].to_f/15
  else
    e = 30.0
  end

  
  if @varpoints 
    all_points_group=Hash.new
    pg_count=0
    @varpoints.each { |v|
	SpatialAndTimeAttribute.find(:all, :conditions=>{:node_id=>v.id}).each { |s| 
         if (all_points_group.keys.length==0)
           all_points_group["point_group0"]=Array.new
           all_points_group["point_group0"].push s
           pg_count=1
         else 
           i=0
           while i <= pg_count do
             points_group = all_points_group["point_group#{i}"]
             if (i==pg_count)
                all_points_group["point_group#{pg_count}"]=Array.new
                all_points_group["point_group#{pg_count}"].push s
                pg_count=pg_count+1
                break               
             elsif (points_group[0].latitude_lb+e >= s.latitude_lb && points_group[0].latitude_lb-e <= s.latitude_lb && points_group[0].longitude_lb+e >= s.longitude_lb && points_group[0].longitude_lb-e <= s.longitude_lb)
                all_points_group["point_group#{i}"].push s
                break
             end
             i=i+1
           end #while 
         end #if
       }#SpatialAttributes
     } #@verpoints.each
    @all_points_group=all_points_group
  end #@verpoints
  
  if(query_partial = @query.querystring("partial"))
    debug+=query_partial
    @varpartial = Node.find_by_sql( [query_partial.gsub(/%/,'%%')] )
    @results = true
  else
    @varpartial = nil
  end

  if @varpartial
    pag_count=0
    all_partial_group=Hash.new
    
    @varpartial.each do |v| 
      SpatialAndTimeAttribute.find(:all, :conditions=>{:node_id=>v.id}).each{ |s|
       if (all_partial_group.keys.length==0)
         all_partial_group["partial_group0"]=Array.new
         all_partial_group["partial_group0"].push s
         pag_count=1
       else  
          i=0 
          while i<=pag_count do
            if (i==pag_count)
              all_partial_group["partial_group#{pag_count}"]=Array.new
              all_partial_group["partial_group#{pag_count}"].push s
              pag_count=pag_count+1
              break
            else
              partial_group=all_partial_group["partial_group#{i}"]
              if(partial_group[0].latitude_lb+e >= s.latitude_lb && partial_group[0].latitude_lb-e <= s.latitude_lb && partial_group[0].longitude_lb+e >= s.longitude_lb && partial_group[0].longitude_lb-e <= s.longitude_lb)
               all_partial_group["partial_group#{i}"].push s
               break
              end
            end
            i=i+1
          end #while 
        end #if 
      }#SpatialAttribute
    end 
    @all_partial_group=all_partial_group
  end 
  
  if(query_global = @query.querystring("global"))
    debug+=query_partial
    @varglobal = Node.find_by_sql( [query_global.gsub(/%/,'%%')] )
    @results = true
  else
    @varglobal = nil
  end

  if (query_no_region = @query.querystring("no_region"))
    debug += query_no_region
    @varno_region = Node.find_by_sql( [query_no_region.gsub(/%/,'%%')] )
    @resutls = true
  else
    @varno_region = nil
  end

  res=Hash.new
  res["debug"]=debug
  res["points"]=@all_points_group
  res["partial"]=@all_partial_group
  res["global"] = @varglobal
  res["no_region"] = @varnoapatialattribute
  res["radius"]=e
  return res
end

#re_searchObject



137
138
139
140
141
142
143
144
# File 'app/controllers/search_controller.rb', line 137

def re_search
  res = msearch
  session[:query]=@query
  session[:all_partial_group]=@all_partial_group
  session[:all_points_group]=@all_points_group

  return res
end

#remapsearchObject



172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
# File 'app/controllers/search_controller.rb', line 172

def remapsearch
  r=re_search
  @objs = Array.new
  if @all_points_group!=nil then
    @all_points_group.keys.each{ |key|
      group = @all_points_group[key]
      size = group.length if group.length > 30
      size = 30 if group.length <= 30 
      if group.length!=0 then
        @objs.push( {:gid=>key, :radius=>r["radius"],:posx=>group[0].latitude_lb, :posy=>group[0].longitude_lb, :size=>size, :num=>group.length, :mode=>"points"} )
      end
    }
  end
  if @all_partial_group!=nil then
    @all_partial_group.keys.each{ |key|
      group = @all_partial_group[key]
      size = group.length if group.length > 30
      size = 30 if group.length <= 30 
      if group.length!=0 then
        @objs.push( {:gid=>key, :radius=>r["radius"], :posx=>group[0].latitude_lb, :posy=>group[0].longitude_lb, :size=>size, :num=>group.length, :mode=>"partial"} )
      end
    }
  end
  @debug = r["debug"]
  @queryregion = {:start_lon=>@query.start_lon,:start_lat=>@query.start_lat,:end_lon=>@query.end_lon,:end_lat=>@query.end_lat}
  @windowregion = {:window_start_lon=>@query.window_start_lon,:window_start_lat=>@query.window_start_lat,:window_end_lon=>@query.window_end_lon,:window_end_lat=>@query.window_end_lat}
end