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

📄 searchservice.as

📁 Yahoo!search API. 用于搜索引擎接口
💻 AS
📖 第 1 页 / 共 4 页
字号:
		* @param params SearchParams passed for using search filters.		*/		public function searchPodcasts(params:SearchParams = null):void		{			handleQueryLoading( PODCAST_SEARCH_URL,  SearchResultEvent.PODCAST_SEARCH_RESULT, params);		}				/**		* Search albums based on an album, album ID, artist, or artist ID.		* @param params SearchParams passed for using search filters.		*/		public function searchAlbums(params:SearchParams = null):void		{			handleQueryLoading( ALBUM_SEARCH_URL,  SearchResultEvent.ALBUM_SEARCH_RESULT, params);		}				/**		* Search artists based on an artist or artist ID.		* @param params SearchParams passed for using search filters.		*/		public function searchArtists(params:SearchParams = null):void		{			handleQueryLoading( ARTIST_SEARCH_URL,  SearchResultEvent.ARTIST_SEARCH_RESULT, params);		}				/**		* Search songs based on an song, song ID, album, album ID, artist, or artist ID.		* @param params SearchParams passed for using search filters.		*/		public function searchSongs(params:SearchParams = null):void		{			handleQueryLoading( SONG_SEARCH_URL,  SearchResultEvent.SONG_SEARCH_RESULT, params);		}				/**		* Search for places to download songs based on a song ID		* @param params SearchParams passed for using search filters.		*/		public function searchSongDownloads(params:SearchParams = null):void		{			handleQueryLoading( SONG_DOWNLOAD_LOCATION_SEARCH_URL,  SearchResultEvent.SONG_DOWNLOAD_LOCATION_SEARCH_RESULT, params);		}						/**		* Search video based on a query.		* @param params SearchParams passed for using search filters.		*/		public function searchVideos(params:SearchParams = null):void		{			handleQueryLoading( VIDEO_SEARCH_URL,  SearchResultEvent.VIDEO_SEARCH_RESULT, params);		}				/**		* Search spelling suggestions based on a misspelled word.		* @param params SearchParams passed for using search filters.		*/		public function searchSpellingSuggestions(params:SearchParams = null):void		{			handleQueryLoading( SPELLING_SUGGESTION_URL,  SearchResultEvent.SPELLING_SUGGESTION_RESULT, params);		}				/**		* Search related suggestions based on a query.		* @param params SearchParams passed for using search filters.		*/		public function searchRelatedSuggestions(params:SearchParams = null):void		{			handleQueryLoading( RELATED_SUGGESTION_URL,  SearchResultEvent.RELATED_SUGGESTION_RESULT, params);		}				/**		* Search keywords based on context.		* @param params SearchParams passed for using search filters.		*/		public function searchTermExtraction(params:SearchParams = null):void		{			handleQueryLoading( TERM_EXTRACTION_URL,  SearchResultEvent.TERM_EXTRACTION_RESULT, params);		}				/**		* Search pages based on a query and context.		* @param params SearchParams passed for using search filters.		*/		public function searchContextAnalysis(params:SearchParams = null):void		{			handleQueryLoading( CONTEXT_ANALYSIS_URL,  SearchResultEvent.CONTEXT_ANALYSIS_RESULT, params);		}								//--------------------------------------------------------------------------	    //	    //  Private Methods	    //	    //--------------------------------------------------------------------------						/**		* Internal handling and loading a Search API Call.		* @private		* @param inSendMethod 	The String description of the Method.		* @param dispatchType The Event dispatch type.		* @param params 		Value for passing Param object.		* @param inDepth 		An Array containing: 0 = Search or Caches, 1 = XML Child Depth 1, 2 = XML Child Depth 2.		*/		protected function handleQueryLoading(inSendMethod:String, dispatchType:String, params:SearchParams = null, inDepth:Array = null):void		{						var sendQuery:String = (inSendMethod + "?appid=" + applicationId );			var typeQuery:String;						if(params != null)			{				var paramString:String = params.collect();				sendQuery += ("&"+paramString);			}						 			var queryXMLURLRequest:URLRequest = new URLRequest(sendQuery); 			 			//make the query XML in POST format for potentially long requests 			queryXMLURLRequest.method = URLRequestMethod.POST; 						var queryLoader:URLLoader = new URLLoader(queryXMLURLRequest);			queryLoader.addEventListener(Event.COMPLETE, completeHandler);			queryLoader.addEventListener(IOErrorEvent.IO_ERROR, ioErrorHandler);			queryLoader.addEventListener(Event.OPEN, openHandler);            queryLoader.addEventListener(ProgressEvent.PROGRESS, progressHandler);            queryLoader.addEventListener(SecurityErrorEvent.SECURITY_ERROR, securityErrorHandler);            queryLoader.addEventListener(HTTPStatusEvent.HTTP_STATUS, httpStatusHandler);           	         // XML loading result method		/**		* @private		*/		function completeHandler(event:Event):void			{				//trace("completeHandler: " + event);				var queryXML:XML = new XML(event.currentTarget.data);								if(queryXML.Error == undefined)				{					// Determine if it's a (Search or Cache List) or a WebSearchResult List					if( hasOwnProperty("inDepth") )					{						if(inDepth.length > 0)						{														var resultsArray:Array = [];														if(resultsArray.length > 0)							{								dispatchResult( resultsArray, dispatchType);							}							}											}					else					{						// Format and Dispatch the Normal WebSearchResult Objects						//queryXML = new XML(queryLoader.data);						formatAndDispatch(queryXML, dispatchType);					}									}				else				{					dispatchFault(new ServiceFault(SearchFaultEvent.API_RESPONSE, queryXML.Error, queryXML.Error.Message ));				}			    			}		}										/**		* @private		*/		private function ioErrorHandler(event:IOErrorEvent):void		{		    dispatchFault(new ServiceFault(SearchFaultEvent.XML_LOADING,"The URL could not be found", event.text ));		}			        /**		* @private		*/		private function openHandler(event:Event):void 		{            //trace("openHandler: " + event);        }        /**		* @private		*/		private function progressHandler(event:ProgressEvent):void 		{            //it is not possible to access the data until it has been received completely            //so bytes total = bytes loaded            //trace("progressHandler loaded:" + event.bytesLoaded + " total: " + event.bytesTotal);        }        /**		* @private		*/		private function securityErrorHandler(event:SecurityErrorEvent):void 		{            //trace("securityErrorHandler: " + event);        }		/**		* @private		*/        private function httpStatusHandler(event:HTTPStatusEvent):void 		{            //trace("httpStatusHandler: " + event);        }              		/**		* @private		* Recurse lastResult and transcribe into Search Objects, then dispatch result Event.		* @param inXML			 The XML to transcribe into Objects.		* @param dispatchType The term of the dispatched Event.		*/		protected function formatAndDispatch(inXML:XML, dispatchType:String):void		{		    if(increment == 0) lastResult = [];		    		    var len:int = lastResult.length;		    		    numResultsAvailable = inXML.@totalResultsAvailable;		    numResultsReturned = inXML.@totalResultsReturned;		    numTotalResultsReturned = numResultsReturned + lastResult.length;		    firstResultPosition = inXML.@firstResultPosition;		    lastResultPosition = firstResultPosition + len;		    		    //moreSearchLink = inXML.@moreSearch;		    			var resultsArray:Array = [];		    		    var resultNode:XML;		    		    		    //loop through child nodes and build value objects based on search type		    switch(dispatchType)			{				case SearchResultEvent.LOCAL_SEARCH_RESULT:					for each (resultNode in inXML.children())						{							var localSearchResult:LocalSearchResult = new LocalSearchResult();														// LocalearchResult Properties							//index is the current index in this set of results added to what has already been returned, if anything							localSearchResult.index = resultNode.childIndex() + len;							localSearchResult.name = resultNode.NAMESPACE_LOCAL::Title;							localSearchResult.id = resultNode.@id;														localSearchResult.url = resultNode.NAMESPACE_LOCAL::Url;							localSearchResult.clickURL = resultNode.NAMESPACE_LOCAL::ClickUrl;														localSearchResult.mapURL = resultNode.NAMESPACE_LOCAL::MapUrl;							localSearchResult.businessClickURL = resultNode.NAMESPACE_LOCAL::BusinessClickUrl;							localSearchResult.businessURL = resultNode.NAMESPACE_LOCAL::BusinessUrl;														localSearchResult.address = resultNode.NAMESPACE_LOCAL::Address;							localSearchResult.city = resultNode.NAMESPACE_LOCAL::City;							localSearchResult.state = resultNode.NAMESPACE_LOCAL::State;							localSearchResult.phone = resultNode.NAMESPACE_LOCAL::Phone;														localSearchResult.latitude = resultNode.NAMESPACE_LOCAL::Latitude;							localSearchResult.longitude = resultNode.NAMESPACE_LOCAL::Longitude;							localSearchResult.distance = resultNode.NAMESPACE_LOCAL::Distance;														localSearchResult.rating = new Rating();							localSearchResult.rating.averageRating = resultNode.NAMESPACE_LOCAL::Rating.NAMESPACE_LOCAL::AverageRating;							localSearchResult.rating.numRatings = resultNode.NAMESPACE_LOCAL::Rating.NAMESPACE_LOCAL::TotalRatings;							localSearchResult.rating.numReviews = resultNode.NAMESPACE_LOCAL::Rating.NAMESPACE_LOCAL::TotalReviews;							localSearchResult.rating.summary = resultNode.NAMESPACE_LOCAL::Rating.NAMESPACE_LOCAL::LastReviewIntro;							//convert string to number to date							localSearchResult.rating.lastReviewDate = new Date(resultNode.NAMESPACE_LOCAL::Rating.NAMESPACE_LOCAL::LastReviewDate as Number);														localSearchResult.categories = [];														for each(var l:XML in resultNode.NAMESPACE_LOCAL::Categories.NAMESPACE_LOCAL::Category)							{								var category:Category = new Category();								category.name = l.toString();								category.id = l.@id;																localSearchResult.categories.push(category);							}														// Add the SearchResult Object to our Data Array.							resultsArray.push(localSearchResult);													}									break;								case SearchResultEvent.TERM_EXTRACTION_RESULT:					for each (resultNode in inXML.children())						{							var termExtractionSearchResult:SearchResult = new SearchResult();														// WebSearchResult Properties							//index is the current index in this set of results added to what has already been returned, if anything							termExtractionSearchResult.index = resultNode.childIndex() + len;							termExtractionSearchResult.name = resultNode.toString();														// Add the WebSearchResult Object to our Data Array.							resultsArray.push(termExtractionSearchResult);													}									break;												case SearchResultEvent.CONTEXT_ANALYSIS_RESULT:					for each (resultNode in inXML.children())						{							var contextAnalysisSearchResult:WebSearchResult = new WebSearchResult();														// WebSearchResult Properties							//index is the current index in this set of results added to what has already been returned, if anything							contextAnalysisSearchResult.index = resultNode.childIndex() + len;							contextAnalysisSearchResult.name = resultNode.NAMESPACE_SEARCH::Title;							contextAnalysisSearchResult.summary = resultNode.NAMESPACE_SEARCH::Summary;														contextAnalysisSearchResult.url = resultNode.NAMESPACE_SEARCH::Url;							contextAnalysisSearchResult.clickURL = resultNode.NAMESPACE_SEARCH::ClickUrl;							contextAnalysisSearchResult.displayURL = resultNode.NAMESPACE_SEARCH::DisplayUrl;														contextAnalysisSearchResult.mimeType = resultNode.NAMESPACE_SEARCH::MimeType;														contextAnalysisSearchResult.cache = new Cache(resultNode.NAMESPACE_SEARCH::Cache.NAMESPACE_SEARCH::Url, 								resultNode.NAMESPACE_SEARCH::Cache.NAMESPACE_SEARCH::Size as uint);														//convert string to number to date							contextAnalysisSearchResult.modificationDate = new Date(resultNode.NAMESPACE_SEARCH::ModificationDate as Number);													/* The following are not implemented in the current XML API */							//contextAnalysisSearchResult.category 							//contextAnalysisSearchResult.internalSearchURL "More fromt this site" link														// Add the WebSearchResult Object to our Data Array.							resultsArray.push(contextAnalysisSearchResult);													}									break;								case SearchResultEvent.RELATED_SUGGESTION_RESULT:									    for each (resultNode in inXML.children())					{						var relatedSuggestionSearchResult:SearchResult = new SearchResult();										// SearchResult Properties						relatedSuggestionSearchResult.index = resultNode.childIndex() + len;						relatedSuggestionSearchResult.name = resultNode.toString();																	// Add the SearchResult Object to our Data Array.						resultsArray.push(relatedSuggestionSearchResult);											}				break;								case SearchResultEvent.SPELLING_SUGGESTION_RESULT:									    for each (resultNode in inXML.children())					{						var spellingSearchResult:SearchResult = new SearchResult();									// SearchResult Properties						spellingSearchResult.index = resultNode.childIndex() + len;						spellingSearchResult.name = resultNode.toString();											// Add the SearchResult Object to our Data Array.						resultsArray.push(spellingSearchResult);						

⌨️ 快捷键说明

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