Paste: part1

Author: randy7
Mode: factor
Date: Fri, 6 Mar 2009 22:06:05
Plain Text |
USING: accessors arrays assocs hashtables http.client kernel sequences strings urls urls.encoding ;

IN: goog-search.search

! USAGE: 1) "search string" <google-query> search results
!        2) "search string" <google-query> "faluninfo.net" >>site "num" 25 param   search results


TUPLE: google-query 
    { url string read-only initial: "http://www.google.com/search" }
    { search string }
    { site string }
    { parameters hashtable } 
    { raw-results } ;

: avail-params ( -- hash )    
    H{  { "client" "opera" } { "rls" "en" } { "as_q" "" } { "filter" 0 } { "oe" "utf-8" }
        { "ie" "utf-8" } { "num" 100 } { "ft" "i" } { "sourceid" "opera" } { "start" 0 } ! 0-1000
        { "safe" "off" }   
        { "hl" "en" } { "as_filetype" f } { "as_occt" "any" } { "as_qdr" f }
     } clone ;

: <google-query> ( search -- tuple ) 
    [ google-query new ] dip 
                 >>search 
    avail-params >>parameters ;

: param ( tuple key value -- tuple )
    [ dup parameters>> ] 2dip spin   ! tuple val key parameters
    set-at ;                         ! tuple 

<PRIVATE     

: (site-str/f) ( tuple -- str/f )
    site>> dup empty? [ drop f ] [ 
    "site:" prepend ] if ;

: (search-string) ( tuple -- str )
    [ (site-str/f) ]
    [ search>> ] bi 2array harvest "+" join ;

: (search-string>as_q) ( tuple str -- tuple ) 
    "as_q" swap param ;
    
PRIVATE>
    
    
: search ( tuple -- tuple' )
    dup [ url>> ] 
        [ dup (search-string) (search-string>as_q) parameters>> assoc>query ] bi 
    "?" glue >url http-get nip >>raw-results ;
  

Annotation: maybe cleaner

Author: rand
Mode: factor
Date: Fri, 6 Mar 2009 22:50:00
Plain Text |
first query should return just the html page
use bi to get some more params from the query tuple.
step2:
then entries and rank them. 

the word should encompass all those, and the user won't see the two stages of search+results.

looks better than storing and retrieving ... less messy

New Annotation

Summary:
Author:
Mode:
Body: