summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorGiuseppe Bilotta <giuseppe.bilotta@gmail.com>2006-10-15 11:18:26 +0000
committerGiuseppe Bilotta <giuseppe.bilotta@gmail.com>2006-10-15 11:18:26 +0000
commit6b54811f182711d2e85018bd5b5a948763b0bb78 (patch)
tree7787badd97232ce3bacd9d2ca1e99a84b984f345
parent1d7ab28b2162db5c3a7b332a2f268d496b7c3c60 (diff)
When searching Wikipedia, strip 'Wikipedia, the free encyclopedia' from titles
-rw-r--r--data/rbot/plugins/search.rb10
1 files changed, 9 insertions, 1 deletions
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