⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 searchservice.as

📁 Yahoo!search API. 用于搜索引擎接口
💻 AS
📖 第 1 页 / 共 4 页
字号:
/*Copyright (c) 2007, Yahoo! Inc. All rights reserved.Code licensed under the BSD License:http://developer.yahoo.com/flash/license.html*/package com.yahoo.webapis.search{	import com.yahoo.webapis.ServiceBase;	import com.yahoo.webapis.search.events.SearchFaultEvent;	import com.yahoo.webapis.search.events.SearchResultEvent;	import com.yahoo.webapis.search.params.SearchParams;		import flash.events.Event;	import flash.events.EventDispatcher;	import flash.events.HTTPStatusEvent;	import flash.events.IOErrorEvent;	import flash.events.ProgressEvent;	import flash.events.SecurityErrorEvent;	import flash.net.URLLoader;	import flash.net.URLRequest;	import flash.net.URLRequestMethod;	import com.yahoo.webapis.ServiceFault;			//--------------------------------------	//  Events	//--------------------------------------		/**	 *  Dispatched after a search is finished.	 * 	 *  @eventType com.yahoo.webapis.search.events.SearchResultEvent	 */	[Event(name="result", type="com.yahoo.webapis.search.events.SearchResultEvent")]	/**	 * Dispatched after a fault occurs.	 * This may happen due to incorrect parameters being sent.	 * @eventType com.yahoo.webapis.search.events.SearchFaultEvent	 */	[Event(name="fault", type="com.yahoo.webapis.search.events.SearchFaultEvent")]	/**	 * Yahoo! Search API Service Class.	 * 	 * <p>Yahoo! Search Web Services allow you to access Yahoo! content and services. </p>	 *  	 * 	 * @mxml	 *	 *  <p>The <code>&lt;yahoo:SearchService&gt;</code> has the following tag attributes:</p>	 *	 *  <pre>	 *  &lt;yahoo:SearchService	 *    <b>Properties</b>	 *    applicationId="YahooDemo"	 *    type="web|image|audio|video|local|artist|album|song|songDownload|news|context|termExtraction|related|spellingSuggestion"	 *    query="<i>No default</i>"	 *    startAt="0"	 *    maximumResults="10"	 *    request="<i>No default</i>"	 * 	 *    <b>Events</b>	 *    result="<i>No default</i>"	 *    fault="<i>No default</i>"	 *  /&gt;	 *  </pre>	 *	 * <p>To use this class in MXML, do the following:</p>	 *	 *  <pre>	 *    &lt;yahoo:SearchService applicationId="YahooDemo" type="web"/&gt;	 *  </pre>	 * 	 * <p>Then give the tag a <code>query</code> attribute with your search terms and call the <code>send()</code> method.	 * For more advanced usage, declare a <code>SearchParams</code> object, give it properties applicable to the type of search	 * you are performing, and pass this to the <code>send()</code> method</p>	 * 	 * @see #type	 * @see com.yahoo.webapis.search.params.SearchParams	 * @see #send()	 * 	 * @example	 * 	 * <listing version="3.0" >	 * &lt;?xml version="1.0" encoding="utf-8"?&gt;	 * &lt;mx:Application 	 * xmlns:mx="http://www.adobe.com/2006/mxml"  	 * xmlns:yahoo="http://www.yahoo.com" &gt;	 * 	 * &lt;!-- The formatter to format the total results with commas --&gt;	 * &lt;mx:NumberFormatter id="commaFormatter"/&gt;	 * 	 * &lt;!-- The Service for all types of searches --&gt;	 * &lt;yahoo:SearchService id="searchService" applicationId="YahooDemo" query="{criteriaTextInput.text}" type="web" maximumResults="50"/&gt;	 *  	 * &lt;!-- The form for searching --&gt;	 *  &lt;mx:HBox defaultButton="{searchButton}"&gt;	 *  		 * 	&lt;mx:TextInput id="criteriaTextInput"/&gt;	 * 	&lt;mx:Button id="searchButton" label="search" click="searchService.send()"/&gt;	 * 	 * &lt;/mx:HBox&gt;	 * 	 * &lt;mx:Label text="{commaFormatter.format(searchService.numResultsAvailable)} results" visible="{Boolean(searchService.numResultsAvailable)}"/&gt;	 *  	 * &lt;!-- The results as a List --&gt;	 * &lt;mx:List id="resultsList" showDataTips="true" dataProvider="{searchService.lastResult}" variableRowHeight="true" width="100%" height="100%"&gt;	 * 	&lt;mx:itemRenderer&gt;	 * 		&lt;mx:Component&gt;	 * 			&lt;mx:VBox toolTip="{data.summary}" doubleClickEnabled="true" doubleClick="navigateToURL(new URLRequest(data.clickURL), '_blank')"&gt;	 * 				&lt;mx:HBox &gt;	 * 					&lt;mx:Label text="{data.index  + 1}" width="25"/&gt;	 * 					&lt;mx:Text text="{data.name}" fontWeight="bold"/&gt;	 * 				&lt;/mx:HBox&gt;	 * 				&lt;mx:Image source="{data.thumbnail.url}" /&gt;	 * 			 &lt;/mx:VBox&gt;	 * 		&lt;/mx:Component&gt;	 * 	&lt;/mx:itemRenderer&gt;	 * &lt;/mx:List&gt;	 * &lt;/mx:Application&gt; 	 * </listing> 	 * 	 * @langversion ActionScript 3.0	 * @playerversion Flash 9	 * @author Alaric Cole 02/22/07	 */			public class SearchService extends ServiceBase	{		//--------------------------------------------------------------------------	    //	    //  Public Constants / Namespaces	    //	    //--------------------------------------------------------------------------	 	 	/**		* @private		*/	 	protected static const NAMESPACE_SEARCH:Namespace = new Namespace("urn:yahoo:srch");		/**		* @private		*/	 	protected static const NAMESPACE_NEWS:Namespace = new Namespace("urn:yahoo:yn");		/**		* @private		*/	 	protected static const NAMESPACE_IMAGE:Namespace = new Namespace("urn:yahoo:srchmi");		/**		* @private		*/	 	protected static const NAMESPACE_AUDIO:Namespace = new Namespace("urn:yahoo:srchma");		/**		* @private		*/	 	protected static const NAMESPACE_AUDIO_ALT:Namespace = new Namespace("urn:yahoo:srchmm");		/**		* @private		*/	 	protected static const NAMESPACE_VIDEO:Namespace = new Namespace("urn:yahoo:srchmv");		/**		* @private		*/	 	protected static const NAMESPACE_TERM_EXTRACTION:Namespace = new Namespace("urn:yahoo:cate");		/**		* @private		*/	 	protected static const NAMESPACE_LOCAL:Namespace = new Namespace("urn:yahoo:lcl"); 			 	//--------------------------------------------------------------------------	    //	    //  Search Type Constants	    //	    //--------------------------------------------------------------------------	    	    /**		* Yahoo! Web Search Web Services let you tap into the power of Yahoo! Search technologies 		* from within other sites, applications, and environments. 		*/		public static const WEB_SEARCH:String = "web";				/**		* The News Search service allows you to search the Internet for news stories.		*/		public static const NEWS_SEARCH:String = "news";				/**		* The Image Search Web Service allows you to search the Internet for images.		*/		public static const IMAGE_SEARCH:String = "image";				/**		* The Video Search service allows you to search the Internet for video clips.		*/		public static const VIDEO_SEARCH:String = "video";				/**		* Yahoo! Audio Search Web Services provide access to music data and audio files using structured and unstructured queries.		*/		public static const AUDIO_SEARCH:String = "audio";				/**		* The Podcast Search service allows you to search the Internet for audio podcasts.		*/		public static const PODCAST_SEARCH:String = "podcast";				/**		* The Artist Search service allows you to find information on a particular musical performer. 		*/		public static const ARTIST_SEARCH:String = "artist";				/**		* The Album Search service allows you to find information on music albums.		*/		public static const ALBUM_SEARCH:String = "album";				/**		* The Song Search service allows you to find information on individual songs.		*/		public static const SONG_SEARCH:String = "song";				/**		* The Song Download Location service allows you to find places to download individual songs, from the web, and from various online music sources.		*/		public static const SONG_DOWNLOAD_LOCATION_SEARCH:String = "songDownload";				/**		* Yahoo! Local Search APIs offer you a way to connect with the wealth of data in Yahoo! Local — including ratings and comments made by Yahoo! users. 		 * The content in Yahoo! Local makes a great addition to any mashup, bringing in location-based relevancy and the additional context of what real people have experienced in these places. 		*/		public static const LOCAL_SEARCH:String = "local";				/**		* The Related Suggestion service returns suggested queries to extend the power of a submitted query, providing variations on a theme to help you dig deeper.		*/		public static const RELATED_SUGGESTION:String = "related";				/**		* The Spelling Suggestion service provides a suggested spelling correction for a given term. 		*/		public static const SPELLING_SUGGESTION:String = "spellingSuggestion";				/**		* The Term Extraction Web Service provides a list of significant words or phrases extracted from a larger content. It is one of the technologies used in Y!Q.		*/		public static const TERM_EXTRACTION:String = "termExtraction";				/**		* The Contextual Web Search service allows you to search the Internet for web pages using a context-based query.		*/		public static const CONTEXT_ANALYSIS:String = "context";					 			//--------------------------------------------------------------------------	    //	    //  Private variables	    //	    //--------------------------------------------------------------------------			private var _numResultsAvailable:uint;		private var _numResultsReturned:uint;		private var _numTotalResultsReturned:uint;		private var _firstResultPosition:uint;		private var _lastResultPosition:uint;		private var _autoIncrement:Boolean;				private var _lastResult:Array = [];				/**		* The last search parameters sent		* @private		*/		private var previousRequest:String;				/**		* The last type invoked		* @private		*/		private var previousType:String = "";				private var _maximumResults:uint = 10;				//--------------------------------------------------------------------------	    //	    //  Search URLs	    //	    //--------------------------------------------------------------------------				/**		* 		* @private		*/		protected static const BASE_URL:String = "http://search.yahooapis.com/"; 		 		/**		* 		* @private		*/		protected static const WEB_SEARCH_URL:String = BASE_URL + "WebSearchService/V1/webSearch";		/**		* 		* @private		*/		protected static const RELATED_SUGGESTION_URL:String = BASE_URL + "WebSearchService/V1/relatedSuggestion";		/**		* 		* @private		*/		protected static const SPELLING_SUGGESTION_URL:String = BASE_URL + "WebSearchService/V1/spellingSuggestion";		/**		* 		* @private		*/		protected static const CONTEXT_ANALYSIS_URL:String = BASE_URL + "WebSearchService/V1/contextSearch";		/**		* 		* @private		*/		protected static const NEWS_SEARCH_URL:String = BASE_URL + "NewsSearchService/V1/newsSearch";				/**		* 		* @private		*/		protected static const IMAGE_SEARCH_URL:String = BASE_URL + "ImageSearchService/V1/imageSearch";		/**		* 		* @private		*/		protected static const VIDEO_SEARCH_URL:String = BASE_URL + "VideoSearchService/V1/videoSearch";				/**		* 		* @private		*/		protected static const AUDIO_SEARCH_URL:String = BASE_URL + "AudioSearchService/V1/audioSearch";		/**		* 		* @private		*/		protected static const PODCAST_SEARCH_URL:String = BASE_URL + "AudioSearchService/V1/podcastSearch";		/**		* 		* @private		*/		protected static const ARTIST_SEARCH_URL:String = BASE_URL + "AudioSearchService/V1/artistSearch";		/**		* 		* @private		*/		protected static const ALBUM_SEARCH_URL:String = BASE_URL + "AudioSearchService/V1/albumSearch";		/**		* 		* @private		*/		protected static const SONG_SEARCH_URL:String = BASE_URL + "AudioSearchService/V1/songSearch";		/**		* 		* @private		*/		protected static const SONG_DOWNLOAD_LOCATION_SEARCH_URL:String = BASE_URL + "AudioSearchService/V1/songDownloadLocation";				/**		* 		* @private		*/		protected static const TERM_EXTRACTION_URL:String = BASE_URL + "ContentAnalysisService/V1/termExtraction";				/**		* 		* @private		*/		protected static const LOCAL_SEARCH_URL:String = "http://local.yahooapis.com/LocalSearchService/V3/localSearch";				//--------------------------------------------------------------------------	    //	    //  Constructor	    //	    //--------------------------------------------------------------------------	

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -