我有三个过滤器,即类别、子类别和产品类型,它们需要应用于搜索查询。我目前正在使用Azure Search.As of now,我使用的是odata过滤器,如下面的代码所示。
SearchParameters parameters = new SearchParameters();
string searchText = Request.Query["query"];
string category = Request.Query["c"];
string subCategory = Request.Query["sc"];
string productType = Request.Query["pt"];
parameters.Filter = $"Category/Id eq '{category}' or SubCategory/Id eq '{subCategory}'" +
$"or ProductType/Id eq '{productType}'";
如何获得这样的结果:如果用户应用categoryId,那么它应该显示与该类别Id.If有关的结果--用户同时应用categoryId和subcategoryId,他应该能够看到与指定的筛选器类别匹配的两个产品,并且subcategory.If只提交producttypeId,然后他应该能够看到与该producttypeId相关的产品。当然,我可以使用if和else,并使用“逻辑或”和“逻辑和”构建我的过滤器。是否有任何Odata库能在这方面帮助我?
发布于 2020-03-02 22:40:41
谢谢你的建议,我用OData FilterString找到了解决这个问题的方法
string filterquery = FilterString.Generate<Product>(p => p.Category.Id == category &&
p.SubCategory.Id == subCategory &&
p.ProductType.Id == productType);
parameters.Filter = filterQuery;
https://stackoverflow.com/questions/60489762
复制