<p>Was looking to get peoples thoughts on keeping a Lucene index up to date as changes are made to the domain model objects of an application.  </p>

<p>The application in question is a Java/J2EE based web app that uses Hibernate.  The way I currently have things working is that the Hibernate mapped model objects all implement a common "Indexable" interface that can return a set of key/value pairs that are recorded in Lucene.  Whenever a CRUD operation is performed involving such an object I send it via JMS queue into a message driven bean that records in Lucene the primary key of the object and the key/value pairs returned from the index( ) method of the Indexable object that was provided.  </p>

<p>My main worries about this scheme is if the MDB gets behind and can't keep up with the indexing operations that are coming in or if some sort of error/exception stops an object from being index.  The result is an out-of-date index for either a sort, or long, period of time.  </p>

<p>Basically I was just wondering what kind of strategies others had come up with for this sort of thing.  Not necessarily looking for one correct answer but am imagining a list of "whiteboard" sort of ideas to get my brain thinking about alternatives.</p>

[{'answer_id': 38189, 'author': 'Marcel', 'author_id': 2554, 'author_profile': 'https://Stackoverflow.com/users/2554', 'pm_score': 3, 'selected': True, 'text': '<p>Change the message: just provide the primary key and the current date, not the key/value pairs. Your mdb fetches the entity by primary key and calls index(). After indexing you set a value "updated" in your index to the message date. You update your index only if the message date is after the "updated" field of the index. This way you can\'t get behind because you always fetch the current key/value pairs first.</p>\n\n<p>As an alternative: have a look at <a href="http://www.compass-project.org" rel="nofollow noreferrer">http://www.compass-project.org</a>.</p>\n'}, {'answer_id': 42695890, 'author': 'Sanne', 'author_id': 563323, 'author_profile': 'https://Stackoverflow.com/users/563323', 'pm_score': 0, 'selected': False, 'text': '<p>The accepted answer is 8 years old now and very out of date.</p>\n\n<p>The Compass Project is not maintained anymore since a long time, as its main developer moved on to create the excellent Elasticsearch.</p>\n\n<p>The modern answer to this is to use <a href="http://hibernate.org/search/" rel="nofollow noreferrer">Hibernate Search</a>, which incidentally can map to either a Lucene index directly or through Elasticsearch.</p>\n'}]
['https://Stackoverflow.com/questions/38125', 'https://Stackoverflow.com', 'https://Stackoverflow.com/users/4063/']