【问题标题】:Azure Search search with slash带有斜杠的 Azure 搜索搜索
【发布时间】:2021-02-14 23:22:22
【问题描述】:

我正在使用 Azure 认知搜索。

private async Task PerformSearchAsync<T>(SearchServiceDocumentsQueryParameters parameters, SearchClient searchClient, ICollection<T> outputCollection)
            where T : BaseSearchIndexObject
        {
            var searchResponse = await searchClient.SearchAsync<T>(parameters.SearchTerm, new SearchOptions
            {
                Filter = parameters.Filter,
                IncludeTotalCount = true,
                Size = parameters.MaxItemsCount
            });
            await foreach (var searchResult in searchResponse.Value.GetResultsAsync())
            {
                if(outputCollection.All(d => d.Id != searchResult.Document.Id))
                    outputCollection.Add(searchResult.Document);
            }
        }

在搜索词包含斜杠之前一切正常。例如,我正在寻找编号为“1508/W/2020”的订单。当我使用 SearchTerm = "1508" 进行搜索时,它可以工作。当 SearchTerm = "1508/W" 时,它什么也不返回。我尝试用\\ 转义斜线,但它仍然不起作用。你能建议我任何解决方案吗?

【问题讨论】:

  • 请注意,正斜杠的正确转义序列是\/,而不是\\
  • 您好,如果回答对您有帮助,您能否接受它作为回答,按照this link?只需几秒钟,谢谢。

标签: c# azure azure-cognitive-search


【解决方案1】:

评论是正确的。要转义/,您应该使用这种格式\/ 而不是\\

特殊字符转义可以参考这个official doc

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2011-02-08
    • 1970-01-01
    • 2019-03-20
    相关资源
    最近更新 更多