[英]Azure Search: price range - min & max value calculation
Currently, I am trying out Azure Search SDK. 目前,我正在尝试Azure Search SDK。 Having a strong background working with lucene and bobobrowse , the Azure Search is quite fantastic and has a lot of features from both frameworks out of the box.
Azure搜索具有强大的背景和lucene和bobobrowse ,非常棒,并且具有开箱即用的两个框架的许多功能。
The only thing I am puzzling with is to get the minimum and maximum value of a numeric facet item. 我唯一感到困惑的是获得数字小平面项的最小值和最大值。 By intention, I do not want to use the interval parameter nor the value lists :
按意图,我不想使用interval参数也不想使用值列表 :
My requirement is to display the price facet with a calculated minimum and maximum value. 我的要求是用计算出的最小值和最大值显示价格方面。 Following website has such a facet in their facet list:
以下网站在其方面列表中有这样一个方面:
In my existing desktop application (.Net) I successfully used BoboBrowse framework and implemented a Custom-FacetHandler to get the desired results which are shown in the following picture below: 在我现有的桌面应用程序(.Net)中,我成功使用了BoboBrowse框架并实现了Custom-FacetHandler以获得所需的结果,如下图所示:
Never mind the facet values within these pictures. 别介意这些图片中的方面值。 These are just length, height and other characteristic values of tools.
这些只是工具的长度,高度和其他特征值。
This is how I build one document for demonstration purposes. 这是我为演示目的构建一个文档的方法。 There is a price field which is generated dynamically.
有一个动态生成的价格字段。 Because of azure search needs a strongly fixed schema for every index.
由于azure搜索需要每个索引的强固定模式。 I update the schema within the indexing process.
我在索引过程中更新架构。 This works very well.
这非常有效。
So the question is how can i achieve the required functionality with azure search? 所以问题是如何通过azure搜索实现所需的功能?
In the elastic search, such a problem could be solved by using Aggregations . 在弹性搜索中,可以通过使用聚合来解决这样的问题。 Does this feature exist in Azure Search?
Azure搜索中是否存在此功能?
The $filter
parameter supports the lt
(less than) and gt
(greater than) operators. $filter
参数支持lt
(小于)和gt
(大于)运算符。 For example: $filter=price gt 0 and price lt < 100
例如:
$filter=price gt 0 and price lt < 100
Sample code: 示例代码:
string PriceFilter(double? fromPrice, double? toPrice)
{
var filter = "$filter=";
if(fromPrice.HasValue)
filter+="price gt " + fromPrice.Value.ToString()
+ (toPrice.HasValue ? " and " : "");
if(toPrice.HasValue)
filter+="price lt " + toPrice.Value.ToString();
return filter;
}
Reference: Build a filter for a range 参考: 为范围构建过滤器
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.