How to keep Lucene index synchronized with Mysql d

2019-04-14 00:20发布

I am trying to utilize Lucene to develop full text search in my application, which need to build index based on my mysql database. I was wondering is how to keep these index synchronized with db? I came up with to ways: 1) add extra code in business logic tightly to update the search index . 2) running a separated task to rebuild the index periodically.

do you have any other approaches? and what do you think is the best way? Any comments would be appreciate, thanks in advance!

3条回答
走好不送
2楼-- · 2019-04-14 00:58

You could setup a trigger in MySQL to update changed docs for all inserted/updated/deleted documents.

Also, you could setup a Filter (javax.servlet spec) in your application to intercept server requests and push them to your index before they even reach database (it can even be done in the same transaction, but there's rarely a real need for that, eventual consistency is usually fine for search engines).

You can, as you said, also schedule periodical updates (similar to what I contributed to DIH in Solr).

查看更多
混吃等死
3楼-- · 2019-04-14 01:02

If you use Hibernate, check out Hibernate search project. It should cover a lot of boilerplate.

查看更多
趁早两清
4楼-- · 2019-04-14 01:10

You could use Elastic Search which provides and a JDBC river plugin or manually trigger updates using events on your Entities via JPA.

查看更多
登录 后发表回答