1 class SearchController < ApplicationController
2 # Support searching for nodes, 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)
22 def do_search(do_ways,do_nodes,do_relations)
24 value = params['value']
38 # Matching for tags table
40 sql = 'id IN (SELECT id FROM current_way_tags WHERE 1=1'
50 cond_way = [sql] + cond_way
52 # Matching for tags table
54 sql = 'id IN (SELECT id FROM current_relation_tags WHERE 1=1'
64 cond_rel = [sql] + cond_rel
66 # Matching for tags column
68 cond_tags = ['tags LIKE ? OR tags LIKE ? OR tags LIKE ? OR tags LIKE ?',
70 ''+type+'='+value+';%',
71 '%;'+type+'='+value+';%',
72 '%;'+type+'='+value+'' ]
74 cond_tags = ['tags LIKE ? OR tags LIKE ?',
78 cond_tags = ['tags LIKE ? OR tags LIKE ?',
85 # First up, look for the relations we want
87 relations = Relation.find(:all, :conditions => cond_rel, :limit => 100)
92 ways = Way.find(:all, :conditions => cond_way, :limit => 100)
97 nodes = Node.find(:all, :conditions => cond_tags, :limit => 2000)
100 # Fetch any node needed for our ways (only have matching nodes so far)
101 nodes += Node.find(ways.collect { |w| w.nds }.uniq)
104 user_display_name_cache = {}
105 doc = OSM::API.new.get_xml_doc
107 doc.root << node.to_xml_node(user_display_name_cache)
111 doc.root << way.to_xml_node(user_display_name_cache)
114 relations.each do |rel|
115 doc.root << rel.to_xml_node(user_display_name_cache)
117 render :text => doc.to_s, :content_type => "text/xml"