1 class SearchController < ApplicationController
2 # Support searching for nodes, segments, ways, or all
3 # Can search by tag k, v, or both (type->k,value->v)
4 # Can search by name (k=name,v=....)
6 before_filter :authorize
7 after_filter :compress_output
10 do_search(true,true,true)
14 do_search(true,false,false)
17 do_search(false,true,false)
20 do_search(false,false,true)
24 def do_search(do_ways,do_segments,do_nodes)
25 response.headers["Content-Type"] = 'text/xml'
28 value = params['value']
42 # Matching for tags table
53 cond_tbl = [sql] + cond_tbl
55 # Matching for tags column
57 cond_tags = ['tags LIKE ? OR tags LIKE ? OR tags LIKE ? OR tags LIKE ?',
59 ''+type+'='+value+';%',
60 '%;'+type+'='+value+';%',
61 '%;'+type+'='+value+'' ]
63 cond_tags = ['tags LIKE ? OR tags LIKE ?',
67 cond_tags = ['tags LIKE ? OR tags LIKE ?',
75 # First up, look for the ids of the ways we want
77 ways_tmp = WayTag.find(:all, :conditions => cond_tbl)
78 way_ids = ways_tmp.collect {|way| way.id }
81 # Now, segments matching
83 segs = Segment.find(:all, :conditions => cond_tags)
88 nodes = Node.find(:all, :conditions => cond_tags)
91 # Get the remaining objects:
92 # Fetch the ways (until now only had their ids)
93 ways = Way.find(way_ids)
95 # Fetch any segments needed for our ways (only have matching segments so far)
98 seg_ids += way.segments
100 segments += Segment.find(seg_ids)
102 # Fetch any nodes needed for our segments (only have matching nodes so far)
104 segments.each do |seg|
105 node_ids += seg.node_a
106 node_ids += seg.node_b
108 nodes += Node.find(node_ids)
112 doc = OSM::API.get_xml_doc
114 doc.root << node.to_xml_node()
117 segments.each do |segment|
118 doc.root << segment.to_xml_node()
122 doc.root << way.to_xml_node()
125 render :text => doc.to_s