如何通过List <int>在Azure搜索中添加包含逻辑

问题描述

   {
            "@search.score": 1,"id": "1","FullName": "Adam","UserName": "Adam1903","Isverified": true,"PartitionKey": "32fbq","IsSearchableuser": true
        }

那是我关于azure搜索索引的文档...我有collection List followedUsers = new List(){1,3}; ...我想在azure搜索中实现的目标是这样的... >

Select * from User where Id is in(1,2,3)

解决方法

您可以将所有搜索结果检索到List 中,并使用以下代码按数组列表中的ID进行过滤。

var s = new List<Search>();
var exceptions = new int[] {1,2,3};
var filtered = s.Where(x=> exceptions.Contains(x.id));

更新:

如果您想使用SearchParameters.SearchFields属性来查询对特定字段的参数挂钩搜索,则可以使用以下代码来查询特定的ID字段。

parameters = new SearchParameters()
{
    SearchFields = new[] { "id" }
};
results = indexClient.Documents.Search<Hotel>("1",parameters);