我已使用与内容类型同名的部分向内容类型添加了一个名为 Website 的 LinkField。
ContentDefinitionManager.AlterTypeDefinition("MyContentType", a => a
.WithPart("CommonPart")
.WithPart("MyContentType")
.Creatable());
ContentDefinitionManager.AlterPartDefinition("MyContentType", cft => cft
.WithField("Website", a => a.OfType("LinkField").WithDisplayName("Website")
.WithSetting("FieldIndexing.Included", "True"))
.Attachable());
然后,我在迁移过程中创建一些默认内容项。
我在添加字段数据之前创建项目,因为在创建项目之前设置字段值时,我遇到了字段未更新的问题。 (请随意说明这一点,但这不是我的问题)
var myItem = _orchardServices.ContentManager.New("MyContentType");
_orchardServices.ContentManager.Create(myItem);
var websitePart = myItem.Parts.FirstOrDefault(x => x.Fields.Any(y => y.Name == "Website"));
var websiteLinkField = websitePart .Fields.FirstOrDefault(x => x.Name == "Website") as LinkField;
websiteLinkField.Value = "http://www.google.com";
websiteLinkField.Text = "Link to google";
_orchardServices.ContentManager.Publish(myItem);
我意识到有更动态的方式来进入这个领域,但这似乎也有效。
当我查看项目时,数据就会显示,但随后我会继续进行查询。
我使用 UI 构建一个简单的查询,在 LinkField 的文本中查找单词“google”,然后点击预览。
没有找到结果。
然后,我打开通过迁移创建的项目之一,然后单击“保存”按钮。
然后我再次尝试预览,我保存的项目现在显示了。
据我所知,当我保存一个我没有从迁移中执行的内容项时,发生了一些事情。但我一直在从各个角度逐步浏览代码,但我就是找不到它。
我怀疑也许应该触发一些处理程序才能创建 FieldIndex'es ?
(我知道如何触发 Lucene 索引的更新,但正如人们所期望的那样,它不会影响使用 Projections 模块查询字段,此时我真的迷失了。)
现在我只是在黑暗中盲目地刺伤。
我真的很感激我能得到的任何帮助,即使它只是指引我回到正确的方向。谢谢。