]> git.netwichtig.de Git - user/henk/code/ruby/rbot.git/commitdiff
When searching Wikipedia, strip 'Wikipedia, the free encyclopedia' from titles
authorGiuseppe Bilotta <giuseppe.bilotta@gmail.com>
Sun, 15 Oct 2006 11:18:26 +0000 (11:18 +0000)
committerGiuseppe Bilotta <giuseppe.bilotta@gmail.com>
Sun, 15 Oct 2006 11:18:26 +0000 (11:18 +0000)
data/rbot/plugins/search.rb

index c44100b1abaa106ba5367f683223b599200906ff..fd1aefdc8a70d512c9cba29d26bcf34a1e2156b3 100644 (file)
@@ -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