创建支持按过滤器评分的 Azure 搜索文档架构
Creating an Azure Search document schema which enables scoring by filters
我的域对象是这样的:
public class MainType {
public int Id {get;set;}
public string Name {get;set;}
public List<TypeA> A_List {get;set;}
public List<TypeB> B_List {get;set;}
... other properties
}
public class TypeA {
public int Id {get;set;}
public string Name {get;set;}
... other properties
}
public class TypeAMapping {
public int TypeAId {get;set;}
public int MainTypeId {get;set;}
public int DisplayOrder {get;set;}
}
public class TypeB {
public int Id {get;set;}
public string Name {get;set;}
... other properties
}
public class TypeBMapping {
public int TypeBId {get;set;}
public int MainTypeId {get;set;}
public int DisplayOrder {get;set;}
}
Azure 搜索索引文档不支持复杂类型,因此我需要将所有这些 class 扁平化为一个模型,如 here 所述。
所以,我创建了一个像这样的 class:
public class MainTypeDocumentModel {
public int Id {get;set;}
public string Name {get;set;}
public List<string> A_Id_List {get;set;}
public List<string> A_Name_List {get;set;}
public List<string> A_DisplayOrder_List {get;set;}
public List<string> B_Id_List {get;set;}
public List<string> B_Name_List {get;set;}
public List<string> B_DisplayOrder_List {get;set;}
... other properties
}
问题是我还需要处理 class 映射的 DisplayOrder
属性。文档未涵盖的内容。
我可以创建查询来搜索按 A_Id_List
and/or B_Id_List
过滤的 MainTypeDocumentModel
。但是我需要用文档的 X_DisplayOrder_List
属性 中的值对文档进行排序(或得分更高)。
我查看了 Microsoft 的 Scoring Profile 文档,但无法弄清楚如何针对这种情况实施。
听起来您想要的是嵌套 A 和 B 上的相关子查询的等价物。不幸的是,这在 Azure 搜索中目前是不可能的,因为它需要对复杂类型的内置支持。这是 on our radar,但目前没有预计到达时间。
同时,你可以考虑将域类型建模为 Azure 搜索索引的其他方法。一种选择是完全反规范化;有一个 A 索引和一个 B 索引,并为 As 和 Bs 的每个组合重复 Id 和 Name。另一种选择是完全标准化;对MainType、A、B以及它们之间的关系有单独的索引,在客户端做"joins"。根据您的查询模式和更新频率,需要权衡取舍。 This thread 在 MSDN 论坛上更详细地介绍了这些选项。
我的域对象是这样的:
public class MainType {
public int Id {get;set;}
public string Name {get;set;}
public List<TypeA> A_List {get;set;}
public List<TypeB> B_List {get;set;}
... other properties
}
public class TypeA {
public int Id {get;set;}
public string Name {get;set;}
... other properties
}
public class TypeAMapping {
public int TypeAId {get;set;}
public int MainTypeId {get;set;}
public int DisplayOrder {get;set;}
}
public class TypeB {
public int Id {get;set;}
public string Name {get;set;}
... other properties
}
public class TypeBMapping {
public int TypeBId {get;set;}
public int MainTypeId {get;set;}
public int DisplayOrder {get;set;}
}
Azure 搜索索引文档不支持复杂类型,因此我需要将所有这些 class 扁平化为一个模型,如 here 所述。
所以,我创建了一个像这样的 class:
public class MainTypeDocumentModel {
public int Id {get;set;}
public string Name {get;set;}
public List<string> A_Id_List {get;set;}
public List<string> A_Name_List {get;set;}
public List<string> A_DisplayOrder_List {get;set;}
public List<string> B_Id_List {get;set;}
public List<string> B_Name_List {get;set;}
public List<string> B_DisplayOrder_List {get;set;}
... other properties
}
问题是我还需要处理 class 映射的 DisplayOrder
属性。文档未涵盖的内容。
我可以创建查询来搜索按 A_Id_List
and/or B_Id_List
过滤的 MainTypeDocumentModel
。但是我需要用文档的 X_DisplayOrder_List
属性 中的值对文档进行排序(或得分更高)。
我查看了 Microsoft 的 Scoring Profile 文档,但无法弄清楚如何针对这种情况实施。
听起来您想要的是嵌套 A 和 B 上的相关子查询的等价物。不幸的是,这在 Azure 搜索中目前是不可能的,因为它需要对复杂类型的内置支持。这是 on our radar,但目前没有预计到达时间。
同时,你可以考虑将域类型建模为 Azure 搜索索引的其他方法。一种选择是完全反规范化;有一个 A 索引和一个 B 索引,并为 As 和 Bs 的每个组合重复 Id 和 Name。另一种选择是完全标准化;对MainType、A、B以及它们之间的关系有单独的索引,在客户端做"joins"。根据您的查询模式和更新频率,需要权衡取舍。 This thread 在 MSDN 论坛上更详细地介绍了这些选项。