From: Tom Hughes Date: Fri, 7 May 2010 21:29:09 +0000 (+0100) Subject: Merge branch 'master' into openstreetbugs X-Git-Tag: live~5697^2~214 X-Git-Url: https://git.openstreetmap.org./rails.git/commitdiff_plain/160429e62d88810ec49ccc9c504edee675dca080 Merge branch 'master' into openstreetbugs Conflicts: lib/osm.rb --- 160429e62d88810ec49ccc9c504edee675dca080 diff --cc lib/osm.rb index 1358c993a,46b904477..2a1ca089e --- a/lib/osm.rb +++ b/lib/osm.rb @@@ -498,15 -499,24 +499,34 @@@ module OS return "#{tilesql} AND #{prefix}latitude BETWEEN #{minlat} AND #{maxlat} AND #{prefix}longitude BETWEEN #{minlon} AND #{maxlon}" end + # Return an SQL fragment to select a given area of the globe without using the quadtile index + def self.sql_for_area_no_quadtile(minlat, minlon, maxlat, maxlon, prefix = nil, without_quadtile = :false) + minlat = (minlat * 10000000).round + minlon = (minlon * 10000000).round + maxlat = (maxlat * 10000000).round + maxlon = (maxlon * 10000000).round + + return "#{prefix}latitude BETWEEN #{minlat} AND #{maxlat} AND #{prefix}longitude BETWEEN #{minlon} AND #{maxlon}" + end + + # Return a spam score for a chunk of text + def self.spam_score(text) + link_count = 0 + link_size = 0 + doc = Nokogiri::HTML(text) + + if doc.content.length > 0 + doc.xpath("//a").each do |link| + link_count += 1 + link_size += link.content.length + end + + link_proportion = link_size.to_f / doc.content.length.to_f + else + link_proportion = 0 + end + + return [link_proportion - 0.2, 0.0].max * 200 + link_count * 20 + end end