Eclipse使用solrJ 7.7.0连接solr步骤
先写一个测试类:
package com.taotao.rest.solrj; import org.apache.solr.client.solrj.SolrClient;
import org.apache.solr.client.solrj.impl.HttpSolrClient;
import org.apache.solr.common.SolrInputDocument;
import org.junit.Test; public class SolrJTest { public static final String BASE_URL = "http://192.168.83.133:8080/solr/collection1";
@Test
public void addDocument() throws Exception {
//创建一个连接
SolrClient solrClient = new HttpSolrClient.Builder(BASE_URL).withConnectionTimeout(1000).withSocketTimeout(6000).build();
//创建一个文档对象
SolrInputDocument document = new SolrInputDocument();
document.addField("id", "test001");
document.addField("item_title", "测试商品2");
document.addField("item_price", 123456);
//把文档对象写入索引库
solrClient.add(document);
//提交
solrClient.commit();
} @Test
public void delete() throws Exception{
// 创建一个连接
SolrClient solrClient = new HttpSolrClient.Builder(BASE_URL).withConnectionTimeout(1000).withSocketTimeout(6000).build();
//solrClient.deleteById("test001");
solrClient.deleteByQuery("*:*");
solrClient.commit();
}
}
说明:最新版的jar包中已经没有SolrServer这个类了,取而代之的是SolrClient。
通过URL操作Solr:
resource.properties:
#solr服务地址
SOLR.SERVER.URL=http://192.168.83.133:8080/solr/collection1
spring 中的 applicationContext-solr.xml:
<?xml version="1.0" encoding="UTF-8"?>
<beans xmlns="http://www.springframework.org/schema/beans"
xmlns:context="http://www.springframework.org/schema/context" xmlns:p="http://www.springframework.org/schema/p"
xmlns:aop="http://www.springframework.org/schema/aop" xmlns:tx="http://www.springframework.org/schema/tx"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-4.0.xsd
http://www.springframework.org/schema/context http://www.springframework.org/schema/context/spring-context-4.0.xsd
http://www.springframework.org/schema/aop http://www.springframework.org/schema/aop/spring-aop-4.0.xsd http://www.springframework.org/schema/tx http://www.springframework.org/schema/tx/spring-tx-4.0.xsd
http://www.springframework.org/schema/util http://www.springframework.org/schema/util/spring-util-4.0.xsd"> <!-- 配置SolrServer对象 -->
<!-- 单机版 -->
<bean id="httpSolrServer" class="org.apache.solr.client.solrj.impl.HttpSolrClient">
<constructor-arg name="builder" value="${SOLR.SERVER.URL}"></constructor-arg>
</bean>
</beans>
说明:使用时注意版本。
Eclipse使用solrJ 7.7.0连接solr步骤的更多相关文章
- Eclipse 下配置MySql5.6的连接池,使用Tomcat7.0
目前找到的最简单的配置方法. 1.首先在eclipse中创建一个Dynamical Web Application,在WebContent文件夹下的META-INF文件夹中创建新的名为conten ...
- C#连接solr时提示 java内存异常 (jetty和tomcat哪个更High) java.lang.OutOfMemoryError
C#连接solr时提示 java内存异常 java.lang.OutOfMemoryError 时间:20180130 09:51:13.329,消息:异常消息<?xml version=& ...
- 使用SolrJ客户端管理SolrCloud(Solr集群)
1.使用SolrJ客户端管理SolrCloud(Solr集群). package com.taotao.search.service; import java.io.IOException; impo ...
- Eclipse中部署hadoop2.3.0
1 eclipse中hadoop环境部署概览 eclipse 中部署hadoop包括两大部分:hdfs环境部署和mapreduce任务执行环境部署.一般hdfs环境部署比较简单,部署后就 可以在ecl ...
- Mysql6.0连接中的几个问题 Mysql6.xx
Mysql6.0连接中的几个问题 在最近做一些Javaweb整合时,因为我在maven官网查找的资源,使用的最新版,6.0.3,发现MySQL连接中的几个问题,总结如下: 1.Loading clas ...
- mysql(8.0连接navicat发生的错误解决方法)
关于mysql(8.0连接navicat发生的错误解决方法)数据库安装图形化界面无法更改加密的方式导致无法连接问题为解决; Alter user 'root'@'localhost' identifi ...
- Windows Tomcat7.0 安装 Solr
准备工作 1.下载Tomcat7.0 ,apache-tomcat-7.0.67.exe,安装目录如下:C:\workspace\Tomcat7.0\ 2.下载Solr 5.2,solr-5.2.0. ...
- Eclipse中通过Android模拟器调用OpenGL ES2.0函数操作步骤
原文地址: Eclipse中通过Android模拟器调用OpenGL ES2.0函数操作步骤 - 网络资源是无限的 - 博客频道 - CSDN.NET http://blog.csdn.net/fen ...
- VB6.0连接MySQL数据库
VB6.0连接MySQL数据库
随机推荐
- CentOS 7 (Linux) 下载百度网盘大文件
这个方法不仅适合下载 "百度网盘" 中的文件,还可以下载磁链之类的,总之,就是能够加快下载速度的方法. (参考了网上的多篇文章,自行实践,成功下载度盘大文件,并且提升了下载速度) ...
- (set stringstream)单词数 hdu2072
单词数 Time Limit: 1000/1000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others) Total Submis ...
- 2.Diango学习
##创建应用 python manage.py startapp blog !!创建应用后要添加应用,名称不允许与模块名称相同 ##应用目录结构 ##文件介绍 1. 2. 3. 4. 5. 6. ## ...
- servlet模拟SpringMVC
1. web.xml <?xml version="1.0" encoding="UTF-8"?> <web-app xmlns:xsi=&q ...
- 2017-12-14python全栈9期第一天第六节之用户交互
9,用户交互.input 1,等待输入, 2,将你输入的内容赋值给了前面变量. 3,input出来的数据类型全部是str 10,基础数据类型初始.数字:int 12,3,45 + - * / ** % ...
- 面向对象【day08】:动态导入模块(八)
本节内容 1.概述 2.知识回顾 3.动态导入模块 一.概述 我们之前导入模块都是用import,或者from ... import ....这种模式去导入模块,那如果我们如何实现只用字符串就可以导入 ...
- Hadoop记录-hadoop和hbase监控有那些比较好的工具
New Relic hadoop jmx granfa falcon Ganglia,Nagios和Chukwa 自带监控软件 hadoop yarn 开启jmx监控 打开{hadoop_home} ...
- MySQL备份工具之mysqldump使用
MySQL备份工具之mysqldump使用说明 一.备份分类 根据能否停用数据库,将备份类型分为: 1. 冷备:数据库服务停止后备份 2. 温备:只能对数据库进行读操作,不能进行写操作 3. 热备:在 ...
- 2018牛客网暑期ACM多校训练营(第二场)G Transform(二分)
题意 在一个数轴上有n个集装箱,第 i 个集装箱的位置为x[i],且在集装箱内装有a[i]件货物,现在将这些集装箱内的货物进行移动(将一件货物从第 i 个集装箱移动到第 j 个集装箱的花费就为2*ab ...
- MySQL学习笔记(二)性能优化的笔记(转)
今天,数据库的操作越来越成为整个应用的性能瓶颈了,这点对于Web应用尤其明显.关于数据库的性能,这并不只是DBA才需要担心的事,而这更是我们程序员需要去关注的事情.当我们去设计数据库表结构,对操作数据 ...