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)
25 value = params['value']
39 # Matching for tags table
50 cond_tbl = [sql] + cond_tbl
52 # Matching for tags column
54 cond_tags = ['tags LIKE ? OR tags LIKE ? OR tags LIKE ? OR tags LIKE ?',
56 ''+type+'='+value+';%',
57 '%;'+type+'='+value+';%',
58 '%;'+type+'='+value+'' ]
60 cond_tags = ['tags LIKE ? OR tags LIKE ?',
64 cond_tags = ['tags LIKE ? OR tags LIKE ?',
72 # First up, look for the ids of the ways we want
74 ways_tmp = WayTag.find(:all, :conditions => cond_tbl)
75 way_ids = ways_tmp.collect {|way| way.id }
78 # Now, segments matching
80 segs = Segment.find(:all, :conditions => cond_tags)
85 nodes = Node.find(:all, :conditions => cond_tags)
88 # Get the remaining objects:
89 # Fetch the ways (until now only had their ids)
90 ways = Way.find(way_ids)
92 # Fetch any segments needed for our ways (only have matching segments so far)
95 seg_ids += way.segments
97 segments += Segment.find(seg_ids)
99 # Fetch any nodes needed for our segments (only have matching nodes so far)
101 segments.each do |seg|
102 node_ids += seg.node_a
103 node_ids += seg.node_b
105 nodes += Node.find(node_ids)
109 doc = OSM::API.new.get_xml_doc
111 doc.root << node.to_xml_node()
114 segments.each do |segment|
115 doc.root << segment.to_xml_node()
119 doc.root << way.to_xml_node()
122 render :text => doc.to_s, :content_type => "text/xml"