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


C# QueryBuilder.Build方法代码示例

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


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

示例1: SearchByKeyword

        public PagedResponse<ProductDoc> SearchByKeyword(PagedRequest<ProductSearchRequest> request)
        {
            //QueryContainer filter = null;
            var matchFields = new string[] { "name^20", "description^5", "instruction" };
            //var categoryLevelMatch = request.Data.FilterCategoryLevel.HasValue ? request.Data.FilterCategoryLevel == 1 ? "categoryLevel1" : request.Data.FilterCategoryLevel == 2 ? "categoryLevel2" : "categoryLevel3" : "categoryLevel3";
            var categoryLevelMatch = "categoryLevel3";
            var query = new QueryBuilder()
                .AndMultiMatch(matchFields, request.Data.Keyword)
                .Build();

            var filterBuilder = new QueryBuilder();
            foreach (var c in request.Data.CategoryName)
            {
                filterBuilder = filterBuilder.OrMatch(categoryLevelMatch, request.Data.CategoryName);
            }
                
            foreach (var bname in request.Data.BrandName)
            {
                filterBuilder = filterBuilder.OrMatch("brandName", bname);
            }
            foreach (var t in request.Data.Tag)
            {
                filterBuilder = filterBuilder.OrMatch("tags", t);
            }
            var filter = filterBuilder.Build();
            //var query = new QueryBuilder()
            //    .OrMultiMatch(matchFields, request.Data.Keyword)
            //    //.AndMatch("brandName", request.Data.BrandName)
            //    .AndMatch(categoryLevelMatch, request.Data.CategoryName)
            //    .Build();
            AggregationContainerDescriptor<ProductDoc> categoryAgg = null;
            if (request.Data.NeedAggregation)
            {
                categoryAgg = new AggregationContainerDescriptor<ProductDoc>()
                .Terms("agg_brand", f => f.Field("brandName"))
                .Terms("agg_category_level_3", f => f.Field("categoryLevel3"))
                .Terms("agg_tag", f => f.Field("tags"));
            }            
            
            //switch (request.Data.FilterCategoryLevel)
            //{                
            //    case 1:
            //        categoryAgg.Terms("agg_category_level_1", f => f.Field("categoryLevel1"));
            //        break;
            //    case 2:
            //        categoryAgg.Terms("agg_category_level_2", f => f.Field("categoryLevel2"));
            //        break;
            //    default:
            //    case 3:
            //        categoryAgg.Terms("agg_category_level_3", f => f.Field("categoryLevel3"));
            //        break;
            //}
                
            var result = Client.SetPageNum(request.PageNumber).SetPageSize(request.PageSize).SearchResponse(query, filter, a => categoryAgg);
            return Client.WrapResult(result);
        }
开发者ID:GBmono,项目名称:GBmonoV1.0,代码行数:56,代码来源:ProductHelper.cs


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