diff options
author | Giuseppe Bilotta <giuseppe.bilotta@gmail.com> | 2012-09-14 08:55:39 +0200 |
---|---|---|
committer | Giuseppe Bilotta <giuseppe.bilotta@gmail.com> | 2012-09-14 08:55:39 +0200 |
commit | 983ad7a177ddb05519ff09b68d7bbf03bf9830a5 (patch) | |
tree | 892ad05cf0449c395548e3079885318938c9f4ae /data/rbot/plugins/search.rb | |
parent | 135370baac12057242320636a3e7758c3a683f13 (diff) |
search: improve ddg output with missing sources
Sometimes duckduckgo fails to report the source/url of a definition or
abstract. Cope with this by removing the leading double dash when no
source information is provided
Diffstat (limited to 'data/rbot/plugins/search.rb')
-rw-r--r-- | data/rbot/plugins/search.rb | 25 |
1 files changed, 19 insertions, 6 deletions
diff --git a/data/rbot/plugins/search.rb b/data/rbot/plugins/search.rb index 1102d5e5..a4c4a89c 100644 --- a/data/rbot/plugins/search.rb +++ b/data/rbot/plugins/search.rb @@ -98,15 +98,28 @@ class SearchPlugin < Plugin answer = xml.elements['//Answer/text()'].to_s # abstract is returned for definitions etc abstract = xml.elements['//AbstractText/text()'].to_s + abfrom = "" unless abstract.empty? - absrc = xml.elements['//AbstractSource/text()'] - aburl = xml.elements['//AbstractURL/text()'] + absrc = xml.elements['//AbstractSource/text()'].to_s + aburl = xml.elements['//AbstractURL/text()'].to_s + unless absrc.empty? and aburl.empty? + abfrom = " --" + abfrom << " " << absrc unless absrc.empty? + abfrom << " " << aburl unless aburl.empty? + end end + # but also definition (yes, you can have both, see e.g. printf) definition = xml.elements['//Definition/text()'].to_s + deffrom = "" unless definition.empty? defsrc = xml.elements['//Definition/@source/text()'].to_s defurl = xml.elements['//Definition/@url/text()'].to_s + unless defsrc.empty? and defurl.empty? + deffrom = " --" + deffrom << " " << defsrc unless defsrc.empty? + deffrom << " " << defurl unless defurl.empty? + end end if heading.empty? and answer.empty? and abstract.empty? and definition.empty? @@ -122,15 +135,15 @@ class SearchPlugin < Plugin # otherwise, return the abstract, followed by as many hits as found unless heading.empty? or abstract.empty? - m.reply "%{bold}%{heading}:%{bold} %{abstract} -- %{absrc} %{aburl}" % { + m.reply "%{bold}%{heading}:%{bold} %{abstract}%{abfrom}" % { :bold => Bold, :heading => heading, - :abstract => abstract, :absrc => absrc, :aburl => aburl + :abstract => abstract, :abfrom => abfrom } end unless heading.empty? or definition.empty? - m.reply "%{bold}%{heading}:%{bold} %{abstract} -- %{absrc} %{aburl}" % { + m.reply "%{bold}%{heading}:%{bold} %{abstract}%{abfrom}" % { :bold => Bold, :heading => heading, - :abstract => definition, :absrc => defsrc, :aburl => defurl + :abstract => definition, :abfrom => deffrom } end # return zeroclick search results |