Forum .LRN Q&A: Response to dotLRN on .NET

Collapse
Posted by Dan Wickstrom on
I played around with the google example a little more, and it turns out that the soap interface is quite easy to use. Here is an example search query:

package require nsjava

# import the google search classes
nsjava::import -package com.google.soap.search GoogleSearch GoogleSearchResult
set result ""

# create a google search instance
set s [nsjava::new GoogleSearch]

# set the authorization key
$s {setKey String} 0XmNi33L1CMmAUFQxxxbOyyyDzdf

nsjava::try {
    $s {setQueryString String} $q
    set r [$s doSearch]
} catch {GoogleSearchFault f} {
    append result " The call to the Google Web APIs failed:[$f toString]"
}

# was a result returned?
if [string equal $result ""] {
    set count [$r getEstimatedTotalResultsCount]
    set etime [$r getSearchTime]
    set sidx [$r getStartIndex]
    set eidx [$r getEndIndex]
    set els [$r getResultElements]
    set result "<h3>Search Results ([expr $eidx - $sidx + 1]) item(s) in $etime seconds</h3>
"

    set cnt 1
    for {set i $sidx} {$i < $eidx} {incr i} {
        set el [$els get $i]
        append result "${cnt}.  <a href="[$el getURL]">[$el getTitle]</a><br>
[$el getSnippet]<br>"
        incr cnt
    }

}


ns_return 200 text/html $result


It turns out that the googleapi.jar file contains the following contents:

So other than the google soap wrapper api, the rest of this code is freely available. Assuming that nsjava could be made to operate reliably (including easy installation), soap integration with aolserver is already freely available now.