【问题标题】:Azure Search - QueryAzure 搜索 - 查询
【发布时间】:2017-11-04 06:03:11
【问题描述】:

所以我在 Azure 搜索周围使用 C# nuget 包装器。我的问题是我有一个产品索引:

public class ProductDocument
{
    [System.ComponentModel.DataAnnotations.Key]
    public string Key { get; set; }
    [IsSearchable]
    public string Sku { get; set; }
    [IsSearchable]
    public string Name { get; set; }
    [IsSearchable]
    public string FullDescription { get; set; }

    [IsSearchable]
    public List<CustomerSkuDocument> CustomerSkus { get; set; }
}
public class CustomerSkuDocument
{
    [IsSearchable]
    public int AccountId { get; set; }
    [IsSearchable]
    public string Sku { get; set; }
}

示例数据为:

            new Product() { Key= 100,Name="Nail 101",Sku = "CCCCCCCC", CustomerSkus = new List<ProductCustomerSku>()
            {
                new ProductCustomerSku() {AccountId = 222, CustomerSku = "BBBB"},
                new ProductCustomerSku() {AccountId = 333, CustomerSku = "EEEEEEE"}
            } 

所以问题在于 CustomerSkuDocument。 当我搜索时,我需要传递 AccountId 以及搜索词,但 AccountId 仅用于搜索 ProductCustomerSkus 时。

基本上,一个帐户可以有不同的客户 sku,但它只与该帐户相关联 - 我不希望每个帐户都有单独的索引。

所以我的调用类似于 /AccountId=222&term=BBBB 会找到匹配项。

但是 /AccountId=333&term=BBBB 找不到匹配项。

所以我这样称呼它:

        SearchParameters sp = new SearchParameters();
            sp.SearchMode = SearchMode.Any;
            sp.QueryType = QueryType.Full;

            DocumentSearchResult<ProductDocument> results =
            productIndexClient.Documents.Search<ProductDocument>(term, sp);

其中 term 是正常的搜索词,尝试添加 AccountId 但不起作用。

【问题讨论】:

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


    【解决方案1】:

    Azure 搜索不支持嵌套在外部文档属性下的重复数据结构。我们正在努力解决这个问题(参见https://feedback.azure.com/forums/263029-azure-search/suggestions/6670910-modelling-complex-types-in-indexes),但在发布之前我们还有一些工作要做。

    鉴于此,您展示的示例可能不会索引嵌套部分。您可以发布您正在使用的搜索索引定义吗?虽然我们直接支持复杂类型,但您可以在此处查看您的方法选项:https://docs.microsoft.com/en-us/azure/search/search-howto-complex-data-types

    从上面您将了解一个索引结构,该结构也将指导您的查询选项。如果您只需要相等,也许您可​​以简单地将 accountId 和 SKU 包含在同一字段中并使用集合字段,以便您可以拥有多个实例。对于您的查询,您将发出一个需要 accountId 并将其余部分作为可选关键字的搜索查询。

    【讨论】:

      猜你喜欢
      • 2018-05-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2021-12-17
      • 2020-04-23
      • 2018-01-11
      • 2021-06-01
      • 2015-08-02
      相关资源
      最近更新 更多