先写一个测试类:

 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步骤的更多相关文章

  1. Eclipse 下配置MySql5.6的连接池,使用Tomcat7.0

    目前找到的最简单的配置方法.   1.首先在eclipse中创建一个Dynamical Web Application,在WebContent文件夹下的META-INF文件夹中创建新的名为conten ...

  2. C#连接solr时提示 java内存异常 (jetty和tomcat哪个更High) java.lang.OutOfMemoryError

    C#连接solr时提示 java内存异常   java.lang.OutOfMemoryError 时间:20180130 09:51:13.329,消息:异常消息<?xml version=& ...

  3. 使用SolrJ客户端管理SolrCloud(Solr集群)

    1.使用SolrJ客户端管理SolrCloud(Solr集群). package com.taotao.search.service; import java.io.IOException; impo ...

  4. Eclipse中部署hadoop2.3.0

    1 eclipse中hadoop环境部署概览 eclipse 中部署hadoop包括两大部分:hdfs环境部署和mapreduce任务执行环境部署.一般hdfs环境部署比较简单,部署后就 可以在ecl ...

  5. Mysql6.0连接中的几个问题 Mysql6.xx

    Mysql6.0连接中的几个问题 在最近做一些Javaweb整合时,因为我在maven官网查找的资源,使用的最新版,6.0.3,发现MySQL连接中的几个问题,总结如下: 1.Loading clas ...

  6. mysql(8.0连接navicat发生的错误解决方法)

    关于mysql(8.0连接navicat发生的错误解决方法)数据库安装图形化界面无法更改加密的方式导致无法连接问题为解决; Alter user 'root'@'localhost' identifi ...

  7. 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. ...

  8. Eclipse中通过Android模拟器调用OpenGL ES2.0函数操作步骤

    原文地址: Eclipse中通过Android模拟器调用OpenGL ES2.0函数操作步骤 - 网络资源是无限的 - 博客频道 - CSDN.NET http://blog.csdn.net/fen ...

  9. VB6.0连接MySQL数据库

    VB6.0连接MySQL数据库

随机推荐

  1. POJ 3463 Sightseeing (次短路经数)

    Sightseeing Time Limit: 2000MS   Memory Limit: 65536K Total Submissions:10005   Accepted: 3523 Descr ...

  2. 多态(instanceof)

    多态调用的三种格式 * A:多态的定义格式: * 就是父类的引用变量指向子类对象 父类类型 变量名 = new 子类类型(); 变量名.方法名(); * B: 普通类多态定义的格式 父类 变量名 = ...

  3. Expected value at 1:0 异常解决方法

    有时候自己也很郁闷,明明自己写的是ok的竟然,还报错. 网上查找了这个异常,竟然没有解决方法,后来尝试着去解决,竟然真的解决了. 其实,我又新建一个文件夹,把原先的代码给粘贴复制进去就ok了,其实到现 ...

  4. mac crontab调用python时出现ImportError: No module named XXX的问题

    写了一个监控mq的脚本,把这个脚本加入crontab里进行时刻监控,于是#crontab -e,添加语句: * * * * * cd /目录 && python mq脚本名.py &g ...

  5. python对象初始化

    当python对象被创建以后,需要将对象进行初始化.Python有一个构造函数和一个初始化函数: 1.构造函数__new__,只接受一个参数,即类本身(它会在对象被构造之前调用,所以这里也就没有sel ...

  6. 剑指Offer_编程题_13

    题目描述 输入一个整数数组,实现一个函数来调整该数组中数字的顺序,使得所有的奇数位于数组的前半部分,所有的偶数位于位于数组的后半部分,并保证奇数和奇数,偶数和偶数之间的相对位置不变. class So ...

  7. ARM三级流水线

    title: ARM三级流水线 tags: ARM date: 2018-10-14 16:57:10 --- 参考: ARM指令集E004armproc.chm ARM Architecture R ...

  8. HDFS 上文件块的副本数设置

    一.使用 setrep 命令来设置 # 设置 /javafx-src.zip 的文件块只存三份 hadoop fs -setrep /javafx-src.zip 二.文件块在磁盘上的路径 # 设置的 ...

  9. UNIX网络编程中的字节序问题

    1.inet_pton 函数原型: inet_pton:将“点分十进制” -> “二进制整数” int inet_pton(int af, const char *src, void *dst) ...

  10. PHP7 学习笔记(十一)使用phpstudy快速配置一个虚拟主机

    说明:为了windows本地开发php方便,这里推荐使用PHP集成环境phpstudy. 目的:使用域名访问项目(tinywan.test) 1.官网:http://www.phpstudy.net ...