Liam
Liam

Reputation: 21

Keeping Sitecore Lucene Indexes Up-To-Date

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?

Upvotes: 2

Views: 3673

Answers (3)

Matt
Matt

Reputation: 894

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.

Upvotes: 0

Kyle Heon
Kyle Heon

Reputation: 412

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.

Upvotes: 4

Mark Cassidy
Mark Cassidy

Reputation: 5860

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.

Upvotes: 1

Related Questions