USING: accessors assocs combinators goog-search.search kernel math quoting seperate-text sequences combinators.short-circuit ; IN: goog-search.results TUPLE: result rank url title summary ; TUPLE: result-list offset entries ; : ( -- tuple ) result new ; CONSTANT: begin-entry "

" CONSTANT: end-entry "" : get-results ( text -- seq ) begin-entry end-entry extract-all ; : add-rank ( result-list -- result-list' ) [ [ entries>> ] [ offset>> ] bi [ + 1+ >>rank ] curry map-index ] keep swap >>entries ; : trim-spaces+quotes ( text -- text' ) [ { [ 32 = ] [ CHAR: " = ] } 1|| ] trim ; : get-url ( text -- url ) ! TODO: prefer regexp url. "" "

" extract-one first strip-tags trim-spaces+quotes ; : get-summary ( text -- summary ) "
" extract-one dup empty? [ drop "" ] [ first strip-tags trim-spaces+quotes ] if ; : make-result ( text -- result ) [ ] dip { [ get-url >>url ] [ get-title >>title ] [ get-summary >>summary ] } cleave ; : raw>results ( tuple -- results-seq ) raw-results>> get-results [ make-result ] map ; ! main: : results ( query-tuple -- result-list ) ! main word - just use this word on the query tuple, after search. [ raw>results ] [ parameters>> "start" swap at dup [ drop 0 ] unless ] bi result-list new swap >>offset swap >>entries add-rank ;