c# - Azure 搜索 - 较小的方面计数未从索引返回

标签 c# asp.net azure azure-cognitive-search

我正在使用 Azure 搜索索引来创建产品的分面搜索。我有大约 5 个方面来帮助过滤显示的产品列表。

我注意到的一件事是,如果列出了相当多的产品以使用构面进行过滤,则属于构面内的较小搜索项不会从索引中返回。

例如(简单来说),如果我的索引在某个方面列​​出了以下汽车制造商:

  • 奥迪 (312)
  • 宝马 (203)
  • 沃尔沃 (198)
  • 斯柯达(4)

我发现斯柯达不会被返回,因为链接到该制造商的搜索结果很少。

当我使用以下查询直接在 Azure 门户中搜索索引时,我可以看到这种情况:facet=<facet-field-name>

经过一番研究,我发现了以下内容 explanation :

Facet counts can be inaccurate due to the sharding architecture. Every search index has multiple shards, and each shard reports the top N facets by document count, which is then combined into a single result. If some shards have many matching values, while others have fewer, you may find that some facet values are missing or under-counted in the results.

Although this behavior could change at any time, if you encounter this behavior today, you can work around it by artificially inflating the count: to a large number to enforce full reporting from each shard. If the value of count: is greater than or equal to the number of unique values in the field, you are guaranteed accurate results. However, when document counts are high, there is a performance penalty, so use this option judiciously.

根据上面的引用,我如何人为地增加计数来解决这个问题?或者有人知道更好的方法吗?

最佳答案

默认构面计数为 10。您可以使用 count 参数作为构面表达式的一部分来指定更大的计数。例如,假设您使用带有 HTTP GET 请求的 REST API:

facet=myfield,count:100

如果您使用的是 .NET SDK:

var parameters =
    new SearchParameters()
    {
        Facets = new[] { "myfield,count:100" }
    };

var results = indexClient.Documents.Search("*", parameters);

您可以在 Azure Search REST API Reference 中找到有关构面表达式语法的更多详细信息。 .

关于c# - Azure 搜索 - 较小的方面计数未从索引返回,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/47500715/

相关文章:

c# - 无法删除 ListView 中显示的图像文件

c# - 带有文本按钮的 WinForms 消息框

asp.net - 如何在 ASP.NET 中隐藏页面名称和查询字符串?

.net - 我应该在生产环境中使用 'Integrated Security=True' 吗?

c# - 正则表达式匹配所有除非?

javascript - 使用 Node js 和 electron 上传图片。 (从 C# 代码转换)

asp.net - ValidationSummary 样式在 Post asp.net 的 IE 6 中不显示

azure - 将具有专用终结点的 Azure 数据工厂连接到具有同一 VNet 中的另一个专用终结点的存储帐户

azure - 无法添加 Azure DB 防火墙规则以允许构建服务器运行测试

c# - 使用 Azure Functions 调用 REST API 并将结果保存在 Azure Data Lake gen2 中