【问题标题】:Using projection while retrieving from Azure Search Index从 Azure 搜索索引检索时使用投影
【发布时间】:2020-07-12 21:59:36
【问题描述】:

在这里,我使用查询从 azure 搜索索引中检索产品列表。在此,我获得了特定产品的图像列表。

 public class ProductImage
{

        public string Id { get; set; }

        [IsSearchable]
        public string ActualSizeUrl { get; set; }

        public string ThumbnailUrl { get; set; }
}

例如,我目前正在获取以下实际大小的 url:5de4ff7246bfe0002579328b/5da957c9e158618c1bbce366.jpg

使用此代码

var results = _indexClient.Documents.Search<Product>(searchText, parameters);

IEnumerable<SearchResult<Product>> itemList = results.Results.AsEnumerable();

IEnumerable<SearchResultItem> items = itemList.Select(x => new SearchResultItem
            {
                Data = x.Document,
                Confidence = x.Score,
                Type = Enum.GetName(typeof(SearchType), SearchType.Product),
            });

当我从搜索索引中检索时,如何实现这样的实际大小 URL:http://localhost:10000/devstoreaccount1/5de4ff7246bfe0002579328b/5da957c9e158618c1bbce366.jpg

【问题讨论】:

    标签: c# linq asp.net-core azure-cognitive-search


    【解决方案1】:

    最简单的选择是在您的应用程序代码中编写完整的 URL。

    在 .Net 中,您可以使用 ProductImage 类中的计算属性,该属性使用索引中的值和一些固定的根 URL 在 get 中创建 URL。

    您可以使用 [JsonIgnore] 属性,这样它就不会映射到索引中的字段。

    谢谢, 艾比

    【讨论】:

      猜你喜欢
      • 2018-11-19
      • 2015-02-01
      • 2012-11-26
      • 1970-01-01
      • 2017-05-27
      • 2019-02-05
      • 2014-11-29
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多