From: Giuseppe Bilotta Date: Sun, 15 Oct 2006 11:18:26 +0000 (+0000) Subject: When searching Wikipedia, strip 'Wikipedia, the free encyclopedia' from titles X-Git-Url: https://git.netwichtig.de/gitweb/?a=commitdiff_plain;h=6b54811f182711d2e85018bd5b5a948763b0bb78;p=user%2Fhenk%2Fcode%2Fruby%2Frbot.git When searching Wikipedia, strip 'Wikipedia, the free encyclopedia' from titles --- diff --git a/data/rbot/plugins/search.rb b/data/rbot/plugins/search.rb index c44100b1..fd1aefdc 100644 --- a/data/rbot/plugins/search.rb +++ b/data/rbot/plugins/search.rb @@ -21,11 +21,15 @@ class SearchPlugin < Plugin def google(m, params) what = params[:words].to_s searchfor = URI.escape what + # This method is also called by other methods to restrict searching to some sites if params[:site] site = "site:#{params[:site]}+" else site = "" end + # It is also possible to choose a filter to remove constant parts from the titles + # e.g.: "Wikipedia, the free encyclopedia" when doing Wikipedia searches + filter = params[:filter] || "" url = "http://www.google.com/wml/search?q=#{site}#{searchfor}" @@ -42,7 +46,10 @@ class SearchPlugin < Plugin return end results = results[0...3].map { |res| - "#{res[0]}. #{Bold}#{Utils.decode_html_entities res[2].strip}#{Bold}: #{URI.unescape res[1].strip}" + n = res[0] + t = Utils.decode_html_entities res[2].gsub(filter, '').strip + u = URI.unescape res[1] + "#{n}. #{Bold}#{t}#{Bold}: #{u}" }.join(" | ") m.reply "Results for #{what}: #{results}" @@ -52,6 +59,7 @@ class SearchPlugin < Plugin lang = params[:lang] site = "#{lang.nil? ? '' : lang + '.'}wikipedia.org" params[:site] = site + params[:filter] = / - Wikipedia.*$/ return google(m, params) end end