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
20 def do_search(do_ways,do_nodes)
22 value = params['value']
35 # Matching for tags table
37 sql = 'id IN (SELECT id FROM current_way_tags WHERE 1=1'
47 cond_tbl = [sql] + cond_tbl
49 # Matching for tags column
51 cond_tags = ['tags LIKE ? OR tags LIKE ? OR tags LIKE ? OR tags LIKE ?',
53 ''+type+'='+value+';%',
54 '%;'+type+'='+value+';%',
55 '%;'+type+'='+value+'' ]
57 cond_tags = ['tags LIKE ? OR tags LIKE ?',
61 cond_tags = ['tags LIKE ? OR tags LIKE ?',
69 # First up, look for the ways we want
71 ways = Way.find(:all, :conditions => cond_tbl, :limit => 100)
76 nodes = Node.find(:all, :conditions => cond_tags, :limit => 2000)
79 # Fetch any node needed for our ways (only have matching nodes so far)
80 nodes += Node.find(ways.collect { |w| w.nds }.uniq)
83 user_display_name_cache = {}
84 doc = OSM::API.new.get_xml_doc
86 doc.root << node.to_xml_node(user_display_name_cache)
90 doc.root << way.to_xml_node(user_display_name_cache)
93 render :text => doc.to_s, :content_type => "text/xml"