java 调用solr服务器 实现增删改查 及高亮显示

转自-----https://blog.csdn.net/u013378306/article/details/50761771;

首先有几点需要注意

客户端要调用solr服务,首先要把solr服务端工程启动,即前面文章讲的把solr下的slor.war例子放在tomcat下,进行相关配置,并启动。

(1)Exception in thread "main" org.apache.solr.client.solrj.beans.BindingException: class: class solr.PeopleBean does not define any fields.
是因为使用实体bean添加索引时,没有在实体属性上添加 Filed注解,导致solr无法匹配

@Field("name")
public void setName(String name) {
this.name = name;
}

public String[] getContent() {
return content;
}

(2)org.apache.solr.client.solrj.impl.HttpSolrServer$RemoteSolrException: Expected mime type application
是因为当solr有多个core时,solrj操作时没有指定是哪个core,以下指定使用core0的数据

private final static String URL = "http://localhost:80/solr/core0";
HttpSolrServer server = new HttpSolrServer(URL);

(3)Exception in thread "main" org.apache.solr.client.solrj.beans.BindingException: Could not instantiate object of class solr.PeopleBean

是因为当QueryResponse.getBeans(PeopleBean.class);方式查询,并返回实体bean时,必须有一个空的构造方法

public PeopleBean(){//此处应该注意,当QueryResponse.getBeans(PeopleBean.class);方式查询,并返回实体bean时,必须有一个                           空的构造方法

}

(4)当明明有数据却查不到时,要注意查询的字段,是否开启了索引。即 在shema.xml中是否设置indexed="true"

<field name="id"        type="string"   indexed="true"  stored="true"  multiValued="false" required="true"/>

<field name="name"      type="text_ik"   indexed="true"  stored="false"  multiValued="false" /> 

 <field name="content"      type="text_ik"   indexed="false"  stored="true"  multiValued="true" /> 

其中 indexed="true" 表示开启索引(当字段不需要被检索时,最好不要开启索引,) stored="true"表示存储原来数据(当字段不被检索,而只是需要通过其他字段检索而获得时,要设为true)  multiValued="true" 表示返回多值,如一个返回多个content,此时要在java代码中把 content设置 集合或数组类型如 

private String[] content;//多值,对应 multiValued="true"

(5)

需要以下jar包

。。。。

文章内容过多,建议根据本文转自网址https://blog.csdn.net/u013378306/article/details/50761771 进行查阅。

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值