- way_ids = Array.new
- ways = Array.new
- nodes = Array.new
- relations = Array.new
-
- # Matching for tags table
- cond_way = Array.new
- sql = '1=1'
- if type
- sql += ' AND current_way_tags.k=?'
- cond_way += [type]
- end
- if value
- sql += ' AND current_way_tags.v=? AND MATCH (current_way_tags.v) AGAINST (? IN BOOLEAN MODE)'
- cond_way += [value,'"' + value.sub(/[-+*<>"~()]/, ' ') + '"']
- end
- cond_way = [sql] + cond_way
-
- # Matching for tags table
- cond_rel = Array.new
- sql = '1=1'
- if type
- sql += ' AND current_relation_tags.k=?'
- cond_rel += [type]
- end
- if value
- sql += ' AND current_relation_tags.v=? AND MATCH (current_relation_tags.v) AGAINST (? IN BOOLEAN MODE)'
- cond_rel += [value,'"' + value.sub(/[-+*<>"~()]/, ' ') + '"']
- end
- cond_rel = [sql] + cond_rel
-
- # Matching for tags column
- if type and value
- cond_tags = ['tags LIKE ? OR tags LIKE ? OR tags LIKE ? OR tags LIKE ?',
- ''+type+'='+value+'',
- ''+type+'='+value+';%',
- '%;'+type+'='+value+';%',
- '%;'+type+'='+value+'' ]
- elsif type
- cond_tags = ['tags LIKE ? OR tags LIKE ?',
- ''+type+'=%',
- '%;'+type+'=%' ]
- elsif value
- cond_tags = ['tags LIKE ? OR tags LIKE ?',
- '%='+value+';%',
- '%='+value+'' ]
+ # Matching for node tags table
+ if do_nodes
+ nodes = Node.joins(:node_tags)
+ nodes = nodes.where(:current_node_tags => { :k => type }) if type
+ nodes = nodes.where(:current_node_tags => { :v => value }) if value
+ nodes = nodes.limit(100)