包含 / 在 Azure 搜索中的数组中(预览版)
Contains / in array in Azure Search (Preview)
我正在使用新的(预览版)Azure 搜索 SDK (information here)。我正在使用 oData 表达式语法通过 $filter
参数构建我的搜索查询,我希望能够将一组 id 提供给端点。 brandId 字段在我的 Azure 搜索索引中,它是可搜索、可筛选、可排序和分面的。理想情况下,我希望能够按照以下方式做一些事情:
http://host/service/Products?brands=["1","2"]
(标题为 "Complex and Collection Literals" 的部分下的See specification here)
我不知道要使用什么语法来将 collection 文字语法包含在 $filter
查询中。所以我目前只是将逻辑 OR
的负载串联起来形成查询,而不是理想的查询:
var sp = new SearchParameters();
string filter = "$filter=";
if(brands.Length > 0)
{
int counter = 0;
foreach(string brand in brands)
{
if(counter == 0)
{
filter += "(brandId eq '" + brand + "'";
}
else if(counter == (brands.Count() - 1))
{
filter += " or brandId eq '" + brand + "')";
}
else
{
filter += " or brandId eq '" + brand + "'";
}
counter++;
}
}
sp.Filter = filter;
DocumentSearchResult response = indexClient.Documents.Search(theSearchQuery, sp);
foreach(SearchResult result in response.Results)
{
// do stuff to the results
}
最终的 (url-encoded) URI 为:
https://[mysearchservicename].search.windows.net/indexes/products/docs?api-version=2015-02-28&$filter=language%20eq%20%27us%27%20and%20%28brandId%20eq%20%276%27%20or%20brandId%20eq%20%278%27%20or%20brandId%20eq%20%279%27%20or%20brandId%20eq%20%2710%27%20or%20brandId%20eq%20%2711%27%20or%20brandId%20eq%20%2713%27%20or%20brandId%20eq%20%2722%27%29
希望有人能赐教吗?
Azure 搜索不支持集合文字或参数化筛选器,但它确实为这种情况提供了专门的功能:search.in
。 Azure 搜索支持的 OData 子集以及 search.in
函数记录在 here.
下面是一个示例,说明如何针对此特定情况使用 search.in
:
$filter=search.in(brandId, '1,2')
我正在使用新的(预览版)Azure 搜索 SDK (information here)。我正在使用 oData 表达式语法通过 $filter
参数构建我的搜索查询,我希望能够将一组 id 提供给端点。 brandId 字段在我的 Azure 搜索索引中,它是可搜索、可筛选、可排序和分面的。理想情况下,我希望能够按照以下方式做一些事情:
http://host/service/Products?brands=["1","2"]
(标题为 "Complex and Collection Literals" 的部分下的See specification here)
我不知道要使用什么语法来将 collection 文字语法包含在 $filter
查询中。所以我目前只是将逻辑 OR
的负载串联起来形成查询,而不是理想的查询:
var sp = new SearchParameters();
string filter = "$filter=";
if(brands.Length > 0)
{
int counter = 0;
foreach(string brand in brands)
{
if(counter == 0)
{
filter += "(brandId eq '" + brand + "'";
}
else if(counter == (brands.Count() - 1))
{
filter += " or brandId eq '" + brand + "')";
}
else
{
filter += " or brandId eq '" + brand + "'";
}
counter++;
}
}
sp.Filter = filter;
DocumentSearchResult response = indexClient.Documents.Search(theSearchQuery, sp);
foreach(SearchResult result in response.Results)
{
// do stuff to the results
}
最终的 (url-encoded) URI 为:
https://[mysearchservicename].search.windows.net/indexes/products/docs?api-version=2015-02-28&$filter=language%20eq%20%27us%27%20and%20%28brandId%20eq%20%276%27%20or%20brandId%20eq%20%278%27%20or%20brandId%20eq%20%279%27%20or%20brandId%20eq%20%2710%27%20or%20brandId%20eq%20%2711%27%20or%20brandId%20eq%20%2713%27%20or%20brandId%20eq%20%2722%27%29
希望有人能赐教吗?
Azure 搜索不支持集合文字或参数化筛选器,但它确实为这种情况提供了专门的功能:search.in
。 Azure 搜索支持的 OData 子集以及 search.in
函数记录在 here.
下面是一个示例,说明如何针对此特定情况使用 search.in
:
$filter=search.in(brandId, '1,2')