Azure 搜索 - SearchMode:任何 - 未按预期工作

Azure Search - SearchMode : ANY - not working as expected

字段(所有字段均可过滤)

DocumentName : string
Document_types : ['type1','type2','type3']
Date : Date

我正在使用 .net 库来调用 Azure 搜索 API。

示例 A(任意)- 我想获得关键字为 Text 或 Document_types 为 type1.

的所有结果

这将如何运作?下面是我正在使用的示例代码。

        var filters = new SearchParameters()
        {
            Filter = "document_types/any(t: search.in(t, 'type1'))",
            Skip = (1 - 1) * 99999999,
            Top = 99999999,
            IncludeTotalResultCount = true,
            OrderBy = new[] { "as_of_date desc" },
            HighlightFields = new[] { "Content" },
            HighlightPreTag = "<span class=\"search-highlight\">",
            HighlightPostTag = "</span>",
            QueryType = QueryType.Full,
            SearchMode = SearchMode.Any
        };
        var results = await indexClient.Documents.SearchAsync("/.*" + query + ".*/", filters);

提前致谢!

Filters in Azure Search 的文档指出 "A filter scopes a search query to a subset of documents" 即我们不能在过滤器和搜索类型之间有 Or 条件。 solution/workaround 是使用 search.ismatch.

将搜索文本转换为过滤器类型

要获取关键字为 Text 或 Document_types 为 type1 的所有结果,请将 Filter 值更改为:

Filter = "Document_types/any(t: search.in(t, 'type1') or search.ismatch('Text')",

并将 SearchAsync 调用为

var results = await indexClient.Documents.SearchAsync("", filters);

请注意,这仅在搜索条件不是空字符串时有效,因为 search.in 不接受空字符串作为其第一个参数。

它与 search.ismatch('{0}') 函数一起使用。