如何以编程方式将内容类型添加到索引?

mil*_*ose 5 c# orchardcms

我正在尝试以编程方式创建与多种类型相对应的索引,因此我可以在控制器中搜索特定类型的项目.(我尝试type在Lucene中使用关键字,但无论我做什么,这似乎根本不起作用,所以我改变了我的方法.)

但是,我无法弄清楚如何告诉Orchard在迁移中的索引中包含特定类型.我试过用:

var typeIndexing = ContentDefinitionManager.GetTypeDefinition(contentType)
                .Settings.GetModel<TypeIndexing>();
typeIndexing.List = typeIndexing.List.Concat(indexName.Yield()).ToArray();
Run Code Online (Sandbox Code Playgroud)

但这只是返回null的结果GetTypeDefinition().

我正在寻找使用:

ContentDefinitionManager.AlterTypeDefinition(contentType, builder => {
    builder.WithSetting("TypeIndexing.Indexes", indexName);
});
Run Code Online (Sandbox Code Playgroud)

但是,似乎是它取代了以前的配置指标,如果它在所有工作(编辑:没了),我不想揍现有的设置.(团队中的另一个人正在处理我们的设置配方.)

是否有任何地方我可以触摸该设置并将其存储并由配方文件外的Orchard实际使用?


为了说明我正在尝试使用类似的管理UI更改,在内容定义> [内容类型名称]>编辑下:

之前:

添加到索引之前的内容类型定义.

后:

添加到索引后的内容类型定义.

小智 4

您正在寻找的是 Indexed() 扩展方法。它接受您想要在内容类型上使用的索引。

ContentDefinitionManager.AlterTypeDefinition(nameof(contentType),type => 
type
.Indexed("FirstIndex", "SecondIndex"));
Run Code Online (Sandbox Code Playgroud)