当前位置: 首页>>代码示例>>C#>>正文


C# Filter.Bool方法代码示例

本文整理汇总了C#中Filter.Bool方法的典型用法代码示例。如果您正苦于以下问题:C# Filter.Bool方法的具体用法?C# Filter.Bool怎么用?C# Filter.Bool使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在Filter的用法示例。


在下文中一共展示了Filter.Bool方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。

示例1: AddFacetQueries

        /// <summary>
        /// Adds the facet queries.
        /// </summary>
        /// <param name="param">The param.</param>
        /// <param name="fieldName">Name of the field.</param>
        /// <param name="values">The values.</param>
        private void AddFacetQueries(Facets<ESDocument> param, string fieldName, IEnumerable<RangeFilterValue> values, ISearchCriteria criteria)
        {
            if (values == null)
                return;

            var ffilter = new Filter<ESDocument>();
            foreach (var f in criteria.CurrentFilters)
            {
                if (!f.Key.Equals(fieldName))
                {
                    var q = ElasticQueryHelper.CreateQuery(criteria, f);
                    ffilter.Bool(ff => q);
                }
            }

            foreach (var value in values)
            {
                var filter = new FacetFilter<ESDocument>();
                filter.Range(r => r.IncludeLower(false).IncludeUpper().From(value.Lower).To(value.Upper));
                filter.And(b => ffilter);
                param.FilterFacets(ff => ff.FacetName(String.Format("{0}-{1}", fieldName, value.Id)).Filter(f => filter));
            }
        }
开发者ID:rdi-drew,项目名称:vc-community,代码行数:29,代码来源:ElasticSearchQueryBuilder.cs

示例2: BuildQuery

        public object BuildQuery(ISearchCriteria criteria)
        {
            var builder = new QueryBuilder<ESDocument>();
            var mainFilter = new Filter<ESDocument>();
            var mainQuery = new BoolQuery<ESDocument>();

            #region Sorting

            // Add sort order
            if (criteria.Sort != null)
            {
                var fields = criteria.Sort.GetSort();
                foreach (var field in fields)
                {
                    builder.Sort(d => d.Field(field.FieldName, field.IsDescending ? SortDirection.desc : SortDirection.asc, ignoreUnmapped: field.IgnoredUnmapped));
                }
            }

            #endregion

            #region Filters
            // Perform facet filters
            if (criteria.CurrentFilters != null)
            {
                var combinedFilter = new BoolFilter<ESDocument>();
                // group filters
                foreach (var filter in criteria.CurrentFilters)
                {
                    // Skip currencies that are not part of the filter
                    if (filter.GetType() == typeof(PriceRangeFilter)) // special filtering 
                    {
	                    var priceRangeFilter = filter as PriceRangeFilter;
	                    if (priceRangeFilter != null)
	                    {
		                    var currency = priceRangeFilter.Currency;
		                    if (!currency.Equals(criteria.Currency, StringComparison.OrdinalIgnoreCase))
			                    continue;
	                    }
                    }

                    var filterQuery = ElasticQueryHelper.CreateQuery(criteria, filter);

                    if (filterQuery != null)
                    {
                        combinedFilter.Must(c => c.Bool(q=>filterQuery));
                    }
                }

                mainFilter.Bool(bl => combinedFilter);
            }
            #endregion

            #region CatalogItemSearchCriteria
            if (criteria is CatalogItemSearchCriteria)
            {
                var c = criteria as CatalogItemSearchCriteria;

                mainQuery.Must(m => m
                    .Range(r => r.Field("startdate").To(c.StartDate.ToString("s")))
					);


                if (c.StartDateFrom.HasValue)
                {
                    mainQuery.Must(m => m
                        .Range(r => r.Field("startdate").From(c.StartDateFrom.Value.ToString("s")))
                   );
                }

				if (c.EndDate.HasValue)
				{
					mainQuery.Must(m => m
						.Range(r => r.Field("enddate").From(c.EndDate.Value.ToString("s")))
				   );
				}

				mainQuery.Must(m => m.Term(t => t.Field("__hidden").Value("false")));

                if (c.Outlines != null && c.Outlines.Count > 0)
                    AddQuery("__outline", mainQuery, c.Outlines);

                if (!String.IsNullOrEmpty(c.SearchPhrase))
                {
					AddQueryString("__content", mainQuery, c);
                }

				if (!String.IsNullOrEmpty(c.Catalog))
				{
					AddQuery("catalog", mainQuery, c.Catalog);
				}
            }
            #endregion

            if (criteria is ElasticSearchCriteria)
            {
                var c = criteria as ElasticSearchCriteria;
                mainQuery.Must(m => m.Custom(c.RawQuery));
            }

            builder.Query(q => q.Bool(b => mainQuery));
//.........这里部分代码省略.........
开发者ID:rdi-drew,项目名称:vc-community,代码行数:101,代码来源:ElasticSearchQueryBuilder.cs


注:本文中的Filter.Bool方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。