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 after_filter :compress_output
9 do_search(true,true,true)
13 do_search(true,false,false)
16 do_search(false,true,false)
19 do_search(false,false,true)
23 def do_search(do_ways,do_segments,do_nodes)
24 response.headers["Content-Type"] = 'text/xml'
27 value = params['value']
41 # Matching for tags table
52 cond_tbl = [sql] + cond_tbl
54 # Matching for tags column
56 cond_tags = ['tags LIKE ? OR tags LIKE ? OR tags LIKE ? OR tags LIKE ?',
58 ''+type+'='+value+';%',
59 '%;'+type+'='+value+';%',
60 '%;'+type+'='+value+'' ]
62 cond_tags = ['tags LIKE ? OR tags LIKE ?',
66 cond_tags = ['tags LIKE ? OR tags LIKE ?',
74 # First up, look for the ids of the ways we want
76 ways_tmp = WayTag.find(:all, :conditions => cond_tbl)
77 way_ids = ways_tmp.collect {|way| way.id }
80 # Now, segments matching
82 segs = Segment.find(:all, :conditions => cond_tags)
87 nodes = Node.find(:all, :conditions => cond_tags)
90 # Get the remaining objects:
91 # Fetch the ways (until now only had their ids)
92 ways = Way.find(way_ids)
94 # Fetch any segments needed for our ways (only have matching segments so far)
97 seg_ids += way.segments
99 segments += Segment.find(seg_ids)
101 # Fetch any nodes needed for our segments (only have matching nodes so far)
103 segments.each do |seg|
104 node_ids += seg.node_a
105 node_ids += seg.node_b
107 nodes += Node.find(node_ids)
111 doc = OSM::API.new.get_xml_doc
113 doc.root << node.to_xml_node()
116 segments.each do |segment|
117 doc.root << segment.to_xml_node()
121 doc.root << way.to_xml_node()
124 render :text => doc.to_s