【问题标题】:Azure Search - SearchMode : ANY - not working as expectedAzure 搜索 - SearchMode:ANY - 未按预期工作
【发布时间】:2018-10-17 07:33:32
【问题描述】:

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

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

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

示例 A (ANY) - 我想获取关键字为 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);

提前致谢!

【问题讨论】:

    标签: azure azure-cognitive-search azure-search-.net-sdk


    【解决方案1】:

    Filters in Azure Search 的文档指出“过滤器将搜索查询范围限定为文档子集” 即我们不能在过滤器和搜索类型之间有Or 条件。解决方案/解决方法是使用 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);

    请注意,这仅适用于 searchcriteria 不是空字符串,因为 search.in 不接受空字符串作为其第一个参数。

    【讨论】:

    • document_types 更改为 Document_types
    • search=""$filters=search.ismatchscoring('Text') OR Document_types/any(t: search.in(t, '38')&amp;highlight=Content&amp;HighlightPreTag=&lt;mitesh&gt;&amp;HighlightPostTag=&lt;/mitesh&gt; 这个我也试过了,它在高亮中返回 OR 作为文本搜索结果。
    • 试试search=*&amp;$filters=Document_types/any(t: search.in(t, 'type1') or search.ismatch('Text')
    • 返回的结果多于实际记录。
    • 添加$count=true like search=*&amp;$filters=Document_types/any(t: search.in(t, 'type1') or search.ismatch('Text')&amp;$count=true 以查看结果计数。能否检查一下结果,找出哪些结果记录不符合预期?
    【解决方案2】:

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

    【讨论】:

      猜你喜欢
      • 2019-03-30
      • 2017-05-12
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2018-10-25
      • 1970-01-01
      • 2021-07-27
      • 1970-01-01
      相关资源
      最近更新 更多