Lasso Soft Inc. > Home


AuthorJason Huck
Posted20 Feb 2007
Updated15 Mar 2007
More by this author...


This tag retrieves search results from Yahoo!'s REST Web Search API. Returns a dictionary containing the result details. Requires [dictionary], [xml_tree], and a valid Yahoo! Application ID. All of the parameters shown in the documentation can be passed to the tag. Note that if you wish to change the type of search performed,  you must use 'searchtype' as the param name instead of 'type' to avoid conflicts with Lasso.

The following values are accessible in the resulting object:

->query - The original query used to create the results.
->found - The total found count (note: tends to vary).
->shown - The number of results shown.
->first - The position of the first result shown.
->last - The position of the last result shown.
->previous - The position needed to recreate the previous set of results.
->next - The position needed to create the next set of results.
->results - An array of dictionary objects containing the result data.

Each item in the results array contains the following values:
->title - The title of the page.
->summary - A summary or excerpt of the page.
->url - The URL of the page.
->clickurl - The same URL  through Yahoo!'s click-tracking mechanism.

Sample Usage

var('sr') = yahoo_search(
	-start=(action_param('skip') ? integer(action_param('skip')) | 1),


Displaying results ' + $sr->first + ' through ' + $sr->last + ' of ' + $sr->found + ' found for "' + $sr->query + '."

'; iterate($sr->results, local('i')); '
' + #i->title + '
\n'; '
' + #i->summary + '
\n'; /iterate; '
'; else; 'No results found.'; /if; $sr->previous ? '[Previous]'; $sr->next ? '[Next]';

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.

	-description='Returns search results via Yahoo!'
	!local_defined('results') ? local('results') = 10;
	local('getparams') = array;
	iterate(params, local('i'));
		local('p') = #i->first;
		#p == 'searchtype' ? #p = 'type';
		#getparams->insert(#p = #i->second);
		local('resp') = xml_tree(
	local('out') = dictionary(
		'query' = #query,
		'found' = integer(#resp->totalResultsAvailable),
		'shown' = integer(#resp->totalResultsReturned),
		'first' = integer(#resp->firstResultPosition),
		'results' = array
	#out->last = #out->first + #out->shown - 1;
	#out->previous = (#out->first > 1 ? #out->first - #results | null);
	#out->next = (#out->first + #results - 1 < #out->found ? #out->first + #results | null);
	// correct for yahoo's strange behavior on the last page of results
	#out->previous < 0 ? #out->previous = null;
	#out->shown < #results ? #out->next = null;
	iterate(#resp->Result, local('i'));
				'title' = #i->Title->contents,
				'summary' = #i->Summary->contents,
				'url' = #i->Url->contents,
				'clickurl' = #i->ClickUrl->contents

Related Tags


15 Mar 2007, Jason Huck


Added some workarounds for how previous/next skip counts are calculated to account for some funky math returned by the service on the last set of search results.

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