public int[] SearchByTags(IDataLayer fabricConnection, string searchQuery) { if (StringHlp.IsEmpty(searchQuery)) { return(new int[0]); } searchQuery = searchQuery.ToLower(); string[] words = searchQuery.Split(new char[] { ' ', ',', '-' }, StringSplitOptions.RemoveEmptyEntries); if (words.Length == 0) { return(new int[0]); } //IEnumerable<int> tagIds = DictionaryHlp.GetValueOrDefault(tagIdsByWord, words[0]); //if (tagIds == null) // return new int[0]; IEnumerable <int> intersectTagIds = null; foreach (string word in words) { IEnumerable <int> tagIds = DictionaryHlp.GetValueOrDefault(tagIdsByWord, word); if (tagIds == null) { return(new int[0]); } if (intersectTagIds == null) { intersectTagIds = tagIds; } else { intersectTagIds = intersectTagIds.Intersect(tagIds); } } List <Tuple <int, int> > tagIdsWithNewsCount = new List <Tuple <int, int> >(); foreach (int tagId in intersectTagIds) { int[] newsIds = ViewTagHlp.GetNewsIdsForTag(fabricConnection, tagId); if (newsIds.Length > 0) { tagIdsWithNewsCount.Add(new Tuple <int, int>(tagId, newsIds.Length)); } } return(_.SortBy(tagIdsWithNewsCount, delegate(Tuple <int, int> tag) { return tag.Item2; }).Select(ti => ti.Item1).Reverse().ToArray()); }
public static IHtmlControl GetTagView(SiteState state, LightObject currentUser, int?tagId, int pageNumber, out string title, out string description) { title = ""; description = ""; if (tagId == null) { return(null); } RowLink tagRow = context.Tags.TagBox.ObjectById.AnyRow(tagId.Value); if (tagRow == null) { return(null); } string tagDisplay = TagType.DisplayName.Get(tagRow); title = string.Format("{0} - все новости на basketball.ru.com", tagDisplay); description = string.Format("{0} - все новости. Живое обсуждение баскетбольных событий на basketball.ru.com", tagDisplay); int[] newsIds = ViewTagHlp.GetNewsIdsForTag(context.FabricConnection, tagId.Value); IHtmlControl[] items = GetNewsItems(state, newsIds, pageNumber); if (items == null) { return(null); } string urlWithoutPageIndex = string.Format("/tags?tag={0}", tagId.Value); return(new HPanel( Decor.Title(tagDisplay), //.Color(Decor.subtitleColor), //Decor.Subtitle(string.Format("Тег — {0}", tagDisplay)).MarginTop(5), new HPanel( new HPanel( items ), ViewJumpHlp.JumpBar(urlWithoutPageIndex, newsIds.Length, newsCountOnPage, pageNumber) ) )); }