保持 Sitecore Lucene 索引最新

发布于 2024-09-19 00:21:02 字数 374 浏览 9 评论 0原文

我有一个 Sitecore 应用程序,它通过 Sitecore 的内置 API 创建和使用许多 Lucene 索引。

我需要确保索引中的项目在发布时保持最新。为此,我创建了一个 Sitecore Hook,用于检测项目何时保存到“web”数据库并重新索引该项目。它似乎在大部分情况下都有效,但似乎有时会莫名其妙地失败。

我在钩子中的代码看起来像:

item.Database.Indexes.RemoveItem(item, true);
item.Database.Indexes.UpdateItem(item);

有人曾经尝试过这个并有更好的解决方案吗?

I've got a Sitecore application, which creates and uses a number of Lucene indexes through Sitecore's built-in API.

I need to make sure that items in the index are kept up-to-date when they are published. To do this, I've created a Sitecore Hook that detects when and item is saved to the "web" database and reindexes the item. It seems to be working for the most part, but it seems to inexplicibly fail from time to time.

The code I have in the hook looks like:

item.Database.Indexes.RemoveItem(item, true);
item.Database.Indexes.UpdateItem(item);

Anyone ever try this before and have a better solution?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(3

伪心 2024-09-26 00:21:02

HistoryEngine配置片段:

<Engines.HistoryEngine.Storage>
    <obj type="Sitecore.Data.$(database).$(database)HistoryStorage, Sitecore.Kernel">
        <param connectionStringName="$(id)" />
        <EntryLifeTime>30.00:00:00</EntryLifeTime>
    </obj>
</Engines.HistoryEngine.Storage>

根据 this SDN 文档 (PDF),每次 Sitecore 对项目进行更改时,都会向数据库表添加一条记录。但默认情况下,Sitecore 不会执行此操作,除非您将上述代码段包含在 web.config 中要索引的数据库的 部分中。

HistoryEngine config snippet:

<Engines.HistoryEngine.Storage>
    <obj type="Sitecore.Data.$(database).$(database)HistoryStorage, Sitecore.Kernel">
        <param connectionStringName="$(id)" />
        <EntryLifeTime>30.00:00:00</EntryLifeTime>
    </obj>
</Engines.HistoryEngine.Storage>

According this SDN document (PDF), every time Sitecore makes a change to an item, it adds a record to a database table. By default, though, Sitecore won't do this unless you include the above snippet in the <database> section in web.config for the database you want to index.

坦然微笑 2024-09-26 00:21:02

我可能会考虑将 Sitecore 历史引擎挂接到您的“web”数据库中,因为它已经用于“master”数据库了。通过这种方式,更改内容的索引将自动发生。

我现在不在电脑上,我可以在其中提取完整的示例,但您应该能够在 web.config 中的“master”数据库定义下找到您需要的配置。

I'd probably look into hooking the Sitecore History Engine into your "web" database, as it already is for "master". Through this, indexing of changed content would happen automatically.

Am not on a pc right now where I can pull up a full example, but you should be able to find the configuration you need, under the "master" database definition in your web.config.

夕嗳→ 2024-09-26 00:21:02

如果您运行 Sitecore 的单个实例来为您的网站提供服务,则发布项目时,Web 数据库上的 Lucene 索引会自动更新。 [编辑:阅读了凯尔在回答中链接到的文档后,我将仔细检查这是否依赖于历史引擎,我将其添加到项目中当然]

如果您运行的是旧版本的 Sitecore(6.2 或更低版本)并使用暂存模块来维护一个/多个前端服务器和创作服务器,那么您需要添加 HistoryEngine 在 Web 数据库(或您正在使用的任何发布目标)上,并将 Indexing.ServerSpecificProperties 设置设置为 true (我不确定此设置在哪个版本被引入 - 如果您没有看到它,那么您可能应该考虑升级(如果可能)。

如果您运行的是 Sitecore 6.3 或更高版本,我相信(而且我还没有对此进行测试)CD 实例应该在从 CM 服务器发布后自动重新索引内容,就好像它是由于事件而导致的单个实例一样联合组织。我稍后会检查一下。

对于任何想知道 HistoryEngine 是什么的人来说,它实际上只是一个非常简单的日志,记录了数据库中的更改内容和时间。每当发生变化时,事件就会被记录在那里。这允许 6.3 之前的实例在与内容创作实例断开连接时保留对更改内容的句柄。如果您好奇,请启用它并查看数据库中的历史记录表。

If you're running a single instance of Sitecore to serve your site then the Lucene indexes on the web database are automatically updated when an item is published. [EDIT: Having read the document linked to by Kyle in his answer, I'm going to double-check that this isn't dependant on the history engine, which I add to projects as a matter of course]

If you're running an old version of Sitecore (6.2 or lower) and are using the staging module to maintain one/several front-end servers and an authoring server then you'll need to add the HistoryEngine on the web database (or whatever publishing target you're using) and set the Indexing.ServerSpecificProperties setting to true (I'm not sure at what version this setting was introduced - if you don't see it then you should probably consider upgrading if possible).

If you're running Sitecore 6.3 or above, I believe (and I haven't tested this yet) that the CD instances should automatically re-index content after a publish from the CM server as though it were a single instance due to the event syndication. I'll check this later.

For anyone wondering what the HistoryEngine is, it's really just a very simple log of what has changed in the database and when. Whenever something changes, the event is recorded there. This allows pre-6.3 instances to keep a handle on what's changed when they're disconnected from the content authoring instance. If you're curious, enable it and have a look at the History table in the database.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文