Changeset 33148

Show
Ignore:
Timestamp:
05/07/09 22:59:19 (4 years ago)
Author:
sho
Message:

supported prev/next page.

Files:
1 modified

Legend:

Unmodified
Added
Removed
  • platform/tdiary/plugin/search-yahoo.rb

    r33145 r33148  
    33# search-yahoo.rb - site search plugin sample using Yahoo! Search BOSS API. 
    44# 
    5 # Copyright (C) 2009, TADA Tadashi <sho@spc.gr.jp> 
     5# Copyright (C) 2009, TADA Tadashi <t@tdtds.jp> 
    66# You can redistribute it and/or modify it under GPL. 
    77# 
     
    3434        appid = @conf['search-yahoo.appid'] 
    3535 
    36         url << "#{q}?appid=#{appid}&count=50&start=#{start}" 
     36        url << "#{q}?appid=#{appid}&count=20&start=#{start}" 
    3737 
    3838        proxy = @conf['proxy'] 
    3939        proxy = 'http://' + proxy if proxy 
    40         timeout( 10 ) do 
     40        timeout( 20 ) do 
    4141                open( url, :proxy => proxy ) {|f| f.read } 
    4242        end 
     
    6868        r = search_input_form( query ) 
    6969        r << '<dl class="search-result">' 
    70         res['resultset_web'].each do |elem| 
     70        (res['resultset_web']||[]).each do |elem| 
    7171                url = elem['url'] 
    7272                next unless url =~ @conf['search-yahoo.result_filter'] 
     
    7878        r << '</dl>' 
    7979 
    80 ### PENDING ### 
    81 #       r << '<div class="search-navi">' 
    82 #       doc.elements.to_a( '/ysearchresponse/prevpage' ).each do |p| 
    83 #               if /start=\d+/ =~ p.text then 
    84 #                       r << %Q|<a href="#{@conf.index}?q=#{u query}&#$&">&lt;前の50件</a>&nbsp;| 
    85 #               end 
    86 #       end 
    87 # 
    88 #       doc.elements.to_a( '/ysearchresponse/nextpage' ).each do |n| 
    89 #               if /start=\d+/ =~ n.text then 
    90 #                       r << %Q|<a href="#{@conf.index}?q=#{u query}&#$&">次の50件&gt;</a>| 
    91 #               end 
    92 #       end 
    93 #       r << '</div>' 
     80        r << '<div class="search-navi">' 
     81        (res['prevpage']||[]).each do |p| 
     82                if /start=\d+/ =~ p then 
     83                        r << %Q|<a href="#{@conf.index}?q=#{u query}&#$&">&lt;前の20件</a>&nbsp;| 
     84                end 
     85        end 
     86 
     87        (res['nextpage']||[]).each do |n| 
     88                if /start=\d+/ =~ n then 
     89                        r << %Q|<a href="#{@conf.index}?q=#{u query}&#$&">次の20件&gt;</a>| 
     90                end 
     91        end 
     92        r << '</div>' 
    9493 
    9594        r