Patches: Browse | Submit New | Admin

[#6666] yahoo/web_search: yahoo not always returns Cache/* fields

Date:
2006-11-14 12:05
Priority:
3
Submitted By:
Andrey Zaikin (zed_0xff)
Assigned To:
Nobody (None)
Category:
None
State:
Open
Summary:
yahoo/web_search: yahoo not always returns Cache/* fields

Detailed description
--- web_search.rb.bk    2006-11-14 17:02:20.000000000 +0500
+++ web_search.rb       2006-11-14 17:02:35.000000000 +0500
@@ -48,8 +48,8 @@
       result.click_url         = URI.parse r.elements['ClickUrl'].text
       result.mime_type         = r.elements['MimeType'].text
       result.modification_date = Time.at r.elements['ModificationDate'].text.to_i
-      result.cache_url         = URI.parse r.elements['Cache/Url'].text
-      result.cache_size        = r.elements['Cache/Size'].text.to_i
+      result.cache_url         = URI.parse r.elements['Cache/Url'].text unless r.elements['Cache/Url'] == nil
+      result.cache_size        = r.elements['Cache/Size'].text.to_i unless r.elements['Cache/Size'] == nil
 
       search_results << result
     end

Add A Comment: Notepad

Please login


Followup

Message
Date: 2007-10-14 16:22
Sender: David Welton

So it's been nearly a year since this has been reported.  Is
it time to fork this project?
Date: 2007-01-03 20:31
Sender: Walter Korman

I hit this issue as well.  It's a showstopper for folks looking
to use this library, so it'd be nice to see it fixed.  I'll have
to manually patch for now.  :-)

Here is an improved patch (IMO) that ensures all values are safely
obtained, avoiding nil exceptions, and also cleans up the code
for parsing URIs and Time values.

I can't find where the source is in svn/cvs, so just diffed locally
against the unmodified gem code.

44,51c44,51
<       result.title             = r.elements['Title'].text
<       result.summary           = r.elements['Summary'].text
<       result.url               = URI.parse
r.elements['Url'].text
<       result.click_url         = URI.parse
r.elements['ClickUrl'].text
<       result.mime_type        
= r.elements['MimeType'].text
<       result.modification_date = Time.at
r.elements['ModificationDate'].text.to_i
<       result.cache_url         = URI.parse
r.elements['Cache/Url'].text
<       result.cache_size       
= r.elements['Cache/Size'].text.to_i
---
>       result.title             = _safe_value(r, 'Title')
>       result.summary           = _safe_value(r, 'Summary')
>       result.url               = _safe_value(r, 'Url',
'to_uri')
>       result.click_url         = _safe_value(r, 'ClickUrl')
>       result.mime_type         = _safe_value(r, 'MimeType')
>       result.modification_date = _safe_value(r,
'ModificationDate', 'to_time')
>       result.cache_url         = _safe_value(r, 'Cache/Url',
'to_uri')
>       result.cache_size        = _safe_value(r, 'Cache/Size',
'to_i')
59a60,73
>   protected
> 
>     def _safe_value (element, key, format = 'to_s')
>       value = element.elements[key]
>       return nil if value.nil?
> 
>       text = value.text
>       case format
>       when 'to_uri' then URI.parse(text)
>       when 'to_time' then Time.at(text.to_i)
>       else text.send(format)
>       end
>     end
> 

Attached Files:

Name Description Download
No Files Currently Attached

Changes:

No Changes Have Been Made to This Item