简体   繁体   中英

How to load an existing Lucene Index in Infinispan?

In my system with Infinispan 6.0.2, I have added some data in cache and indexing them with lucene. It works well for the searching part.

But because the caches exist in server, sometimes when the server break down, I need to reload the data and index them. That takes a long time.

Then I find that Infinispan can store the index in database and load from an existing Lucene index. I think that should fix my problem. But there is little information in Infinispan user guide, I dont know how to do it. Can someone give me a example???

Infinispan includes a highly scalable distributed Apache Lucene Directory implementation. To create a Directory instance:

import org.apache.lucene.store.Directory;
import org.infinispan.lucene.directory.DirectoryBuilder;
import org.infinispan.Cache;

Cache cache = // create an Infinispan cache, configured as you like
Directory indexDir = DirectoryBuilder.newDirectoryInstance(cache, cache, cache, indexName)
                                     .create();

The indexName is a unique key to identify your index. It takes the same role as the path did on filesystem based indexes: you can create several different indexes giving them different names. When you use the same indexName in another instance connected to the same network (or instantiated on the same machine, useful for testing) they will join, form a cluster and share all content. Using a different indexName allows you to store different indexes in the same set of Caches.

The cache is passed three times in this example, as that is ok for a quick demo, but as the API suggests it's a good idea to tune each cache separately as they will be used in different ways. More details provided below.

New nodes can be added or removed dynamically, making the service administration very easy and also suited for cloud environments: it's simple to react to load spikes, as adding more memory and CPU power to the search system is done by just starting more nodes.

Refer documentation and API reference for details

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM