Esempio n. 1
0
		void IBlogRssComponentTagFilter.InitFilter(string siteId, string tags, List<int> ids, bool exclude, int categoryId)
		{
			if (ids.Count == 0 && !exclude)
			{
				empty = true;
				return;
			}

			q = new BXSearchQuery();
			q.SiteId = siteId;
			q.LanguageId = string.Empty;
			q.FieldsToSelect.Add(BXSearchField.ItemId);

			BXSearchContentGroupFilter f = new BXSearchContentGroupFilter(BXFilterExpressionCombiningLogic.And);
			
			//discrete timestep for count caching
			DateTime now = DateTime.Now;
			DateTime nowFloor = new DateTime(now.Year, now.Month, now.Day, now.Hour, now.Minute / 5 * 5, 0);
			f.Add(BXSearchContentFilter.IsActive(nowFloor));

			f.Add(new BXSearchContentFilterItem(BXSearchField.ModuleId, BXSqlFilterOperators.Equal, "blog"));


			List<int> ids2 = null;
			if (categoryId > 0)
			{
				ids2 = BXBlog.GetList(
					new BXFilter(new BXFilterItem(BXBlog.Fields.Categories.CategoryId, BXSqlFilterOperators.Equal, categoryId)),
					null,
					new BXSelect(BXBlog.Fields.Id),
					null
				)
				.ConvertAll(x => x.Id);
			}

			if (ids2 != null)
			{
				if (ids2.Count == 0)
					ids = ids2;									
				if (exclude)
				{
					if (ids.Count == 0)
						ids = ids2;
					else 
						ids = Bitrix.DataTypes.BXSet.Difference(ids2, ids);
				}
				else
					ids = Bitrix.DataTypes.BXSet.Intersection(ids2, ids);

				exclude = false;

				if (ids.Count == 0)
				{
					empty = true;
					return;
				}
			}


			if (!exclude || ids.Count > 0)
			{
				BXSearchContentFilter scf = new BXSearchContentFilterItem(BXSearchField.ItemGroup, Bitrix.DataLayer.BXSqlFilterOperators.In, ids.ConvertAll(x => x.ToString()).ToArray());
				if (exclude)
					scf = new BXSearchContentNotFilter(scf);
				f.Add(scf);
			}

			q.Filter = f;

			q.CalculateRelevance = false;
			q.AddTags(tags, ',');
            q.OrderBy = new BXSearchOrderBy(
                new BXSearchOrderByPair(BXSearchField.DateFrom, BXOrderByDirection.Desc),
                new BXSearchOrderByPair(BXSearchField.ContentDate, BXOrderByDirection.Desc),
                new BXSearchOrderByPair(BXSearchField.Id, BXOrderByDirection.Asc)
            ); 
		}
Esempio n. 2
0
		void IBlogPostsComponentTagFilter.InitFilter(string siteId, string tags, string blogSlugs, List<int> ids, bool exclude, int categoryId)
		{
			if (ids != null && ids.Count == 0 && exclude)
				ids = null;

			if (ids != null && ids.Count == 0 && !exclude)
			{
				empty = true;
				return;
			}


			q = new BXSearchQuery();
			q.SiteId = siteId;
			q.LanguageId = "";
			q.FieldsToSelect.Add(BXSearchField.ItemId);

			BXSearchContentGroupFilter f = new BXSearchContentGroupFilter(BXFilterExpressionCombiningLogic.And);
			//discrete timestep for count caching
			DateTime now = DateTime.Now;
			//DateTime nowFloor = new DateTime(now.Year, now.Month, now.Day, now.Hour, now.Minute / 5 * 5, 0);
			f.Add(BXSearchContentFilter.IsActive(now.AddMinutes(5 - (now.Minute % 5)).AddSeconds(-now.Second).AddMilliseconds(-now.Millisecond)));
			f.Add(new BXSearchContentFilterItem(BXSearchField.ModuleId, BXSqlFilterOperators.Equal, "blog"));

			BXFilter bf = null;

			if (!string.IsNullOrEmpty(blogSlugs))
			{
				string[] blogSlugArr = blogSlugs.Split(new char[] { ',' }, StringSplitOptions.RemoveEmptyEntries);
				if (blogSlugArr.Length > 0)
				{
					for (int i = 0; i < blogSlugArr.Length; i++)
						blogSlugArr[i] = blogSlugArr[i].Trim();

					bf = new BXFilter(new BXFilterItem(BXBlog.Fields.Slug, BXSqlFilterOperators.In, blogSlugArr));
				}
			}

			if (categoryId > 0)
			{
				if (bf == null)
					bf = new BXFilter();
				bf.Add(new BXFilterItem(BXBlog.Fields.Categories.CategoryId, BXSqlFilterOperators.Equal, categoryId));
			}

			List<int> blogIdLst = null;
			if (bf != null)
			{
				BXBlogCollection blogs = BXBlog.GetList(
					bf,
					null,
					new BXSelect(BXSelectFieldPreparationMode.Normal, BXBlog.Fields.Id),
					null
				);
				blogIdLst = blogs.ConvertAll(x => x.Id);
			}

			if (blogIdLst != null)
			{
				if (ids != null)
				{
					if (exclude)
					{
						ids = Bitrix.DataTypes.BXSet.Difference(blogIdLst, ids);
						exclude = false;
					}
					else
					{
						ids = Bitrix.DataTypes.BXSet.Intersection(blogIdLst, ids);
					}
				}
				else
				{
					ids = blogIdLst;
					exclude = false;
				}				
			}			
			
			if (ids != null && ids.Count == 0 && !exclude)
			{
				empty = true;
				return;
			}

			if (ids != null)
			{
				BXSearchContentFilter scf = new BXSearchContentFilterItem(BXSearchField.ItemGroup, Bitrix.DataLayer.BXSqlFilterOperators.In, ids.ConvertAll(x => x.ToString()).ToArray());
				if (exclude)
					scf = new BXSearchContentNotFilter(scf);
				f.Add(scf);
			}
			

			q.Filter = f;
			q.CalculateRelevance = false;
			q.AddTags(tags, ',');

			q.OrderBy = new BXSearchOrderBy(
				new BXSearchOrderByPair(BXSearchField.DateFrom, BXOrderByDirection.Desc),
				new BXSearchOrderByPair(BXSearchField.ContentDate, BXOrderByDirection.Desc),
				new BXSearchOrderByPair(BXSearchField.Id, BXOrderByDirection.Asc)
			 );
		}