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