Lasso Soft Inc. > Home

[gapi_search]

Linkgapi_search
AuthorKyle Jessup
CategoryUtility
Version8.x
LicensePublic Domain
Posted27 Apr 2006
Updated27 Apr 2006
More by this author...

Description

This tag sends a query to Google via their Search API and parses the results.  Requires a valid Google API Key. The sample code below demonstrates how the tag could be used to search the contents of a specific site. For more information about what parameters can be supplied to the tag, and how to use the results, see <http://www.google.com/apis/reference.html#1_1>.

Sample Usage

if(action_param('kwd'));
	// set defaults specific to this site
	var(
		'gapi_site' = 'www.example.com',
		'gapi_kwd' = action_param('kwd'),
		'gapi_max' = 10,
		'gapi_key' = 'a valid Google API key'
	);

	// set skip value	
	if(action_param('skip'));
		var('gapi_start') = integer(action_param('skip'));
	else;
		var('gapi_start' = 0);
	/if;

	// retrieve the results	
	protect;
		local('result' = gapi_search( 
			-q=($gapi_kwd + ' site:' + $gapi_site),
			-start=$gapi_start,
			-key=$gapi_key, 
			-maxResults=$gapi_max
		));

		var('gapi_found') = integer(#result->estimatedTotalResultsCount);
		
		if($gapi_start + $gapi_max < $gapi_found);
			var('gapi_shown' = $gapi_start + $gapi_max);
		else;
			var('gapi_shown' = $gapi_found);
		/if;
		
		'Displaying results ' + ($gapi_start + 1) + ' through ' 
			+ $gapi_shown + ' of ' + $gapi_found + ' for "'
			+ $gapi_kwd + '."
\n
\n'; iterate(#result->resultElements, local('i')); ' ' + #i->title + '
' + #i->snippet + '

'; /iterate; '
'; if($gapi_start > 0); 'Previous'; /if; '   '; if($gapi_start + $gapi_max < $gapi_found); 'Next'; /if; '
\n'; handle_error; '

Oops! We had trouble interpreting the response from Google. Please try again.

'; /handle_error; /protect; /if;

Source Code

Click the "Download" button below to retrieve a copy of this tag, including the complete documentation and sample usage shown on this page. Place the downloaded ".inc" file in your LassoStartup folder, restart Lasso, and you can begin using this tag immediately.

soap_definetag(
	'search', 
	-namespace='gapi_',
	-wsdl=xml(include_url('http://api.google.com/GoogleSearch.wsdl')),
	-operationname='doGoogleSearch',
	-defaults=map(
		'filter'=false, 
		'restrict'='',
		'safeSearch'=false, 
		'lr'='',
		'ie'='',
		'oe'=''
	),
	-procs=array(
		proc_extractOne('*[1]/*[1]'), 
		\proc_convert
	)
);

Related Tags

Comments

04 Aug 2007, Dominique Guardiola Falco

Error on startup

on OSX/Lasso 8.5.2, I get this errors after restarting with this tag :
-9948 ERROR while running startup script "gapi_search.inc". No tag, type or constant was defined under the name null->find with arguments: array: (urn:GoogleSearch)
at: loadSchema with params:

Please log in to comment

Subscribe to the LassoTalk mail list

LassoSoft Inc. > Home

 

 

©LassoSoft Inc 2015 | Web Development by Treefrog Inc | PrivacyLegal terms and Shipping | Contact LassoSoft