/// <summary> /// Initiate a remote (web) search using the engine incl. search expression specified /// by searchFeedUrl. We assume, the specified Url will return a RSS feed. /// This can be used e.g. to get a RSS search result from feedster. /// </summary> /// <param name="searchFeedUrl">Complete Url of the search engine incl. search expression</param> /// <param name="tag">optional, can be used by the caller</param> public void SearchRemoteFeed(string searchFeedUrl, object tag) { var unreturnedMatchItems = new List <INewsItem>(1); try { unreturnedMatchItems = RssParser.DownloadItemsFromFeed(searchFeedUrl); } catch (Exception remoteSearchException) { unreturnedMatchItems.Add(FeedSource.CreateHelpNewsItemFromException(remoteSearchException)); } int feedmatches = 1; int itemmatches = unreturnedMatchItems.Count; var fi = new FeedInfo(String.Empty, String.Empty, unreturnedMatchItems, String.Empty, String.Empty, String.Empty, new Dictionary <XmlQualifiedName, string>(), String.Empty); var fil = new FeedInfoList(String.Empty) { fi }; RaiseSearchFinishedEvent(tag, fil, feedmatches, itemmatches); }
/// <summary> /// Search for NewsItems, that match a provided criteria collection within a optional search scope. /// </summary> /// <param name="criteria">SearchCriteriaCollection containing the defined search criteria</param> /// <param name="scope">Search scope: an array of NewsFeed</param> /// <param name="tag">optional object to be used by the caller to identify this search</param> /// <param name="cultureName">Name of the culture.</param> /// <param name="returnFullItemText">if set to <c>true</c>, full item texts are returned instead of the summery.</param> public void SearchNewsItems(SearchCriteriaCollection criteria, INewsFeed[] scope, object tag, string cultureName, bool returnFullItemText) { // if scope is an empty array: search all, else search only in spec. feeds int feedmatches = 0; int itemmatches = 0; IList <INewsItem> unreturnedMatchItems = new List <INewsItem>(); var fiList = new FeedInfoList(String.Empty); Exception ex; bool valid = SearchHandler.ValidateSearchCriteria(criteria, cultureName, out ex); if (ex != null) // report always any error (warnings) { // render the error in-line (search result): fiList.Add(FeedSource.CreateHelpNewsItemFromException(ex).FeedDetails); feedmatches = fiList.Count; unreturnedMatchItems = fiList.GetAllNewsItems(); itemmatches = unreturnedMatchItems.Count; } if (valid) { try { // do the search (using lucene): LuceneSearch.Result r = SearchHandler.ExecuteSearch(criteria, scope, this.Sources.Select(entry => entry.Source), cultureName); // we iterate r.ItemsMatched to build a // NewsItemIdentifier and ArrayList list with items, that // match the read status (if this was a search criteria) // then call FindNewsItems(NewsItemIdentifier[]) to get also // the FeedInfoList. // Raise ONE event, instead of two to return all (counters, lists) SearchCriteriaProperty criteriaProperty = null; foreach (ISearchCriteria sc in criteria) { criteriaProperty = sc as SearchCriteriaProperty; if (criteriaProperty != null && PropertyExpressionKind.Unread == criteriaProperty.WhatKind) { break; } } ItemReadState readState = ItemReadState.Ignore; if (criteriaProperty != null) { readState = criteriaProperty.BeenRead ? ItemReadState.BeenRead : ItemReadState.Unread; } if (r != null && r.ItemMatchCount > 0) { /* append results */ var nids = new SearchHitNewsItem[r.ItemsMatched.Count]; r.ItemsMatched.CopyTo(nids, 0); //look in every feed source to find source feed for matching news items IEnumerable <FeedInfoList> results = Sources.Select(entry => entry.Source.FindNewsItems(nids, readState, returnFullItemText)); foreach (FeedInfoList fil in results) { fiList.AddRange(fil); } feedmatches = fiList.Count; unreturnedMatchItems = fiList.GetAllNewsItems(); itemmatches = unreturnedMatchItems.Count; } } catch (Exception searchEx) { // render the error in-line (search result): fiList.Add(FeedSource.CreateHelpNewsItemFromException(searchEx).FeedDetails); feedmatches = fiList.Count; unreturnedMatchItems = fiList.GetAllNewsItems(); itemmatches = unreturnedMatchItems.Count; } } RaiseSearchFinishedEvent(tag, fiList, unreturnedMatchItems, feedmatches, itemmatches); }