七、通过java代码实现增量、全量索引
来源:互联网 发布:mac hdmi声音输出设置 编辑:程序博客网 时间:2024/05/22 12:11
前期对solr全文检索已经做了绝大部分的工作,现在剩下的就是如何让索引自动加载,包括全量加载及增量加载。
1.首先要实现自动的全量加载及增量加载就要通过定时任务来实现,这里定时任务的编写不在这里描述。
2.如下是我在项目中的全量、增量加载的代码:
package com.ultrapower.bpm.interfaces;import java.io.IOException;import java.util.Properties;import org.apache.http.auth.AuthScope;import org.apache.http.auth.UsernamePasswordCredentials;import org.apache.http.impl.client.DefaultHttpClient;import org.apache.log4j.Logger;import org.apache.solr.client.solrj.SolrQuery;import org.apache.solr.client.solrj.SolrServerException;import org.apache.solr.client.solrj.impl.HttpSolrServer;import org.apache.solr.client.solrj.response.QueryResponse;import org.apache.solr.client.solrj.response.UpdateResponse;import org.apache.solr.common.SolrDocumentList;import org.apache.solr.common.SolrInputDocument;import org.springframework.core.io.support.PropertiesLoaderUtils;import com.ultrapower.bpm.process.action.ProcessAction;import com.ultrapower.bpm.sheet.manage.PreemptiveAuthInterceptor;public class AddSolrOperator {//======================================读取配置文件中solr的URLpublic static String SOLR_URL = "";public static String SOLR_IP = "";public static String SOLR_PORT = "";private static Logger log = Logger.getLogger(ProcessAction.class);static{try {Properties properties = PropertiesLoaderUtils.loadAllProperties("solrURL.properties");SOLR_URL = properties.getProperty("solr.url");SOLR_IP = properties.getProperty("solr.ip");SOLR_PORT = properties.getProperty("solr.port");} catch (IOException e) {log.error("读取solrURL.properties出现异常!!", e);}}//======================================// private static final String DEFAULT_URL = "http://localhost:8088/solr/"; // http://localhost:8088/solr/collection1/dataimport?command=delta-import&clean=false&commit=true&entity=up_knowledge&optimize=false // http://localhost:8088/solr/collection1/dataimport?command=delta-import&clean=false&commit=true&optimize=false public static HttpSolrServer solr=null ; @SuppressWarnings("unchecked")public synchronized void scanInterface() throws IOException{ solr= new HttpSolrServer(SOLR_URL);//====进行用户验证,因为tomcat中设定了用户验证,所以为了能连接服务器必需要验证用户,否则不能连通服务器 DefaultHttpClient m_client =(DefaultHttpClient)solr.getHttpClient(); UsernamePasswordCredentials credentials = new UsernamePasswordCredentials("admin","admin"); m_client.addRequestInterceptor(new PreemptiveAuthInterceptor(),0); (((DefaultHttpClient)m_client).getCredentialsProvider()).setCredentials(new AuthScope(SOLR_IP,Integer.parseInt(SOLR_PORT)), credentials); //======// AddSolrOperator add=new AddSolrOperator(); buildIndex(false); SolrInputDocument doc = new SolrInputDocument(); try { } catch (Exception e) { e.printStackTrace(); }} /** * 增量/全量建立索引 。 * * @param delta false,增量建立索引;true,重建所有索引 * @throws IOException */ public static void buildIndex(boolean delta) throws IOException { SolrQuery query = new SolrQuery(); // 指定RequestHandler,默认使用/select query.setRequestHandler("/dataimport"); String command = delta ? "full-import" : "delta-import"; String clean = delta ? "true" : "false"; String optimize = delta ? "true" : "false"; query.setParam("command", command) .setParam("clean", false) .setParam("commit", "true")// .setParam("entity", "") .setParam("optimize", optimize); try { solr.query(query); solr.commit(); System.out.println(" ///////////"+command); } catch (SolrServerException e) { e.printStackTrace(); } }}
0 0
- 七、通过java代码实现增量、全量索引
- solr全量索引、增量索引以及定时索引
- [搜索] Solr (三) 全量索引与增量索引
- solr 定时创建全量索引和增量索引
- 3.solr5全量索引和增量索引配置
- Solr全量索引、增量索引和定时增量索引配置
- solr6.0 -MySQL定时增量、全量更新索引
- 增量和全量
- mysql全量备份、增量备份实现方法
- solr 定时全量索引 增量索引与dataimporter.properties 配置
- solr 从数据库导入数据,全量索引和增量索引
- 转:solr 从数据库导入数据,全量索引和增量索引(实例&配置&原理)
- solr 从数据库导入数据,全量索引和增量索引
- solr 从数据库导入数据,全量索引和增量索引
- mysql增量、全量备份
- kettle入门(七) 之kettle增量方案(一)全量比对取增量-根据唯一标示
- solr通过http方式全量更新索引
- 全量同步索引
- python webui login code
- RobotArtl离线编程——活塞装配之打磨、去毛刺及抛光加工处理
- Android Animation的用法总结
- 分享一段Html5获取地理位置(定位)代码
- HDU 5745 La Vie en rose(DP+bitset优化)
- 七、通过java代码实现增量、全量索引
- 计算机网络最伟大的变革:多路径TCP
- 【Linux】进程间通信之管道
- Jmeter教程 简单的压力测试
- Android之三种网络请求解析数据(最佳案例)
- Retrofit初探
- ubuntu下apt-get安装和彻底卸载mysql
- sealed作用
- 数据库范式