Esempio n. 1
0
        public void SearchDialogSetSearchCriterias(FinderNode node)
        {
            if (node == null)
            {
                return;
            }

            SearchCriteriaCollection criterias = node.Finder.SearchCriterias;
            string searchName = node.Finder.FullPath;

            ResetControlState();

            Queue itemAgeCriterias = new Queue(2);

            foreach (ISearchCriteria criteria in criterias)
            {
                SearchCriteriaString str = criteria as SearchCriteriaString;
                if (str != null)
                {
                    SearchStringElement where = str.Where;
                    if ((where & SearchStringElement.Title) == SearchStringElement.Title)
                    {
                        checkBoxRssSearchInTitle.Checked = true;
                    }
                    else
                    {
                        checkBoxRssSearchInTitle.Checked = false;
                    }

                    if ((where & SearchStringElement.Content) == SearchStringElement.Content)
                    {
                        checkBoxRssSearchInDesc.Checked = true;
                    }
                    else
                    {
                        checkBoxRssSearchInDesc.Checked = false;
                    }

                    if ((where & SearchStringElement.Subject) == SearchStringElement.Subject)
                    {
                        checkBoxRssSearchInCategory.Checked = true;
                    }
                    else
                    {
                        checkBoxRssSearchInCategory.Checked = false;
                    }

                    if ((where & SearchStringElement.Link) == SearchStringElement.Link)
                    {
                        checkBoxRssSearchInLink.Checked = true;
                    }
                    else
                    {
                        checkBoxRssSearchInLink.Checked = false;
                    }

                    SearchFieldsGroupExpanded = true;

//					if (str.WhatKind == StringExpressionKind.Text)
//						radioRssSearchSimpleText.Checked = true;
//					else if (str.WhatKind == StringExpressionKind.RegularExpression)
//						radioRssSearchRegEx.Checked = true;
//					else if (str.WhatKind == StringExpressionKind.XPathExpression)
//						radioRssSearchExprXPath.Checked = true;
//
//					if (!radioRssSearchSimpleText.Checked)
//						this.collapsiblePanelRssSearchExprKindEx.Collapsed = false;

                    textSearchExpression.Text = str.What;
                }

                SearchCriteriaProperty prop = criteria as SearchCriteriaProperty;
                if (prop != null)
                {
                    if (prop.WhatKind == PropertyExpressionKind.Unread)
                    {
                        if (!prop.BeenRead)
                        {
                            checkBoxRssSearchUnreadItems.Checked = true;
                        }
                        else
                        {
                            checkBoxRssSearchUnreadItems.Checked = false;
                        }
                    }
                    IsAdvancedOptionReadStatusActive = true;
                    AdvancedOptionsGroupExpanded     = true;
                }

                SearchCriteriaAge age = criteria as SearchCriteriaAge;
                if (age != null)
                {
                    if (age.WhatRelativeToToday.CompareTo(TimeSpan.Zero) != 0)
                    {
                        // relative item age specified
                        IsAdvancedOptionItemAgeActive = true;
                        if (age.WhatKind == DateExpressionKind.NewerThan)
                        {
                            this.optionSetItemAge.CheckedIndex = 0;
                        }
                        else
                        {
                            this.optionSetItemAge.CheckedIndex = 1;
                        }
                        this.comboRssSearchItemAge.SelectedIndex = Utils.RssSearchItemAgeToIndex(age.WhatRelativeToToday);
                    }
                    else
                    {
                        // absolute item age or range specified, queue for later handling
                        itemAgeCriterias.Enqueue(age);
                    }

                    if (!AdvancedOptionsGroupExpanded)
                    {
                        AdvancedOptionsGroupExpanded = true;
                    }
                }
            }

            if (itemAgeCriterias.Count > 0)
            {
                // absolute date specified

                IsAdvancedOptionItemPostedActive = true;
                SearchCriteriaAge ageAbs = (SearchCriteriaAge)itemAgeCriterias.Dequeue();
                if (ageAbs.WhatKind == DateExpressionKind.Equal)
                {
                    this.comboBoxRssSearchItemPostedOperator.SelectedIndex = 0;
                }
                else if (ageAbs.WhatKind == DateExpressionKind.OlderThan)
                {
                    this.comboBoxRssSearchItemPostedOperator.SelectedIndex = 1;
                }
                else if (ageAbs.WhatKind == DateExpressionKind.NewerThan)
                {
                    this.comboBoxRssSearchItemPostedOperator.SelectedIndex = 2;
                }
                else                    // between (range):
                {
                    this.comboBoxRssSearchItemPostedOperator.SelectedIndex = 3;
                }
                this.dateTimeRssSearchItemPost.Value = ageAbs.What;

                if (itemAgeCriterias.Count > 1)
                {
                    // range specified
                    SearchCriteriaAge ageFrom = (SearchCriteriaAge)itemAgeCriterias.Dequeue();
                    SearchCriteriaAge ageTo   = (SearchCriteriaAge)itemAgeCriterias.Dequeue();
                    this.dateTimeRssSearchItemPost.Value   = ageFrom.What;
                    this.dateTimeRssSearchPostBefore.Value = ageTo.What;
                }
            }

            itemAgeCriterias.Clear();

            if (!node.IsTempFinderNode)
            {
                textFinderCaption.Text = searchName;
            }

            if (textFinderCaption.Text.Length > 0)
            {
                SaveSearchGroupExpanded = true;
            }

            PopulateTreeRssSearchScope();               // init, all checked. Common case

            if (this.treeRssSearchScope.Nodes.Count == 0 ||
                (node.Finder.CategoryPathScope == null || node.Finder.CategoryPathScope.Count == 0) &&
                (node.Finder.FeedUrlScope == null || node.Finder.FeedUrlScope.Count == 0))
            {
                return;
            }

            this.treeRssSearchScope.Nodes[0].Checked = false;                   // uncheck all.
            TreeHelper.CheckChildNodes(this.treeRssSearchScope.Nodes[0], false);

            TreeHelper.SetCheckedNodes(this.treeRssSearchScope.Nodes[0],
                                       node.Finder.CategoryPathScope, node.Finder.FeedUrlScope);
        }
Esempio n. 2
0
        /// <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);
        }
Esempio n. 3
0
        private SearchCriteriaCollection SearchDialogGetSearchCriterias()
        {
            SearchCriteriaCollection sc = new SearchCriteriaCollection();

            SearchStringElement where = SearchStringElement.Undefined;
            if (textSearchExpression.Text.Length > 0)
            {
                if (checkBoxRssSearchInTitle.Checked)
                {
                    where |= SearchStringElement.Title;
                }
                if (checkBoxRssSearchInDesc.Checked)
                {
                    where |= SearchStringElement.Content;
                }
                if (checkBoxRssSearchInCategory.Checked)
                {
                    where |= SearchStringElement.Subject;
                }
                if (checkBoxRssSearchInLink.Checked)
                {
                    where |= SearchStringElement.Link;
                }
            }

            StringExpressionKind kind = StringExpressionKind.LuceneExpression;
//			if (radioRssSearchSimpleText.Checked)
//				kind = StringExpressionKind.Text;
//			else if (radioRssSearchRegEx.Checked)
//				kind = StringExpressionKind.RegularExpression;
//			else if (radioRssSearchExprXPath.Checked)
//				kind = StringExpressionKind.XPathExpression;

            SearchCriteriaString scs = new SearchCriteriaString(textSearchExpression.Text, where, kind);

            sc.Add(scs);

            if (this.IsAdvancedOptionReadStatusActive)
            {
                SearchCriteriaProperty scp = new SearchCriteriaProperty();
                scp.BeenRead = !checkBoxRssSearchUnreadItems.Checked;
                scp.WhatKind = PropertyExpressionKind.Unread;
                sc.Add(scp);
            }

            if (this.IsAdvancedOptionItemAgeActive)
            {
                SearchCriteriaAge sca = new SearchCriteriaAge();
                if (this.optionSetItemAge.CheckedIndex == 0)
                {
                    sca.WhatKind = DateExpressionKind.NewerThan;
                }
                else
                {
                    sca.WhatKind = DateExpressionKind.OlderThan;
                }
                sca.WhatRelativeToToday = Utils.RssSearchItemAgeToTimeSpan(this.comboRssSearchItemAge.SelectedIndex);
                sc.Add(sca);
            }

            if (this.IsAdvancedOptionItemPostedActive)
            {
                if (comboBoxRssSearchItemPostedOperator.SelectedIndex == 0)
                {
                    sc.Add(new SearchCriteriaAge(dateTimeRssSearchItemPost.Value, DateExpressionKind.Equal));
                }
                else if (comboBoxRssSearchItemPostedOperator.SelectedIndex == 1)
                {
                    sc.Add(new SearchCriteriaAge(dateTimeRssSearchItemPost.Value, DateExpressionKind.OlderThan));
                }
                else if (comboBoxRssSearchItemPostedOperator.SelectedIndex == 2)
                {
                    sc.Add(new SearchCriteriaAge(dateTimeRssSearchItemPost.Value, DateExpressionKind.NewerThan));
                }
                else
                {
                    // handle case: either one date is greater than the other or equal
                    if (dateTimeRssSearchItemPost.Value > dateTimeRssSearchPostBefore.Value)
                    {
                        sc.Add(new SearchCriteriaDateRange(dateTimeRssSearchPostBefore.Value, dateTimeRssSearchItemPost.Value));
                    }
                    else if (dateTimeRssSearchItemPost.Value < dateTimeRssSearchPostBefore.Value)
                    {
                        sc.Add(new SearchCriteriaDateRange(dateTimeRssSearchItemPost.Value, dateTimeRssSearchPostBefore.Value));
                    }
                    else
                    {
                        sc.Add(new SearchCriteriaAge(dateTimeRssSearchPostBefore.Value, DateExpressionKind.Equal));
                    }
                }
            }

            return(sc);
        }