浏览 1431 次
精华帖 (0) :: 良好帖 (0) :: 新手帖 (0) :: 隐藏帖 (0)
|
|
---|---|
作者 | 正文 |
发表时间:2014-05-06
Our application will often face all kinds of demand. Among the them , the most taboo is to the restart the server. In the application of some large, restart the service may bring some serious impact.
So, in most of the time. we should try to avoid to restart . Then , In Solr ,how should we dynamic load some data ? such as : The dynamic load our index or Dynamic update our modified schemal and solrconfig.xml. if you need, the CoreAdminRequest class is a good choice. Example Code is given blow : <pre name="code" class="java">/** * dynamic adding indexes * * Search technology group : 324714439 * * * */ public static void reloadIndex()throws Exception{ CoreAdminRequest admin=new CoreAdminRequest(); //some index need to be added String []indexDirs={"D:\\mysolr\\webapps\\solr\\solr_home\\collections\\collection1\\data\\index"}; // String []srcCores={"collection2","collection1"}; String []srcCores={}; server.setBaseURL("http://localhost:9001/solr/collection2"); server.deleteByQuery("*:*");//clear old index server.setBaseURL("http://localhost:9001/solr/"); admin.mergeIndexes("collection2", indexDirs, srcCores, server);//copy new index into target admin.reloadCore("collection2", server); server.setBaseURL("http://localhost:9001/solr/collection2"); server.commit(); System.out.println("execute successful !"); }</pre> <pre name="code" class="java">/* * Dynamic update SolrCore * * avoid to the restart service * * **/ public static void reloadCore()throws Exception{ HttpSolrServer s=new HttpSolrServer("http://localhost:9003/solr"); CoreAdminRequest core=new CoreAdminRequest(); core.reloadCore("collection1", s); System.out.println("reload success!"); s.commit(); }</pre> Some is marked on the images below part, can be easy dynamically loaded . Restart the service is bad , You need dynamic loading ! 声明:ITeye文章版权属于作者,受法律保护。没有作者书面许可不得转载。
推荐链接
|
|
返回顶楼 | |